Optional default tag for union type #227
Conversation
@@ -1098,7 +1107,7 @@ class $className(service_type): | |||
$methodNameMap | |||
]) | |||
__nirum_method_annotations__ = $methodAnnotations' | |||
|
|||
__valerie__ = True |
nellaG
Feb 10, 2018
Author
Contributor
oh my
oh my
7bd4220
to
02bbdff
Checklist
|
|
Need changelog as well. |
tag = do | ||
annotationSet' <- annotationSet <?> "union tag annotations" | ||
spaces | ||
-- CHECK: If a new reserved keyword is introduced, it has to be also | ||
-- added to `reservedKeywords` set in the `Nirum.Constructs.Identifier` | ||
-- module. |
dahlia
Feb 12, 2018
Member
This check comment should go to the top of Parser.hs source. See also Checkmate docs. Since it's sensitive to block indentation levels, if a CHECK
comment is too deeply inside it could be hardly warned.
This check comment should go to the top of Parser.hs source. See also Checkmate docs. Since it's sensitive to block indentation levels, if a CHECK
comment is too deeply inside it could be hardly warned.
@@ -1104,36 +1121,33 @@ class $className({T.intercalate "," $ compileExtendClasses annotations}): | |||
else: | |||
name = attribute_name | |||
tag_types = cls.__nirum_tag_types__ | |||
if callable(tag_types): # old compiler could generate non-callable map | |||
# old compiler could generate non-callable map | |||
if callable(tag_types): | |||
tag_types = dict(tag_types()) | |||
try: | |||
args[name] = deserialize_meta(tag_types[name], item) |
dahlia
Feb 12, 2018
Member
Despite this kind of conditionals are necessary for the runtime library to be compatible old and new versions of the compiler, it's no more needed for compiler-generated codes; it's guaranteed that it's always generated by the new one.
Despite this kind of conditionals are necessary for the runtime library to be compatible old and new versions of the compiler, it's no more needed for compiler-generated codes; it's guaranteed that it's always generated by the new one.
@@ -200,6 +207,9 @@ runCodeGen :: CodeGen a | |||
-> (Either CompileError' a, CodeGenContext) | |||
runCodeGen = C.runCodeGen | |||
|
|||
renderCompileText :: BI.Markup -> T.Text | |||
renderCompileText = toStrict . renderMarkup |
dahlia
Feb 12, 2018
•
Member
These toStrict $ renderMarkup ...
codes have remained by intention; they need to be merely removed in the near future by replacing type CompileResult Python = Code
with type CompileResult Python = BI.Markup
.
These toStrict $ renderMarkup ...
codes have remained by intention; they need to be merely removed in the near future by replacing type CompileResult Python = Code
with type CompileResult Python = BI.Markup
.
@@ -1007,17 +1018,10 @@ class $className(object): | |||
] | |||
compileTypeDeclaration src | |||
d@TypeDeclaration { typename = typename' | |||
, type' = UnionType tags | |||
, type' = u |
dahlia
Feb 12, 2018
Member
We don't need to define tags
like the following code in where
clause:
tags :: [Tag]
tags = findTags u
Instead we can just match both of UnionType
and its tags
:
, type' = u@(UnionType tags)
Also we should rename u
to better one.
We don't need to define tags
like the following code in where
clause:
tags :: [Tag]
tags = findTags u
Instead we can just match both of UnionType
and its tags
:
, type' = u@(UnionType tags)
Also we should rename u
to better one.
{arg "cls" "type"}, value | ||
){ ret className }: | ||
#{arg "cls" "type"}, value | ||
)#{ ret className }: |
dahlia
Feb 12, 2018
Member
Since we now have proper conditionals through Heterocephalus, things like arg "cls" "type"
or ret className
can be avoided. See also compileTypeDeclaration
function for EnumType
:
@classmethod
%{ case pyVer }
%{ of Python2 }
def __nirum_deserialize__(cls, value):
%{ of Python3 }
def __nirum_deserialize__(cls: type, value: str) -> '#{className}':
%{ endcase }
return cls(value.replace('-', '_')) # FIXME: validate input
Since we now have proper conditionals through Heterocephalus, things like arg "cls" "type"
or ret className
can be avoided. See also compileTypeDeclaration
function for EnumType
:
@classmethod
%{ case pyVer }
%{ of Python2 }
def __nirum_deserialize__(cls, value):
%{ of Python3 }
def __nirum_deserialize__(cls: type, value: str) -> '#{className}':
%{ endcase }
return cls(value.replace('-', '_')) # FIXME: validate input
7d5a611
to
12a5ff2
2e79dd0
to
87d7f5e
|
implements #13 .