Fixed #49 : working

This commit is contained in:
2021-03-18 11:49:48 +01:00
parent 27bc6c4ba1
commit 36515aebb7
5 changed files with 153 additions and 63 deletions
+14 -2
View File
@@ -4,7 +4,7 @@ from typing import List, Tuple, Union
from core.builtin_concepts_ids import BuiltinConcepts
from core.sheerka.services.SheerkaExecute import ParserInput
from core.tokenizer import Token, TokenKind, Tokenizer, LexerError
from core.utils import tokens_are_matching
from core.utils import tokens_are_matching, get_text_from_tokens
from parsers.BaseNodeParser import UnrecognizedTokensNode
from parsers.BaseParser import Node, ParsingError, BaseParser, ErrorSink, UnexpectedTokenParsingError
@@ -33,7 +33,7 @@ class ParenthesisMismatchError(ParsingError):
token: Token
@dataclass
@dataclass(init=False)
class ExprNode(Node):
"""
Base ExprNode
@@ -43,6 +43,12 @@ class ExprNode(Node):
end: int # index of the last token
tokens: List[Token]
def __init__(self, start: int, end: int, tokens: List[Token]):
self.start = start
self.end = end
self.tokens = tokens
self.source = None
def eval(self, obj):
return True
@@ -61,6 +67,12 @@ class ExprNode(Node):
def __hash__(self):
return hash((self.start, self.end))
def get_source(self):
if self.source is None:
self.source = get_text_from_tokens(self.tokens)
return self.source
class NameExprNode(ExprNode):
def __init__(self, start, end, tokens):