summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-13 21:20:00 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-13 21:20:00 +0100
commitaef533920831d96a4d39271bdbcbcd8e2e76bc4c (patch)
treec2e3299cff339988cc955600ee6be99109cc2176 /prolog
parent84ac2d8dc04f9a882e6c558319c3029d4c5470e0 (diff)
Prolog: add generic style check for ":- false."
Diffstat (limited to 'prolog')
-rw-r--r--prolog/common.py17
-rw-r--r--prolog/sl.py4
2 files changed, 17 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
diff --git a/prolog/sl.py b/prolog/sl.py
index 095d253..ea15f93 100644
--- a/prolog/sl.py
+++ b/prolog/sl.py
@@ -53,4 +53,8 @@ hint = {
'noncapitalised_variable_markup': '''\
<p>Je prav, da je to pisano z malo?</p>
''',
+
+ 'fail_rule_markup': '''\
+<p>Pravila, ki nikoli ne drži, nikoli ne potrebuješ.</p>
+''',
}