X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=parsing.py;h=014d74b0e5ab75227825097eb98fa7b4be8fc076;hp=12b93f585d22a1c47e11b5ccf1ad47c68139fcb7;hb=3a076cfd2c46c9f3b51815facd613445722a340b;hpb=61733d6070859e6a639ae4b34faec9aacca52a29 diff --git a/parsing.py b/parsing.py index 12b93f5..014d74b 100644 --- a/parsing.py +++ b/parsing.py @@ -36,14 +36,6 @@ def _zero_or_more_parser(formatter, parser): return result_parser -NodeMetadata = collections.namedtuple( - 'NodeMetadata', - [ - 'index', - 'line', - ], -) - FurIntegerLiteralExpression = collections.namedtuple( 'FurIntegerLiteralExpression', [ @@ -61,6 +53,7 @@ FurStringLiteralExpression = collections.namedtuple( FurSymbolExpression = collections.namedtuple( 'FurSymbolExpression', [ + 'metadata', 'symbol', ], ) @@ -68,6 +61,7 @@ FurSymbolExpression = collections.namedtuple( FurNegationExpression = collections.namedtuple( 'FurNegationExpression', [ + 'metadata', 'value', ], ) @@ -135,7 +129,14 @@ def _string_literal_expression_parser(index, tokens): def _symbol_expression_parser(index, tokens): if tokens[index].type == 'symbol': - return (True, index + 1, FurSymbolExpression(symbol=tokens[index].match)) + return ( + True, + index + 1, + FurSymbolExpression( + metadata=tokens[index].metadata, + symbol=tokens[index].match, + ), + ) return (False, index, None) @@ -249,12 +250,14 @@ def _negation_expression_parser(index, tokens): if tokens[index].match != '-': return failure + metadata = tokens[index].metadata + success, index, value = _dot_expression_parser(index + 1, tokens) if not success: return failure - return (True, index, FurNegationExpression(value=value)) + return (True, index, FurNegationExpression(metadata=metadata, value=value)) def _negation_level_expression_parser(index, tokens): return _or_parser( @@ -279,10 +282,7 @@ def _left_recursive_infix_operator_parser(operator_token_matcher, operand_parser if success: result = FurInfixExpression( - metadata=NodeMetadata( - index=tokens[index].index, - line=tokens[index].line, - ), + metadata=tokens[index].metadata, order=order, operator=tokens[index].match, left=result, @@ -368,6 +368,7 @@ FurListItemExpression = collections.namedtuple( 'FurListItemExpression', [ 'list_expression', + 'metadata', 'index_expression', ], ) @@ -375,6 +376,7 @@ FurListItemExpression = collections.namedtuple( FurFunctionCallExpression = collections.namedtuple( 'FurFunctionCallExpression', [ + 'metadata', 'function', 'arguments', ], @@ -424,6 +426,8 @@ def _list_item_expression_parser(index, tokens): if not success: return failure + metadata = tokens[index].metadata + success, index, index_expression = _bracket_wrapped_parser(_expression_parser)( index, tokens, @@ -437,9 +441,12 @@ def _list_item_expression_parser(index, tokens): # We can't give this a better name without a bunch of checks, however. list_expression = FurListItemExpression( list_expression=list_expression, + metadata=metadata, index_expression=index_expression, ) + metadata = tokens[index].metadata + success, index, index_expression = _bracket_wrapped_parser(_expression_parser)( index, tokens, @@ -460,6 +467,8 @@ def _function_call_expression_parser(index, tokens): if not success: return failure + metadata = tokens[index].metadata + success, index, arguments = _parenthese_wrapped_parser(_comma_separated_expression_list_parser)( index, tokens, @@ -472,10 +481,13 @@ def _function_call_expression_parser(index, tokens): # "function" is actually the full function call if the next parse attempt doesn't succeed # We can't give this a better name without a bunch of checks, however. function = FurFunctionCallExpression( + metadata=metadata, function=function, arguments=arguments, ) + metadata = tokens[index].metadata + success, index, arguments = _parenthese_wrapped_parser(_comma_separated_expression_list_parser)( index, tokens, @@ -549,7 +561,7 @@ def _assignment_statement_parser(index, tokens): if tokens[index].type == 'symbol': target = tokens[index].match - target_assignment_line = tokens[index].line + target_assignment_line = tokens[index].metadata.line index += 1 else: