diff options
Diffstat (limited to 'prolog')
-rw-r--r-- | prolog/common.py | 38 | ||||
-rw-r--r-- | prolog/problems/family_relations/grandparent_2/common.py | 2 | ||||
-rw-r--r-- | prolog/sl.py | 8 |
3 files changed, 40 insertions, 8 deletions
diff --git a/prolog/common.py b/prolog/common.py index 4636936..65fc218 100644 --- a/prolog/common.py +++ b/prolog/common.py @@ -16,14 +16,38 @@ hint_type = { 'monkey_change': HintPopup('monkey_change', style='change'), 'monkey_insert': HintPopup('monkey_insert', style='insert'), 'monkey_remove': HintPopup('monkey_remove', style='remove'), + 'noncapitalised_variable': Hint('noncapitalised_variable'), + 'noncapitalised_variable_markup': HintPopup('noncapitalised_variable_markup'), } def hint(code, aux_code): - # Check program for syntax errors. - engine_id, output = prolog.engine.create(code=code) - if engine_id is not None: - prolog.engine.destroy(engine_id) - if 'error' in map(operator.itemgetter(0), output): - errors_msg = '\n'.join(['{}: {}'.format(m_type, m_text) for m_type, m_text in output]) - return [{'id': 'syntax_error', 'args': {'messages': errors_msg}}] + + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + + # Check program for syntax errors. + if 'error' in map(operator.itemgetter(0), output): + errors_msg = '\n'.join(['{}: {}'.format(m_type, m_text) for m_type, m_text in output]) + return [{'id': 'syntax_error', 'args': {'messages': errors_msg}}] + + tokens = prolog.util.tokenize(code) + + # a,b,c are a bit dangerous when crossing the river exercise is being solved + # what about potential numbers after letters? + # this will have to be solved more generally + targets = [prolog.util.Token('NAME', 'x'), prolog.util.Token('NAME', 'y'), + prolog.util.Token('NAME', 'z'), prolog.util.Token('NAME', 'a'), + prolog.util.Token('NAME', 'b'), prolog.util.Token('NAME', 'c')] + marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] + if marks: + return [{'id': 'noncapitalised_variable_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ + [{'id': 'noncapitalised_variable'}] + + except socket.timeout as ex: + pass + + finally: + if engine_id is not None: + prolog.engine.destroy(engine_id) + return [] diff --git a/prolog/problems/family_relations/grandparent_2/common.py b/prolog/problems/family_relations/grandparent_2/common.py index 1cfdfe8..1665c18 100644 --- a/prolog/problems/family_relations/grandparent_2/common.py +++ b/prolog/problems/family_relations/grandparent_2/common.py @@ -139,5 +139,5 @@ def hint(code, aux_code): # 1o can we make predicate_always_false a ghint? # with this in mind: how can we supply/know the correct target name and arity? # 2x popraviti je potrebno spremni tekst glede na novo lokacijo gumba Namig -# 3 what's the name of \= token? And what of =\= token? +# 3x what's the name of \= token? And what of =\= token? # 4 final hint! This very much improves the user experience, adds knowledge, therefore needs to be implemented now! diff --git a/prolog/sl.py b/prolog/sl.py index 2bd2b56..5a408a7 100644 --- a/prolog/sl.py +++ b/prolog/sl.py @@ -42,4 +42,12 @@ hint = { 'monkey_remove': '''\ <p>Odstrani ta cilj.</p> ''', + + 'noncapitalised_variable': '''\ +<p>Preveri kodo, označeni so deli, kjer bi morda moral uporabiti velike črke, ki označujejo spremenljivke v prologu.</p> +''', + + 'noncapitalised_variable_markup': '''\ +<p>Je prav, da je to pisano z malo?</p> +''', } |