Commit 632a5b76 authored by di68kap's avatar di68kap
Browse files

- parser.py: faster Regex: m.group(0) instead of text[:end]

parent bff61c50
...@@ -1150,7 +1150,7 @@ class RegExp(Parser): ...@@ -1150,7 +1150,7 @@ class RegExp(Parser):
match = text.match(self.regexp) match = text.match(self.regexp)
if match: if match:
end = text.index(match.end()) end = text.index(match.end())
return Node(self, text[:end], True), text[end:] return Node(self, match.group(0), True), text[end:]
return None, text return None, text
def __repr__(self): def __repr__(self):
......
...@@ -52,6 +52,8 @@ def fail_on_error(src, result): ...@@ -52,6 +52,8 @@ def fail_on_error(src, result):
def tst_func(): def tst_func():
with toolkit.logging(False): with toolkit.logging(False):
if not os.path.exists('REPORT'):
os.mkdir('REPORT')
files = os.listdir('testdata') files = os.listdir('testdata')
files.sort() files.sort()
for file in files: for file in files:
...@@ -60,10 +62,10 @@ def tst_func(): ...@@ -60,10 +62,10 @@ def tst_func():
doc = f.read() doc = f.read()
print('\n\nParsing document: "%s"\n' % file) print('\n\nParsing document: "%s"\n' % file)
result = parser(doc) result = parser(doc)
with open('results/' + file[:-4]+'.cst', 'w', encoding='utf-8') as f: with open('REPORT/' + file[:-4]+'.cst', 'w', encoding='utf-8') as f:
f.write(result.as_sxpr(compact=False)) f.write(result.as_sxpr(compact=False))
transformer(result) transformer(result)
with open('results/' + file[:-4]+'.ast', 'w', encoding='utf-8') as f: with open('REPORT/' + file[:-4]+'.ast', 'w', encoding='utf-8') as f:
f.write(result.as_sxpr(compact=False)) f.write(result.as_sxpr(compact=False))
parser.log_parsing_history__() parser.log_parsing_history__()
fail_on_error(doc, result) fail_on_error(doc, result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment