dot is not expr.expr, it's expr.ident
This commit is contained in:
parent
5dd92c99fe
commit
ac37c8d491
2 changed files with 8 additions and 4 deletions
10
agast.py
10
agast.py
|
@ -29,6 +29,7 @@ class Equation:
|
||||||
def __init__(self, lhs: Expr, rhs: Expr):
|
def __init__(self, lhs: Expr, rhs: Expr):
|
||||||
self.lhs = lhs
|
self.lhs = lhs
|
||||||
self.rhs = rhs
|
self.rhs = rhs
|
||||||
|
def __repr__(self) -> str: return f"{self.lhs} = {self.rhs}"
|
||||||
|
|
||||||
class Variant:
|
class Variant:
|
||||||
def __init__(self, prod: List[Sym], equations: List[Equation]):
|
def __init__(self, prod: List[Sym], equations: List[Equation]):
|
||||||
|
@ -43,7 +44,7 @@ class Node(Decl):
|
||||||
self.variants = variants
|
self.variants = variants
|
||||||
|
|
||||||
class ExprDot(Expr):
|
class ExprDot(Expr):
|
||||||
def __init__(self, left: Expr, right: Expr):
|
def __init__(self, left: Expr, right: str):
|
||||||
self.left = left
|
self.left = left
|
||||||
self.right = right
|
self.right = right
|
||||||
def __repr__(self) -> str: return f"{self.left}.{self.right}"
|
def __repr__(self) -> str: return f"{self.left}.{self.right}"
|
||||||
|
@ -101,7 +102,7 @@ class Parser(Transformer[List[Decl]]):
|
||||||
def equation(self, items: List[Expr]) -> Equation: return Equation(items[0], items[1])
|
def equation(self, items: List[Expr]) -> Equation: return Equation(items[0], items[1])
|
||||||
|
|
||||||
# expr
|
# expr
|
||||||
def expr_dot(self, items: List[Expr]) -> Expr:
|
def expr_dot(self, items: List[Any]) -> Expr:
|
||||||
[left, right] = items
|
[left, right] = items
|
||||||
return ExprDot(left, right)
|
return ExprDot(left, right)
|
||||||
def expr_add(self, items: List[Expr]) -> Expr:
|
def expr_add(self, items: List[Expr]) -> Expr:
|
||||||
|
@ -112,7 +113,10 @@ class Parser(Transformer[List[Decl]]):
|
||||||
return ExprMul(left, right)
|
return ExprMul(left, right)
|
||||||
def expr_call(self, items: List[Expr]) -> Expr:
|
def expr_call(self, items: List[Expr]) -> Expr:
|
||||||
[func, args] = items
|
[func, args] = items
|
||||||
return ExprMul(func, args)
|
# TODO: args should be a list of exprs -_ -
|
||||||
|
return ExprCall(func, [args])
|
||||||
|
def expr_name(self, items: List[str]) -> Expr:
|
||||||
|
return ExprName(items[0])
|
||||||
|
|
||||||
def sep_trail(self, items: List[Tree]) -> List[T]:
|
def sep_trail(self, items: List[Tree]) -> List[T]:
|
||||||
return list(map(lambda it: cast(T, it), items))
|
return list(map(lambda it: cast(T, it), items))
|
||||||
|
|
|
@ -29,7 +29,7 @@ equation_: equation ";"
|
||||||
// called lvalue, and should NOT include literals
|
// called lvalue, and should NOT include literals
|
||||||
equation: expr "=" expr
|
equation: expr "=" expr
|
||||||
|
|
||||||
expr: expr_dot
|
?expr: expr_dot
|
||||||
| expr_add
|
| expr_add
|
||||||
| expr_mul
|
| expr_mul
|
||||||
| expr_call
|
| expr_call
|
||||||
|
|
Loading…
Reference in a new issue