From c9a2a1cd045a528e773b3e7705665bec181e84f6 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 26 Mar 2015 16:59:28 +0100 Subject: Always lex , as COMMA, never as NAME Also a testing loop to prolog.lexer. --- prolog/lexer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'prolog') diff --git a/prolog/lexer.py b/prolog/lexer.py index 971e8a6..42d1620 100644 --- a/prolog/lexer.py +++ b/prolog/lexer.py @@ -69,7 +69,8 @@ def t_comment(t): def t_NAME(t): r"'(''|\\.|[^\\'])*'|[a-z][a-zA-Z0-9_]*|[-+*/\\^<>=~:.?@#$&]+|!|;|," - if t.lexer.lexpos >= len(t.lexer.lexdata) or t.lexer.lexdata[t.lexer.lexpos] != '(': + if t.value == ',' or \ + t.lexer.lexpos >= len(t.lexer.lexdata) or t.lexer.lexdata[t.lexer.lexpos] != '(': t.type = operators.get(t.value, 'NAME') return t @@ -88,3 +89,16 @@ def t_error(t): return t lexer = lex.lex() + +if __name__ == '__main__': + while True: + try: + s = input('> ') + except EOFError: + break + if not s: + continue + + lexer.input(s) + tokens = list(lexer) + print(tokens) -- cgit v1.2.1