-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional default tag for union type #227
Conversation
src/Nirum/Targets/Python.hs
Outdated
@@ -1098,7 +1107,7 @@ class $className(service_type): | |||
$methodNameMap | |||
]) | |||
__nirum_method_annotations__ = $methodAnnotations' | |||
|
|||
__valerie__ = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my
7bd4220
to
02bbdff
Compare
Checklist 🤔
|
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need changelog as well.
src/Nirum/Parser.hs
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/Nirum/Targets/Python.hs
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/Nirum/Targets/Python.hs
Outdated
@@ -200,6 +207,9 @@ runCodeGen :: CodeGen a | |||
-> (Either CompileError' a, CodeGenContext) | |||
runCodeGen = C.runCodeGen | |||
|
|||
renderCompileText :: BI.Markup -> T.Text | |||
renderCompileText = toStrict . renderMarkup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
src/Nirum/Targets/Python.hs
Outdated
@@ -1007,17 +1018,10 @@ class $className(object): | |||
] | |||
compileTypeDeclaration src | |||
d@TypeDeclaration { typename = typename' | |||
, type' = UnionType tags | |||
, type' = u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/Nirum/Targets/Python.hs
Outdated
{arg "cls" "type"}, value | ||
){ ret className }: | ||
#{arg "cls" "type"}, value | ||
)#{ ret className }: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Compare
2e79dd0
to
87d7f5e
Compare
👏 |
implements #13 .