Introduced ParserInput
This commit is contained in:
@@ -9,6 +9,25 @@ from core.sheerka_logger import get_logger
|
||||
from core.tokenizer import TokenKind, Keywords, Token, Tokenizer
|
||||
|
||||
|
||||
# # keep a cache for the parser input
|
||||
# pi_cache = Cache(default=lambda key: ParserInput(key), max_size=20)
|
||||
#
|
||||
#
|
||||
# def get_parser_input(text, tokens=None, length=None):
|
||||
# """
|
||||
# Returns new or existing parser input
|
||||
# :param text:
|
||||
# :param tokens:
|
||||
# :param length:
|
||||
# :return:
|
||||
# """
|
||||
# if tokens is None or pi_cache.has(text):
|
||||
# return pi_cache.get(text)
|
||||
# pi = ParserInput(text, tokens, length)
|
||||
# pi_cache.put(text, pi)
|
||||
# return pi
|
||||
|
||||
|
||||
@dataclass()
|
||||
class Node:
|
||||
pass
|
||||
@@ -84,6 +103,9 @@ class BaseParser:
|
||||
self.enabled = enabled
|
||||
|
||||
self.error_sink = []
|
||||
self.context: ExecutionContext = None
|
||||
self.sheerka = None
|
||||
self.parser_input: ParserInput = None
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, self.__class__):
|
||||
@@ -99,6 +121,12 @@ class BaseParser:
|
||||
def parse(self, context, parser_input):
|
||||
pass
|
||||
|
||||
def add_error(self, error, next_token=True):
|
||||
self.error_sink.append(error)
|
||||
if next_token:
|
||||
self.parser_input.next_token()
|
||||
return error
|
||||
|
||||
@property
|
||||
def has_error(self):
|
||||
return len(self.error_sink) > 0
|
||||
|
||||
Reference in New Issue
Block a user