mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
expressions: Add closure expressions
This commit is contained in:
parent
8a7941dcbf
commit
3f7688a563
6 changed files with 69 additions and 0 deletions
|
@ -66,6 +66,30 @@ class IdentExpr(AstNode):
|
|||
xml.end_tag()
|
||||
|
||||
|
||||
class ClosureExpr(AstNode):
|
||||
grammar = [
|
||||
UseIdent("function"),
|
||||
"(",
|
||||
Delimited(Expr, ",").expected("closure arguments"),
|
||||
Match(")").expected(),
|
||||
]
|
||||
|
||||
@validate()
|
||||
def is_cast_to_return_val(self):
|
||||
if not isinstance(self.parent.parent, CastExpr):
|
||||
raise CompileError(f"Closure expression needs to be cast to {self.tokens['function']}'s return type")
|
||||
|
||||
@property
|
||||
def gir_type(self):
|
||||
return self.parent.parent.gir_type
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("closure", function=self.tokens["function"], type=self.gir_type)
|
||||
for child in self.children[Expr]:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class LookupOp(InfixExpr):
|
||||
grammar = [".", UseIdent("property")]
|
||||
|
||||
|
@ -94,6 +118,7 @@ class CastExpr(AstNode):
|
|||
|
||||
|
||||
expr.children = [
|
||||
Prefix(ClosureExpr),
|
||||
Prefix(IdentExpr),
|
||||
Prefix(CastExpr),
|
||||
Prefix(["(", Expr, ")"]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue