summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
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)