Commit 6511d03b authored by dbarbera's avatar dbarbera
Browse files

Refactor expression rules in grammar

parent 931862cd
......@@ -1219,12 +1219,10 @@ def expression(root, context):
return neg_expression(root, context)
elif root.type == lexer.PAREN:
return expression(root.children[0], context)
elif root.type == lexer.PRIMPATH:
return primary_path(root, context)
elif root.type == lexer.IFTHENELSE:
return if_then_else_expression(root, context)
elif root.type == lexer.LITERAL:
return literal(root.children[0], context)
elif root.type == lexer.PRIMARY:
return primary(root.children[0], context)
else:
raise NotImplementedError
......@@ -1464,14 +1462,12 @@ def if_then_else_expression(root, context):
return expr, errors, warnings
def literal(root, context):
def primary(root, context):
''' Literal expression analysis '''
prim, errors, warnings = None, [], []
if root.type == lexer.ID:
prim = ogAST.PrimPath()
prim.value = [root.text]
prim.exprType = UNKNOWN_TYPE
if root.type == lexer.PATH:
return primary_path(root, context)
elif root.type == lexer.INT:
prim = ogAST.PrimInteger()
prim.value = [root.text.lower()]
......@@ -1545,7 +1541,7 @@ def literal(root, context):
prim.value = []
for elem in root.getChildren():
# SEQUENCE OF elements cannot have fieldnames/indexes
prim_elem, prim_elem_errors, prim_elem_warnings = literal(elem, context)
prim_elem, prim_elem_errors, prim_elem_warnings = primary(elem, context)
errors += prim_elem_errors
warnings += prim_elem_warnings
prim_elem.inputString = get_input_string(elem)
......
......@@ -82,8 +82,8 @@ tokens {
PARAMNAMES;
PARAMS;
PAREN;
PATH;
PRIMARY;
PRIMPATH;
PROCEDURE;
PROCEDURE_CALL;
PROCEDURE_NAME;
......@@ -798,36 +798,33 @@ field_selection
: (('!'|'.') field_name);
expression
: operand0 ( IMPLIES^ operand0)* ;
operand0
: operand1 (( (OR^ ELSE?) | XOR^ ) operand1)*;
operand1
: operand2 ( AND^ THEN? operand2)*;
operand2
: operand3 (( EQ^ | NEQ^ | GT^ | GE^ | LT^ | LE^ | IN^ ) operand3)*;
operand3
: operand4 (( PLUS^ | DASH^ | APPEND^ ) operand4)*;
operand4
: operand5 (( ASTERISK^ | DIV^ | MOD^ | REM^ ) operand5)*;
operand5
: primary
| NOT^ operand5
| DASH operand5 -> ^(NEG operand5);
primary
: ID primary_params+ -> ^(PRIMPATH ID primary_params*)
| literal -> ^(LITERAL literal)
: binary_expression;
binary_expression
: binary_expression_0 ( IMPLIES^ binary_expression_0)*;
binary_expression_0
: binary_expression_1 (( (OR^ ELSE?) | XOR^ ) binary_expression_1)*;
binary_expression_1
: binary_expression_2 ( AND^ THEN? binary_expression_2)*;
binary_expression_2
: binary_expression_3 (( EQ^ | NEQ^ | GT^ | GE^ | LT^ | LE^ | IN^ ) binary_expression_3)*;
binary_expression_3
: binary_expression_4 (( PLUS^ | DASH^ | APPEND^ ) binary_expression_4)*;
binary_expression_4
: unary_expression (( ASTERISK^ | DIV^ | MOD^ | REM^ ) unary_expression)*;
unary_expression
: primary_expression
| NOT^ unary_expression
| DASH unary_expression -> ^(NEG unary_expression);
primary_expression
: primary -> ^(PRIMARY primary)
| '(' expression ')' -> ^(PAREN expression)
| conditional_ground_expression
;
literal
primary
: BITSTR^
| OCTSTR^
| TRUE^
......@@ -838,8 +835,8 @@ literal
| MINUS_INFINITY^
| INT^
| FLOAT^
| ID^
| choiceValue
| ID ':' expression -> ^(CHOICE ID expression)
| ID primary_params* -> ^(PATH ID primary_params*)
| '{' '}' -> ^(EMPTYSTR)
| '{'
MANTISSA mant=INT COMMA
......@@ -847,11 +844,11 @@ literal
EXPONENT exp=INT
'}' -> ^(FLOAT2 $mant $bas $exp)
| '{'
namedValue (COMMA namedValue)*
'}' -> ^(SEQUENCE namedValue+)
named_value (COMMA named_value)*
'}' -> ^(SEQUENCE named_value+)
| '{'
literal (COMMA literal)*
'}' -> ^(SEQOF literal+)
primary (COMMA primary)*
'}' -> ^(SEQOF primary+)
;
informal_text
......@@ -859,14 +856,8 @@ informal_text
-> ^(INFORMAL_TEXT STRING);
// hello:5 (CHOICE field value)
choiceValue
: choice=ID ':' expression
-> ^(CHOICE $choice expression);
// { a 5 } (SEQUENCE field value)
namedValue
named_value
: ID expression;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment