aboutsummaryrefslogtreecommitdiff
path: root/builder.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2012-12-23 16:54:52 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2012-12-23 16:54:52 +0200
commit5ab75888737c7e6dea15475e8423e3f8ca83613d (patch)
treeb04d10375af3db65bf1944e8a44bfda7eb6a70cf /builder.py
parenta428c953ffd017933c7540927ecc6c1ee83f1a8d (diff)
downloadmeson-5ab75888737c7e6dea15475e8423e3f8ca83613d.zip
meson-5ab75888737c7e6dea15475e8423e3f8ca83613d.tar.gz
meson-5ab75888737c7e6dea15475e8423e3f8ca83613d.tar.bz2
Created simple parser.
Diffstat (limited to 'builder.py')
-rwxr-xr-xbuilder.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/builder.py b/builder.py
index e432109..03e55b6 100755
--- a/builder.py
+++ b/builder.py
@@ -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