From 9e82a2fb2a33781285432111f22c0d7e8493a24a Mon Sep 17 00:00:00 2001 From: James Westman Date: Sun, 9 Apr 2023 14:46:29 -0500 Subject: [PATCH] language: Rename expression classes Rename the expression classes to match the documentation. --- blueprintcompiler/language/__init__.py | 4 +-- blueprintcompiler/language/binding.py | 8 +++--- blueprintcompiler/language/expression.py | 26 +++++++++---------- .../language/gobject_property.py | 2 +- blueprintcompiler/outputs/xml/__init__.py | 6 ++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blueprintcompiler/language/__init__.py b/blueprintcompiler/language/__init__.py index c48ae35..99521a3 100644 --- a/blueprintcompiler/language/__init__.py +++ b/blueprintcompiler/language/__init__.py @@ -7,8 +7,8 @@ from .expression import ( CastExpr, ClosureArg, ClosureExpr, - Expr, - ExprChain, + ExprBase, + Expression, LiteralExpr, LookupOp, ) diff --git a/blueprintcompiler/language/binding.py b/blueprintcompiler/language/binding.py index b2dee10..88105fc 100644 --- a/blueprintcompiler/language/binding.py +++ b/blueprintcompiler/language/binding.py @@ -20,19 +20,19 @@ from dataclasses import dataclass from .common import * -from .expression import ExprChain, LookupOp, LiteralExpr +from .expression import Expression, LookupOp, LiteralExpr from .contexts import ValueTypeCtx class Binding(AstNode): grammar = [ Keyword("bind"), - ExprChain, + Expression, ] @property - def expression(self) -> ExprChain: - return self.children[ExprChain][0] + def expression(self) -> Expression: + return self.children[Expression][0] @property def simple_binding(self) -> T.Optional["SimpleBinding"]: diff --git a/blueprintcompiler/language/expression.py b/blueprintcompiler/language/expression.py index 0cf41b0..dd8db60 100644 --- a/blueprintcompiler/language/expression.py +++ b/blueprintcompiler/language/expression.py @@ -27,7 +27,7 @@ from .gtkbuilder_template import Template expr = Sequence() -class Expr(AstNode): +class ExprBase(AstNode): @context(ValueTypeCtx) def value_type(self) -> ValueTypeCtx: if rhs := self.rhs: @@ -44,8 +44,8 @@ class Expr(AstNode): return True @property - def rhs(self) -> T.Optional["Expr"]: - if isinstance(self.parent, ExprChain): + def rhs(self) -> T.Optional["ExprBase"]: + if isinstance(self.parent, Expression): children = list(self.parent.children) if children.index(self) + 1 < len(children): return children[children.index(self) + 1] @@ -55,11 +55,11 @@ class Expr(AstNode): return None -class ExprChain(Expr): +class Expression(ExprBase): grammar = expr @property - def last(self) -> Expr: + def last(self) -> ExprBase: return self.children[-1] @property @@ -71,14 +71,14 @@ class ExprChain(Expr): return self.last.type_complete -class InfixExpr(Expr): +class InfixExpr(ExprBase): @property def lhs(self): - children = list(self.parent_by_type(ExprChain).children) + children = list(self.parent_by_type(Expression).children) return children[children.index(self) - 1] -class LiteralExpr(Expr): +class LiteralExpr(ExprBase): grammar = LITERAL @property @@ -208,18 +208,18 @@ class CastExpr(InfixExpr): class ClosureArg(AstNode): - grammar = ExprChain + grammar = Expression @property - def expr(self) -> ExprChain: - return self.children[ExprChain][0] + def expr(self) -> Expression: + return self.children[Expression][0] @context(ValueTypeCtx) def value_type(self) -> ValueTypeCtx: return ValueTypeCtx(None) -class ClosureExpr(Expr): +class ClosureExpr(ExprBase): grammar = [ Optional(["$", UseLiteral("extern", True)]), UseIdent("name"), @@ -257,6 +257,6 @@ class ClosureExpr(Expr): expr.children = [ - AnyOf(ClosureExpr, LiteralExpr, ["(", ExprChain, ")"]), + AnyOf(ClosureExpr, LiteralExpr, ["(", Expression, ")"]), ZeroOrMore(AnyOf(LookupOp, CastExpr)), ] diff --git a/blueprintcompiler/language/gobject_property.py b/blueprintcompiler/language/gobject_property.py index 6beb738..b52feb9 100644 --- a/blueprintcompiler/language/gobject_property.py +++ b/blueprintcompiler/language/gobject_property.py @@ -19,7 +19,7 @@ from dataclasses import dataclass -from .expression import ExprChain +from .expression import Expression from .gobject_object import Object from .gtkbuilder_template import Template from .values import Value, ObjectValue diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index ed13610..852a81b 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -211,15 +211,15 @@ class XmlOutput(OutputFormat): else: raise CompilerBugError() - def _emit_expression(self, expression: ExprChain, xml: XmlEmitter): + def _emit_expression(self, expression: Expression, xml: XmlEmitter): self._emit_expression_part(expression.last, xml) - def _emit_expression_part(self, expression: Expr, xml: XmlEmitter): + def _emit_expression_part(self, expression: ExprBase, xml: XmlEmitter): if isinstance(expression, LiteralExpr): self._emit_literal_expr(expression, xml) elif isinstance(expression, LookupOp): self._emit_lookup_op(expression, xml) - elif isinstance(expression, ExprChain): + elif isinstance(expression, Expression): self._emit_expression(expression, xml) elif isinstance(expression, CastExpr): self._emit_cast_expr(expression, xml)