Added empty string parser

This commit is contained in:
2019-11-15 17:49:37 +01:00
parent 2fbda533f1
commit 3a1dea19e8
7 changed files with 65 additions and 11 deletions
+1
View File
@@ -25,6 +25,7 @@ class BuiltinConcepts(Enum):
PARSING = 16 # activated during the parsing. It contains the text to parse
AFTER_PARSING = 17 # activated when the parsing process seems to be finished
CONCEPT_ALREADY_DEFINED = 18 # when you try to add the same concept twice
NOP = 19 # no operation concept. Does nothing
"""
+7 -2
View File
@@ -208,7 +208,8 @@ class Sheerka(Concept):
return result
def process(self, context, return_values, contextual_concepts=None):
log.debug("Evaluating parsing result.")
contextual_concepts_values = [c.value for c in contextual_concepts] if contextual_concepts else []
log.debug(f"Processing parsing result. context concept={contextual_concepts_values}")
# return_values must be a list
if not isinstance(return_values, list):
@@ -317,8 +318,12 @@ class Sheerka(Concept):
"""
for part_key in ConceptParts:
source = getattr(concept, part_key.value)
if source is None or source == "":
if source is None or not isinstance(source, str) or source == "":
# the only sources that I am sure to parse are strings
# I refuse empty strings for performance, I don't want to handle useless NOPConcepts
continue
ret_val = self.expect_one(context, self.parse(context, source))
concept.codes[part_key] = ret_val