summaryrefslogtreecommitdiff
path: root/prolog/lexer.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/lexer.py')
-rw-r--r--prolog/lexer.py17
1 files changed, 4 insertions, 13 deletions
diff --git a/prolog/lexer.py b/prolog/lexer.py
index f2b19dc..4e6c746 100644
--- a/prolog/lexer.py
+++ b/prolog/lexer.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
# CodeQ: an online programming tutor.
-# Copyright (C) 2015 UL FRI
+# Copyright (C) 2015-2017 UL FRI
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
@@ -18,19 +18,11 @@
import ply.lex as lex
-# LEXER
-
-#states = (
-# ('comment', 'exclusive'),
-#)
-
-# tokens; treat operators as names if followed by (
operators = {
r':-': 'FROM',
r'-->': 'FROMDCG',
r'->': 'IMPLIES',
r'\+': 'NOT',
- r'not': 'NOT',
r'=': 'EQU',
r'\=': 'NEQU',
r'==': 'EQ',
@@ -89,16 +81,15 @@ t_UREAL = r'[0-9]+\.[0-9]+([eE][-+]?[0-9]+)?|inf|nan'
t_VARIABLE = r'(_|[A-Z])[a-zA-Z0-9_]*'
t_STRING = r'"(""|\\.|[^\"])*"'
-# no support for nested comments yet
+# TODO support nested comments
def t_comment(t):
r'(/\*(.|\n)*?\*/)|(%.*)'
pass
def t_NAME(t):
r"'(''|\\.|[^\\'])*'|[a-z][a-zA-Z0-9_]*|[-+*/\\^<>=~:.?@#$&]+|!|;|,"
- 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 appropriate tokens for names that are operators
+ t.type = operators.get(t.value, 'NAME')
return t
t_ignore = ' \t'