feat: MVP проекта закончено
This commit is contained in:
@ -38,12 +38,31 @@ class RulesParser:
|
||||
raise ValueError(f"Can't recognize transform symbol. "
|
||||
f"\"{self.TRANSFORM}\" or \"{self.B_TRANSFORM}\""
|
||||
f" expected, but \"{arrow}\" encountered")
|
||||
|
||||
#optimising empty symbol
|
||||
return Rule(
|
||||
operand=tokens[0],
|
||||
target=tokens[2],
|
||||
operand=self._optimise_empty(tokens[0]),
|
||||
target=self._optimise_empty(tokens[2]),
|
||||
is_blocking=is_blocking
|
||||
)
|
||||
|
||||
def _optimise_empty(self, string: str) -> str:
|
||||
"""
|
||||
Empty symbol has meaning only while it's the only
|
||||
symbol in the string (I hope i'm not wrong right now),
|
||||
so all empty symbols can be optimised
|
||||
|
||||
Returns sting without EMPTY symbols if deleting them
|
||||
is semantically possible, returns unchanges string if
|
||||
nothing can be optimised
|
||||
|
||||
NOTE: right now contains naive implementation
|
||||
"""
|
||||
string = re.sub(self.EMPTY+'+', EMPTY_SYMBOL, string)
|
||||
if re.fullmatch(self.EMPTY, string):
|
||||
return string
|
||||
return re.sub(self.EMPTY, '', string)
|
||||
|
||||
def _get_lines(self, src: str) -> list[str]:
|
||||
"""
|
||||
Get cleaned lines only with rules to parse
|
||||
@ -65,5 +84,4 @@ class RulesParser:
|
||||
Strips whitespaces at the end of lines
|
||||
"""
|
||||
result = re.sub(r' +$', '', src, flags=re.M)
|
||||
# result = re.sub(r"\n+", r'\n', result)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user