From aef533920831d96a4d39271bdbcbcd8e2e76bc4c Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 13 Mar 2016 21:20:00 +0100 Subject: Prolog: add generic style check for ":- false." --- prolog/common.py | 17 +++++++++++++---- prolog/sl.py | 4 ++++ 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 @@ -52,5 +52,9 @@ hint = { 'noncapitalised_variable_markup': '''\

Je prav, da je to pisano z malo?

+''', + + 'fail_rule_markup': '''\ +

Pravila, ki nikoli ne drži, nikoli ne potrebuješ.

''', } -- cgit v1.2.1