return result_parser
-NodeMetadata = collections.namedtuple(
- 'NodeMetadata',
- [
- 'index',
- 'line',
- ],
-)
-
FurIntegerLiteralExpression = collections.namedtuple(
'FurIntegerLiteralExpression',
[
FurSymbolExpression = collections.namedtuple(
'FurSymbolExpression',
[
+ 'metadata',
'symbol',
],
)
FurNegationExpression = collections.namedtuple(
'FurNegationExpression',
[
+ 'metadata',
'value',
],
)
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)
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(
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,
'FurListItemExpression',
[
'list_expression',
+ 'metadata',
'index_expression',
],
)
FurFunctionCallExpression = collections.namedtuple(
'FurFunctionCallExpression',
[
+ 'metadata',
'function',
'arguments',
],
if not success:
return failure
+ metadata = tokens[index].metadata
+
success, index, index_expression = _bracket_wrapped_parser(_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,
if not success:
return failure
+ metadata = tokens[index].metadata
+
success, index, arguments = _parenthese_wrapped_parser(_comma_separated_expression_list_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,
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: