aboutsummaryrefslogtreecommitdiff
path: root/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'parser.py')
-rwxr-xr-xparser.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/parser.py b/parser.py
index 639a19a..2fd6343 100755
--- a/parser.py
+++ b/parser.py
@@ -76,29 +76,29 @@ def p_codeblock(t):
def p_codeblock_last(t):
'codeblock : statement EOL'
- cb = nodes.CodeBlock()
+ cb = nodes.CodeBlock(t.lineno(1))
cb.prepend(t[1])
t[0] = cb
def p_expression_atom(t):
'expression : ATOM'
- t[0] = nodes.AtomExpression(t[1])
+ t[0] = nodes.AtomExpression(t[1], t.lineno(1))
def p_expression_string(t):
'expression : STRING'
- t[0] = nodes.StringExpression(t[1])
+ t[0] = nodes.StringExpression(t[1], t.lineno(1))
def p_statement_assign(t):
'statement : expression EQUALS statement'
- t[0] = nodes.Assignment(t[1], t[3])
+ t[0] = nodes.Assignment(t[1], t[3], t.lineno(1))
def p_statement_func_call(t):
'statement : expression LPAREN args RPAREN'
- t[0] = nodes.FunctionCall(t[1], t[3])
+ t[0] = nodes.FunctionCall(t[1], t[3], t.lineno(1))
def p_statement_method_call(t):
'statement : expression DOT expression LPAREN args RPAREN'
- t[0] = nodes.MethodCall(t[1], t[3], t[5])
+ t[0] = nodes.MethodCall(t[1], t[3], t[5], t.lineno(1))
def p_statement_expression(t):
'statement : expression'
@@ -112,13 +112,13 @@ def p_args_multiple(t):
def p_args_single(t):
'args : statement'
- args = nodes.Arguments()
+ args = nodes.Arguments(t.lineno(1))
args.prepend(t[1])
t[0] = args
def p_args_none(t):
'args :'
- t[0] = nodes.Arguments()
+ t[0] = nodes.Arguments(t.lineno(0))
def p_error(t):
print('Parser errored out at: ' + t.value)
@@ -141,8 +141,7 @@ def test_lexer():
def test_parser():
code = """func_call('something', 'or else')
objectname.methodname(abc)
- emptycall()
- """
+ emptycall()"""
print(build_ast(code))
def build_ast(code):