Parse slightly more.

pull/15/head
Jussi Pakkanen 12 years ago
parent 6373bff4ff
commit 5545518de1
  1. 18
      builder.py

@ -80,12 +80,12 @@ def p_codeblock_last(t):
def p_expression_atom(t): def p_expression_atom(t):
'expression : ATOM' 'expression : ATOM'
print('Atom: ' + t[1]) print('Atom: ' + t[1])
pass t[0] = t[1]
def p_expression_string(t): def p_expression_string(t):
'expression : STRING' 'expression : STRING'
print('String: ' + t[1]) print('String: ' + t[1])
pass t[0] = t[1]
def p_statement_assign(t): def p_statement_assign(t):
'statement : expression EQUALS statement' 'statement : expression EQUALS statement'
@ -93,13 +93,11 @@ def p_statement_assign(t):
def p_statement_func_call(t): def p_statement_func_call(t):
'statement : expression LPAREN args RPAREN' 'statement : expression LPAREN args RPAREN'
print('Function call: ' + str(t[1])) # t[1]) print('Function call: %s. Args: %s' % (str(t[1]), str(t[3]))) # t[1])
pass
def p_statement_method_call(t): def p_statement_method_call(t):
'statement : expression DOT expression LPAREN args RPAREN' 'statement : expression DOT expression LPAREN args RPAREN'
print('Method call: ' + str(t[1])) print('Method call: %s %s. Args: %s' % (str(t[1]), str(t[3]), str(t[5])))
pass
def p_statement_expression(t): def p_statement_expression(t):
'statement : expression' 'statement : expression'
@ -108,11 +106,11 @@ def p_statement_expression(t):
def p_args_multiple(t): def p_args_multiple(t):
'args : statement COMMA args' 'args : statement COMMA args'
pass t[0] = [t[1]] + t[3]
def p_args_single(t): def p_args_single(t):
'args : statement' 'args : statement'
pass t[0] = [t[1]]
def p_args_none(t): def p_args_none(t):
'args :' 'args :'
@ -137,8 +135,8 @@ def test_lexer():
print(tok) print(tok)
def test_parser(): def test_parser():
code = """funccall('something') code = """func_call('something', 'or else')
method.call(abc) objectname.methodname(abc)
""" """
lexer = lex.lex() lexer = lex.lex()
parser = yacc.yacc() parser = yacc.yacc()

Loading…
Cancel
Save