summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-03-26 16:59:28 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:03 +0200
commitc9a2a1cd045a528e773b3e7705665bec181e84f6 (patch)
tree9d7556c8aaeed0bbed716cabae5a583f673443ad /prolog
parentd492e360586c4ff11f5c87d6d4212cdf2bc9bb36 (diff)
Always lex , as COMMA, never as NAME
Also a testing loop to prolog.lexer.
Diffstat (limited to 'prolog')
-rw-r--r--prolog/lexer.py16
1 files changed, 15 insertions, 1 deletions
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)