feat: Разметил токены парсера
This commit is contained in:
26
src/rulesparser.py
Normal file
26
src/rulesparser.py
Normal file
@ -0,0 +1,26 @@
|
||||
from collections import OrderedDict
|
||||
import re
|
||||
|
||||
class RulesParser:
|
||||
TRANSFORM = r'->'
|
||||
B_TRANSFORM = r'->\|'
|
||||
NEWLINE = '\n'
|
||||
IGNORE = r'\s'
|
||||
COMMENTS = r'//.+$'
|
||||
EMPTY = r'\$'
|
||||
|
||||
def parse(self, file: str) -> OrderedDict[str, str]:
|
||||
"""
|
||||
Parsing file according to syntax, specified
|
||||
in class variables. Hardcoded for now (and forever)
|
||||
"""
|
||||
with open(file, 'r') as f:
|
||||
text = f.read()
|
||||
|
||||
def _remove_comments(self, src: str) -> str:
|
||||
"""
|
||||
removes comments from end of lines and returns
|
||||
cleaned text
|
||||
"""
|
||||
return re.sub(self.COMMENTS, "", src)
|
||||
|
||||
Reference in New Issue
Block a user