31 lines
948 B
Python
31 lines
948 B
Python
from core.builtin_concepts import BuiltinConcepts
|
|
from parsers.BaseParser import BaseParser
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class EmptyStringParser(BaseParser):
|
|
"""
|
|
To parse empty or blank strings
|
|
"""
|
|
|
|
def __init__(self):
|
|
BaseParser.__init__(self, "NullParser")
|
|
|
|
def parse(self, context, text):
|
|
sheerka = context.sheerka
|
|
|
|
if isinstance(text, str) and text.strip() == "" or \
|
|
isinstance(text, list) and text == [] or \
|
|
text is None:
|
|
log.debug(f"Recognized '{text}' as BuiltinConcepts.NOP.")
|
|
return sheerka.ret(self.name, True, sheerka.new(
|
|
BuiltinConcepts.PARSER_RESULT,
|
|
parser=self,
|
|
source="",
|
|
body=sheerka.new(BuiltinConcepts.NOP)))
|
|
|
|
log.debug(f"Failed to recognize '{text}'")
|
|
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.NOT_FOR_ME))
|