summaryrefslogtreecommitdiff
path: root/prolog/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/common.py')
-rw-r--r--prolog/common.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/prolog/common.py b/prolog/common.py
index 5f16364..16f7769 100644
--- a/prolog/common.py
+++ b/prolog/common.py
@@ -2,6 +2,7 @@
import operator
import prolog.engine
+from prolog.util import tokenize
from server.hints import Hint, HintPopup
id = 1
@@ -36,7 +37,15 @@ def check_syntax(code, aux_code):
return []
def hint(code, aux_code):
- tokens = prolog.util.tokenize(code)
+ tokens = tokenize(code)
+ hints = []
+
+ # rules like a(X) :- fail.
+ for i, t in enumerate(tokens[:-2]):
+ t1 = tokens[i+1]
+ t2 = tokens[i+2]
+ if t.val == ':-' and t1.val in ('fail', 'false') and t2.val == '.':
+ hints += [{'id': 'fail_rule_markup', 'start': t.pos, 'end': t2.pos + len(t2.val)}]
# a,b,c are a bit dangerous when crossing the river exercise is being solved
# what about potential numbers after letters?
@@ -44,7 +53,7 @@ def hint(code, aux_code):
targets = {'a', 'b', 'c', 'x', 'y', 'z', 'h', 't', 'l', 's', 'v', 'w'}
marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t.type == 'NAME' and t.val in targets]
if marks:
- return [{'id': 'noncapitalised_variable_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
- [{'id': 'noncapitalised_variable'}]
+ hints += [{'id': 'noncapitalised_variable_markup', 'start': m[0], 'end': m[1]} for m in marks] + \
+ [{'id': 'noncapitalised_variable'}]
- return []
+ return hints