From 5545518de1f511fff065469f5398b59e6e6f38e4 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Tue, 25 Dec 2012 19:12:33 +0200 Subject: [PATCH] Parse slightly more. --- builder.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/builder.py b/builder.py index f65a9a979..8f31fcf9a 100755 --- a/builder.py +++ b/builder.py @@ -80,12 +80,12 @@ def p_codeblock_last(t): def p_expression_atom(t): 'expression : ATOM' print('Atom: ' + t[1]) - pass + t[0] = t[1] def p_expression_string(t): 'expression : STRING' print('String: ' + t[1]) - pass + t[0] = t[1] def p_statement_assign(t): 'statement : expression EQUALS statement' @@ -93,13 +93,11 @@ def p_statement_assign(t): def p_statement_func_call(t): 'statement : expression LPAREN args RPAREN' - print('Function call: ' + str(t[1])) # t[1]) - pass + print('Function call: %s. Args: %s' % (str(t[1]), str(t[3]))) # t[1]) def p_statement_method_call(t): 'statement : expression DOT expression LPAREN args RPAREN' - print('Method call: ' + str(t[1])) - pass + print('Method call: %s %s. Args: %s' % (str(t[1]), str(t[3]), str(t[5]))) def p_statement_expression(t): 'statement : expression' @@ -108,11 +106,11 @@ def p_statement_expression(t): def p_args_multiple(t): 'args : statement COMMA args' - pass + t[0] = [t[1]] + t[3] def p_args_single(t): 'args : statement' - pass + t[0] = [t[1]] def p_args_none(t): 'args :' @@ -137,8 +135,8 @@ def test_lexer(): print(tok) def test_parser(): - code = """funccall('something') - method.call(abc) + code = """func_call('something', 'or else') + objectname.methodname(abc) """ lexer = lex.lex() parser = yacc.yacc()