Skip to content

Commit

Permalink
Fix literal parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tbittar committed Aug 21, 2024
1 parent bcafb95 commit 75266a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/andromede/expression/parsing/parse_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
ExpressionNodeEfficient,
ExpressionRange,
PortFieldNode,
literal,
param,
)
from andromede.expression.linear_expression_efficient import (
LinearExpressionEfficient,
literal,
var,
wrap_in_linear_expr,
)
from andromede.expression.parsing.antlr.ExprLexer import ExprLexer
from andromede.expression.parsing.antlr.ExprParser import ExprParser
Expand Down Expand Up @@ -65,7 +66,7 @@ def visitFullexpr(

# Visit a parse tree produced by ExprParser#number.
def visitNumber(self, ctx: ExprParser.NumberContext) -> LinearExpressionEfficient:
return literal(float(ctx.NUMBER().getText())) # type: ignore
return wrap_in_linear_expr(literal(float(ctx.NUMBER().getText()))) # type: ignore

# Visit a parse tree produced by ExprParser#identifier.
def visitIdentifier(
Expand Down Expand Up @@ -117,7 +118,7 @@ def _convert_identifier(self, identifier: str) -> LinearExpressionEfficient:
if self.identifiers.is_variable(identifier):
return var(identifier)
elif self.identifiers.is_parameter(identifier):
return param(identifier)
return wrap_in_linear_expr(param(identifier))
raise ValueError(f"{identifier} is not a valid variable or parameter name.")

# Visit a parse tree produced by ExprParser#portField.
Expand Down

0 comments on commit 75266a0

Please sign in to comment.