Logger is now an attribute of the execution context
This commit is contained in:
@@ -100,20 +100,28 @@ class BaseParser:
|
||||
|
||||
if ret.status:
|
||||
value = context.return_value_to_str(ret)
|
||||
context.log(self.log, f"Recognized '{source}' as {value}", self.name)
|
||||
context.log(f"Recognized '{source}' as {value}", self.name)
|
||||
else:
|
||||
context.log(self.log, f"Failed to recognize '{source}'", self.name)
|
||||
context.log(f"Failed to recognize '{source}'", self.name)
|
||||
|
||||
def log_multiple_results(self, context, source, list_of_ret):
|
||||
if not self.log.isEnabledFor(logging.DEBUG):
|
||||
return
|
||||
|
||||
context.log(self.log, f"Recognized '{source}' as multiple concepts", self.name)
|
||||
context.log(f"Recognized '{source}' as multiple concepts", self.name)
|
||||
for r in list_of_ret:
|
||||
value = context.return_value_to_str(r)
|
||||
context.log(self.log, f" Recognized '{value}'", self.name)
|
||||
context.log(f" Recognized '{value}'", self.name)
|
||||
|
||||
def get_return_value_body(self, sheerka, source, tree, try_parse):
|
||||
"""
|
||||
All parsers must return their result in a standard way
|
||||
:param sheerka:
|
||||
:param source:
|
||||
:param tree:
|
||||
:param try_parse:
|
||||
:return:
|
||||
"""
|
||||
if len(self.error_sink) == 1 and isinstance(self.error_sink[0], Concept):
|
||||
return self.error_sink[0]
|
||||
|
||||
|
||||
@@ -665,8 +665,9 @@ class ConceptLexerParser(BaseParser):
|
||||
self.sheerka = context.sheerka
|
||||
concepts_to_resolve = set()
|
||||
|
||||
# ## Gets the grammars
|
||||
for concept, concept_def in concepts_definitions.items():
|
||||
# ## Gets the grammars
|
||||
context.log(f"Resolving grammar for '{concept}'", context.who)
|
||||
concept.init_key() # make sure that the key is initialized
|
||||
grammar = self.get_model(concept_def, concepts_to_resolve)
|
||||
self.concepts_grammars[concept] = grammar
|
||||
|
||||
@@ -56,7 +56,6 @@ class ConceptsWithConceptsParser(BaseParser):
|
||||
prop_name = list(concept.props.keys())[index]
|
||||
concept.compiled[prop_name] = node.concept
|
||||
context.log(
|
||||
self.verbose_log,
|
||||
f"Setting property '{prop_name}='{node.concept}'.",
|
||||
self.name)
|
||||
index += 1
|
||||
@@ -66,7 +65,6 @@ class ConceptsWithConceptsParser(BaseParser):
|
||||
value = sheerka.new(BuiltinConcepts.PARSER_RESULT, parser=self, source=node.source, body=node.node)
|
||||
concept.compiled[prop_name] = [context.sheerka.ret(self.name, True, value)]
|
||||
context.log(
|
||||
self.verbose_log,
|
||||
f"Setting property '{prop_name}'='Python({node.source})'.",
|
||||
self.name)
|
||||
index += 1
|
||||
|
||||
@@ -230,7 +230,7 @@ class DefaultParser(BaseParser):
|
||||
token = self.get_token()
|
||||
if token.value == Keywords.DEF:
|
||||
self.next_token()
|
||||
self.context.log(self.verbose_log, "Keyword DEF found.", self.name)
|
||||
self.context.log("Keyword DEF found.", self.name)
|
||||
return self.parse_def_concept(token)
|
||||
else:
|
||||
return self.parse_isa_concept()
|
||||
@@ -411,14 +411,13 @@ class DefaultParser(BaseParser):
|
||||
|
||||
# ask the other parsers if they recognize the tokens
|
||||
with self.context.push(self.name, desc=f"Parsing {keyword}") as sub_context:
|
||||
sub_context.log_new(self.verbose_log)
|
||||
to_parse = self.sheerka.ret(
|
||||
sub_context.who,
|
||||
True,
|
||||
self.sheerka.new(BuiltinConcepts.USER_INPUT, body=tokens))
|
||||
steps = [BuiltinConcepts.PARSING]
|
||||
parsed = self.sheerka.execute(sub_context, to_parse, steps, self.verbose_log)
|
||||
parsing_result = core.builtin_helpers.expect_one(sub_context, parsed, self.verbose_log)
|
||||
parsed = self.sheerka.execute(sub_context, to_parse, steps)
|
||||
parsing_result = core.builtin_helpers.expect_one(sub_context, parsed)
|
||||
sub_context.add_values(return_values=parsing_result)
|
||||
|
||||
if not parsing_result.status:
|
||||
|
||||
@@ -24,17 +24,17 @@ class ExactConceptParser(BaseParser):
|
||||
:return:
|
||||
"""
|
||||
|
||||
context.log(self.verbose_log, f"Parsing '{text}'", self.name)
|
||||
context.log(f"Parsing '{text}'", self.name)
|
||||
res = []
|
||||
sheerka = context.sheerka
|
||||
try:
|
||||
words = self.get_words(text)
|
||||
except LexerError as e:
|
||||
context.log(self.verbose_log, f"Error found in tokenizer {e}", self.name)
|
||||
context.log(f"Error found in tokenizer {e}", self.name)
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.ERROR, body=e))
|
||||
|
||||
if len(words) > self.MAX_WORDS_SIZE:
|
||||
context.log(self.verbose_log, f"Max words reached. Stopping.", self.name)
|
||||
context.log(f"Max words reached. Stopping.", self.name)
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, body=text))
|
||||
|
||||
recognized = False
|
||||
@@ -50,7 +50,7 @@ class ExactConceptParser(BaseParser):
|
||||
concepts = result if isinstance(result, list) else [result]
|
||||
|
||||
for concept in concepts:
|
||||
context.log(self.verbose_log, f"Recognized concept {concept}.", self.name)
|
||||
context.log(f"Recognized concept {concept}.", self.name)
|
||||
# update the properties if needed
|
||||
for i, token in enumerate(combination):
|
||||
if token.startswith(VARIABLE_PREFIX):
|
||||
@@ -59,7 +59,6 @@ class ExactConceptParser(BaseParser):
|
||||
if self.verbose_log.isEnabledFor(logging.DEBUG):
|
||||
prop_name = list(concept.props.keys())[index]
|
||||
context.log(
|
||||
self.verbose_log,
|
||||
f"Added property {index}: {prop_name}='{words[i]}'.",
|
||||
self.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user