Commit 16a25786 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

parser.py, ebnf.py: Allow Parsers for resume-skipping (refactorings pending)

parent 3eefd06d
#!/usr/bin/env python
# A mini-DSL for a key value store
from DHParser import create_parser
# specify the grammar of your DSL in EBNF-notation
grammar = '''@ drop = whitespace, strings
key_store = ~ { entry }
entry = key "=" ~ value
key = /\w+/~ # Scannerless parsing: Use regular
value = /\"[^"\n]*\"/~ # expressions wherever you like'''
# generating a parser is almost as simple as compiling a regular expression
# parser = create_parser(grammar) # parser factory for thread-safety
parser = create_parser(grammar)
text = '''
title = "Odysee 2001"
director = "Stanley Kubrick"
'''
if __name__ == "__main__":
result = parser(text)
assert not result.errors, str(result.as_sxpr())
......@@ -22,7 +22,7 @@ cythonize_modules = [
'DHParser/ebnf.py',
]
with open('README.md', encoding='utf-8') as f:
with open('../../README.md', encoding='utf-8') as f:
read_me = f.read()
setuptools.setup(
......
......@@ -24,7 +24,7 @@ cythonize_modules = [
# 'DHParser/ebnf.py',
]
with open('README.md', encoding='utf-8') as f:
with open('../../README.md', encoding='utf-8') as f:
read_me = f.read()
setuptools.setup(
......
......@@ -38,8 +38,8 @@ from DHParser.log import log_dir, start_logging, is_logging, suspend_logging, re
class TestLoggingAndLoading:
def setup(self):
self.tmpname = 'tmp_' + concurrent_ident()
self.filename = os.path.join("test", self.tmpname, "test.py") if os.path.isdir('test') \
else os.path.join(self.tmpname, "test.py")
self.filename = os.path.join("test", self.tmpname, "key_value_example.py") if os.path.isdir('test') \
else os.path.join(self.tmpname, "key_value_example.py")
self.dirname = os.path.dirname(self.filename)
self.code1 = "x = 46\n"
self.code2 = "def f():\n return 46"
......
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