Fixed #29: Parsers: Implement parsing memoization
Fixed #77 : Parser: ShortTermMemoryParser should be called separately Fixed #78 : Remove VariableNode usage Fixed #79 : ConceptManager: Implement compile caching Fixed #80 : SheerkaExecute : parsers_key is not correctly computed Fixed #81 : ValidateConceptEvaluator : Validate concept's where and pre clauses right after the parsing Fixed #82 : SheerkaIsAManager: isa() failed when the set as a body Fixed #83 : ValidateConceptEvaluator : Support BNF and SYA Concepts Fixed #84 : ExpressionParser: Implement the parser as a standard parser Fixed #85 : Services: Give order to services Fixed #86 : cannot manage smart_get_attr(the short, color)
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import List
|
||||
|
||||
from core import builtin_helpers
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.builtin_helpers import update_compiled
|
||||
from core.concept import Concept, DEFINITION_TYPE_BNF
|
||||
from core.global_symbols import CONCEPT_COMPARISON_CONTEXT, SyaAssociativity
|
||||
from core.sheerka.services.SheerkaComparisonManager import SheerkaComparisonManager
|
||||
@@ -1270,8 +1271,10 @@ class SyaNodeParser(BaseNodeParser):
|
||||
while len(item.nodes) > 0:
|
||||
res = self.postfix_to_item(sheerka, item.nodes)
|
||||
if isinstance(res, PostFixToItem):
|
||||
items.append(
|
||||
ConceptNode(res.concept, res.start, res.end, self.parser_input.tokens[res.start: res.end + 1]))
|
||||
items.append(ConceptNode(res.concept,
|
||||
res.start,
|
||||
res.end,
|
||||
self.parser_input.tokens[res.start: res.end + 1]))
|
||||
else:
|
||||
items.append(res)
|
||||
item.has_unrecognized |= hasattr(res, "has_unrecognized") and res.has_unrecognized or \
|
||||
@@ -1314,6 +1317,8 @@ class SyaNodeParser(BaseNodeParser):
|
||||
assert meta_orig[0] == meta_new[0]
|
||||
# ---- Sanity check. To remove at some point
|
||||
concept.get_metadata().variables = concept_metadata
|
||||
concept.get_hints().use_copy = True
|
||||
concept.get_hints().need_validation = True
|
||||
|
||||
source = get_text_from_tokens(self.parser_input.tokens[start:end + 1])
|
||||
return PostFixToItem(concept, start, end, has_unrecognized, source)
|
||||
@@ -1354,6 +1359,7 @@ class SyaNodeParser(BaseNodeParser):
|
||||
for infix_to_postfix in valid_infix_to_postfixs:
|
||||
sequence = []
|
||||
has_unrecognized = False
|
||||
errors = []
|
||||
while len(infix_to_postfix.out) > 0:
|
||||
item = self.postfix_to_item(context.sheerka, infix_to_postfix.out)
|
||||
has_unrecognized |= hasattr(item, "has_unrecognized") and item.has_unrecognized or \
|
||||
@@ -1363,10 +1369,30 @@ class SyaNodeParser(BaseNodeParser):
|
||||
item.start,
|
||||
item.end,
|
||||
self.parser_input.tokens[item.start: item.end + 1])
|
||||
|
||||
# validate the concept
|
||||
update_compiled(context, item.concept, errors)
|
||||
if errors:
|
||||
break
|
||||
else:
|
||||
to_insert = item
|
||||
sequence.insert(0, to_insert)
|
||||
|
||||
if errors:
|
||||
if len(errors) == 1:
|
||||
ret.append(
|
||||
self.sheerka.ret(
|
||||
self.name,
|
||||
False,
|
||||
errors[0]))
|
||||
else:
|
||||
ret.append(
|
||||
self.sheerka.ret(
|
||||
self.name,
|
||||
False,
|
||||
self.sheerka.err([e.body for e in errors])))
|
||||
continue
|
||||
|
||||
if has_unrecognized:
|
||||
# Manage some sick cases where missing parenthesis mess the order or the sequence
|
||||
# example "foo bar(one plus two"
|
||||
@@ -1380,7 +1406,7 @@ class SyaNodeParser(BaseNodeParser):
|
||||
self.sheerka.new(
|
||||
BuiltinConcepts.PARSER_RESULT,
|
||||
parser=self,
|
||||
source=parser_input,
|
||||
source=parser_input.as_text(),
|
||||
body=sequence,
|
||||
try_parsed=sequence)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user