diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2012-12-23 16:54:52 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2012-12-23 16:54:52 +0200 |
commit | 5ab75888737c7e6dea15475e8423e3f8ca83613d (patch) | |
tree | b04d10375af3db65bf1944e8a44bfda7eb6a70cf /builder.py | |
parent | a428c953ffd017933c7540927ecc6c1ee83f1a8d (diff) | |
download | meson-5ab75888737c7e6dea15475e8423e3f8ca83613d.zip meson-5ab75888737c7e6dea15475e8423e3f8ca83613d.tar.gz meson-5ab75888737c7e6dea15475e8423e3f8ca83613d.tar.bz2 |
Created simple parser.
Diffstat (limited to 'builder.py')
-rwxr-xr-x | builder.py | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -17,5 +17,40 @@ import ply.lex as lex import ply.yacc as yacc +tokens = ['LPAREN', + 'RPAREN', + 'VARIABLE', + 'COMMENT', + 'EQUALS', + 'COMMA', + 'DOT'] + +t_EQUALS = '=' +t_LPAREN = '\(' +t_RPAREN = '\)' +t_VARIABLE = '[a-zA-Z][_0-9a-zA-Z]*' +t_COMMENT = '\#[^\n]*' +t_COMMA = ',' +t_DOT = '\.' + +t_ignore = ' \t\n' + +def t_error(t): + print("Illegal character '%s'" % t.value[0]) + t.lexer.skip(1) + +def test_lexer(): + s = """hello = (something) # this = (that) + function(h) + obj.method(lll) + """ + lexer = lex.lex() + lexer.input(s) + while True: + tok = lexer.token() + if not tok: + break + print(tok) + if __name__ == '__main__': - pass
\ No newline at end of file + test_lexer()
\ No newline at end of file |