mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Use <> instead of () for casts & typeof
This makes it clearer that they aren't functions, and it eliminates syntactic ambiguity with closure expressions.
This commit is contained in:
parent
d6bd282e58
commit
02796fd830
10 changed files with 66 additions and 11 deletions
|
@ -159,7 +159,17 @@ class LookupOp(InfixExpr):
|
|||
|
||||
|
||||
class CastExpr(InfixExpr):
|
||||
grammar = ["as", "(", TypeName, ")"]
|
||||
grammar = [
|
||||
"as",
|
||||
AnyOf(
|
||||
["<", TypeName, Match(">").expected()],
|
||||
[
|
||||
UseExact("lparen", "("),
|
||||
TypeName,
|
||||
UseExact("rparen", ")").expected("')'"),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
@context(ValueTypeCtx)
|
||||
def value_type(self):
|
||||
|
@ -183,6 +193,19 @@ class CastExpr(InfixExpr):
|
|||
f"Invalid cast. No instance of {self.lhs.type.full_name} can be an instance of {self.type.full_name}."
|
||||
)
|
||||
|
||||
@validate("lparen", "rparen")
|
||||
def upgrade_to_angle_brackets(self):
|
||||
if self.tokens["lparen"]:
|
||||
raise UpgradeWarning(
|
||||
"Use angle bracket syntax introduced in blueprint 0.8.0",
|
||||
actions=[
|
||||
CodeAction(
|
||||
"Use <> instead of ()",
|
||||
f"<{self.children[TypeName][0].as_string}>",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class ClosureArg(AstNode):
|
||||
grammar = ExprChain
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue