Skip to content

Commit

Permalink
continue to tweak the class methods. this compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Aug 21, 2023
1 parent 0d3d94a commit 13c2718
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/haskell/natural4/src/LS/XPile/Typescript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import LS.Rule as SFL4R
)
import LS.Types as SFL4
( ClsTab (CT), unCT,
EntityType,
HornClause (HC, hHead),
HornClause2,
BoolStructR(..),
Expand Down Expand Up @@ -277,10 +278,10 @@ tsClasses l4i = return $
<//> " // using prettySimpleType (old code path)"
<//> indent 2 ( vsep [ snake_case [MTT attrname] <>
case attrType children attrname of
Just t@(SimpleType TOptional _) -> " () : null | " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className t)
Just t@(SimpleType TOne _) -> " () : " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className t)
Just t@(SimpleType TOptional _) -> " () : null | " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className (Just t))
Just t@(SimpleType TOne _) -> " () : " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className (Just t))
Just t@(InlineEnum TOne _) -> " () : " <+> snake_case [MTT attrname] <> "Enum"
Just t -> " () : " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className t)
Just t -> " () : " <+> prettySimpleType "ts" (snake_inner . MTT) t <+> braces (methodFor l4i className (Just t))
Nothing -> "// tsClasses nothing case"
<> semi
| attrname <- getCTkeys children
Expand Down Expand Up @@ -323,13 +324,15 @@ tsClasses l4i = return $
-- class MyClass { MyValue = (someArgument) => { return 2 * someArgument } }
--

-- methodFor :: Interpreted -> EntityType ->
methodFor :: Interpreted -> EntityType -> Maybe TypeSig -> Doc ann
methodFor l4i entype mtsig =
defaultMethod mtsig

-- | if we can't find a decision rule defining this particular attribute as a method, we return a default method
defaultMethod :: TypeSig -> Doc ann
defaultMethod (SimpleType TOne "string") = " return \"\" "
defaultMethod (SimpleType TOne "number") = " return 0 "
defaultMethod _ = " return undefined "
defaultMethod :: Maybe TypeSig -> Doc ann
defaultMethod (Just (SimpleType TOne "string")) = " return \"\" "
defaultMethod (Just (SimpleType TOne "number")) = " return 0 "
defaultMethod _ = " return undefined "

-- | output enum declarations
tsEnums :: Interpreted -> XPileLog (Doc ann)
Expand Down

0 comments on commit 13c2718

Please sign in to comment.