def normalize_infix_expression(counter, expression):
# TODO Unfake this normalization
return {
- '+': normalize_basic_infix_operation,
- '-': normalize_basic_infix_operation,
- '*': normalize_basic_infix_operation,
- '//': normalize_basic_infix_operation,
- '%': normalize_basic_infix_operation,
- '==': fake_normalization,
- '<=': fake_normalization,
- '>=': fake_normalization,
- '!=': fake_normalization,
- '<': fake_normalization,
- '>': fake_normalization,
- 'and': fake_normalization,
- 'or': fake_normalization,
- }[expression.operator](counter, expression)
+ 'multiplication_level': normalize_basic_infix_operation,
+ 'addition_level': normalize_basic_infix_operation,
+ 'comparison_level': fake_normalization,
+ 'and_level': fake_normalization,
+ 'or_level': fake_normalization,
+ }[expression.order](counter, expression)
def normalize_expression(counter, expression):
return {
'addition_level',
)(index, tokens)
-def _equality_level_expression_parser(index, tokens):
+def _comparison_level_expression_parser(index, tokens):
return _left_recursive_infix_operator_parser(
- lambda token: token.type == 'equality_level_operator',
+ lambda token: token.type == 'comparison_level_operator',
_addition_level_expression_parser,
- 'equality_level',
+ 'comparison_level',
)(index, tokens)
def _and_level_expression_parser(index, tokens):
return _left_recursive_infix_operator_parser(
lambda token: token.type == 'symbol' and token.match == 'and',
- _equality_level_expression_parser,
+ _comparison_level_expression_parser,
'and_level',
)(index, tokens)
('integer_literal', r'\d+'),
('symbol', r'[a-z]+'),
('single_quoted_string_literal', r"'.*?'"),
- ('equality_level_operator', r'(<=|>=|==|!=|<|>)'),
+ ('comparison_level_operator', r'(<=|>=|==|!=|<|>)'),
('assignment_operator', r'='),
('addition_level_operator', r'(\+|-)'),
('multiplication_level_operator', r'(\*|//|%)'),
self.assertEqual(
tokenize('=='),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='==',
index=0,
line=1,
self.assertEqual(
tokenize('>='),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='>=',
index=0,
line=1,
self.assertEqual(
tokenize('<='),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='<=',
index=0,
line=1,
self.assertEqual(
tokenize('>'),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='>',
index=0,
line=1,
self.assertEqual(
tokenize('<'),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='<',
index=0,
line=1,
self.assertEqual(
tokenize('!='),
(Token(
- type='equality_level_operator',
+ type='comparison_level_operator',
match='!=',
index=0,
line=1,
'>': 'greaterThan',
}
-def transform_equality_level_expression(accumulators, expression):
+def transform_comparison_level_expression(accumulators, expression):
# Transform expressions like 1 < 2 < 3 into expressions like 1 < 2 && 2 < 3
- if isinstance(expression.left, parsing.FurInfixExpression) and expression.left.order == 'equality_level':
- left = transform_equality_level_expression(
+ if isinstance(expression.left, parsing.FurInfixExpression) and expression.left.order == 'comparison_level':
+ left = transform_comparison_level_expression(
accumulators,
expression.left
)
return CVariableExpression(variable=expression.variable)
def transform_infix_expression(accumulators, expression):
- if expression.order == 'equality_level':
- return transform_equality_level_expression(accumulators, expression)
+ if expression.order == 'comparison_level':
+ return transform_comparison_level_expression(accumulators, expression)
INFIX_OPERATOR_TO_FUNCTION_NAME = {
'+': 'add',