Commit a21decfb authored by di68kap's avatar di68kap

- check_examples.py - script added: just quickly check if all(!) examples are still working

parent 447927f6
......@@ -59,7 +59,7 @@ class ArithmeticGrammar(Grammar):
digit = Forward()
expression = Forward()
variable = Forward()
source_hash__ = "c4e6e090ef9673b972ba18ef39fe7c8e"
source_hash__ = "120070baa84f5a2bd1bbb900627078fc"
parser_initialization__ = "upon instantiation"
resume_rules__ = {}
COMMENT__ = r''
......@@ -76,10 +76,13 @@ class ArithmeticGrammar(Grammar):
root__ = expression
def get_grammar() -> ArithmeticGrammar:
global GLOBALS
try:
grammar = GLOBALS.Arithmetic_1_grammar_singleton
except AttributeError:
GLOBALS.Arithmetic_1_grammar_singleton = ArithmeticGrammar()
if hasattr(get_grammar, 'python_src__'):
GLOBALS.Arithmetic_1_grammar_singleton.python_src__ = get_grammar.python_src__
grammar = GLOBALS.Arithmetic_1_grammar_singleton
return grammar
......
......@@ -57,7 +57,7 @@ class BibTeXGrammar(Grammar):
r"""Parser for a BibTeX source file.
"""
text = Forward()
source_hash__ = "569bee4a051ea4d9f625ad9bbd46a7a2"
source_hash__ = "e402951b290cb0fce63ba0cbca3f23e9"
parser_initialization__ = "upon instantiation"
resume_rules__ = {}
COMMENT__ = r'(?i)%.*(?:\n|$)'
......@@ -83,10 +83,13 @@ class BibTeXGrammar(Grammar):
root__ = bibliography
def get_grammar() -> BibTeXGrammar:
global GLOBALS
try:
grammar = GLOBALS.BibTeX_1_grammar_singleton
except AttributeError:
GLOBALS.BibTeX_1_grammar_singleton = BibTeXGrammar()
if hasattr(get_grammar, 'python_src__'):
GLOBALS.BibTeX_1_grammar_singleton.python_src__ = get_grammar.python_src__
grammar = GLOBALS.BibTeX_1_grammar_singleton
return grammar
......
......@@ -57,7 +57,7 @@ class EBNFGrammar(Grammar):
r"""Parser for an EBNF source file.
"""
expression = Forward()
source_hash__ = "82a7c668f86b83f86515078e6c9093ed"
source_hash__ = "5e9e65a057bec7da29989dba47f40394"
parser_initialization__ = "upon instantiation"
resume_rules__ = {}
COMMENT__ = r'#.*(?:\n|$)'
......@@ -86,10 +86,13 @@ class EBNFGrammar(Grammar):
root__ = syntax
def get_grammar() -> EBNFGrammar:
global GLOBALS
try:
grammar = GLOBALS.EBNF_1_grammar_singleton
except AttributeError:
GLOBALS.EBNF_1_grammar_singleton = EBNFGrammar()
if hasattr(get_grammar, 'python_src__'):
GLOBALS.EBNF_1_grammar_singleton.python_src__ = get_grammar.python_src__
grammar = GLOBALS.EBNF_1_grammar_singleton
return grammar
......
......@@ -153,10 +153,13 @@ class LaTeXGrammar(Grammar):
root__ = latexdoc
def get_grammar() -> LaTeXGrammar:
global GLOBALS
try:
grammar = GLOBALS.LaTeX_1_grammar_singleton
except AttributeError:
GLOBALS.LaTeX_1_grammar_singleton = LaTeXGrammar()
if hasattr(get_grammar, 'python_src__'):
GLOBALS.LaTeX_1_grammar_singleton.python_src__ = get_grammar.python_src__
grammar = GLOBALS.LaTeX_1_grammar_singleton
return grammar
......
This diff is collapsed.
......@@ -46,8 +46,7 @@ if __name__ == '__main__':
if arg.endswith('.ebnf'):
recompile_grammar(arg, force=True)
else:
recompile_grammar(os.path.join(scriptpath, 'XML.ebnf'),
force=False)
recompile_grammar(os.path.join(scriptpath, 'XML.ebnf'), force=False)
sys.path.append('.')
from XMLCompiler import get_grammar, get_transformer
error_report = run_grammar_tests(glob_pattern=arg)
......
......@@ -34,6 +34,16 @@ Yes = 'yes'
No = 'no'
#######################################################################
#
# Document Type Definition stub
#
#######################################################################
doctypedecl = '<!DOCTYPE' ~ Name [~ ExternalID] ~ ['[' intSubset ']' ~] '>'
ExternalID = 'SYSTEM' §S SystemLiteral
intSubset = /(?:(?!\][^\]])[^<&])+/
#######################################################################
#
# Logical Structures
......
This diff is collapsed.
[match:WORD]
M1: word
M2: one_word_with_underscores
[fail:WORD]
F1: two words
[match:document]
M1: """This is a sequence of words
extending over several lines"""
M2: """ This sequence contains leading whitespace"""
[fail:document]
F1: """This test should fail, because neither
comma nor full have been defined anywhere."""
[match:document]
M1*: """
<?xml version="1.0" encoding="UTF-8"?>
<note date="2018-06-14">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<priority level="high" />
<remark></remark>
</note>
"""
#!/usr/bin/python
"""Goes through all examples and runs any tst_*.py or recompile_grammar.py
scripts"""
import fnmatch
import os
import platform
if __name__ == "__main__":
scriptdir = os.path.dirname(os.path.realpath(__file__))
rootdir = scriptdir[:scriptdir.find('DHParser') + 8]
if platform.system() != "Windows":
interpreter = 'python3 '
else:
interpreter = 'python.exe '
example_dirs = os.listdir(os.path.join(rootdir, 'examples'))
run = 0
failures = 0
for example in example_dirs:
example_path = os.path.join(rootdir, 'examples', example)
if os.path.isdir(example_path):
save = os.getcwd()
os.chdir(example_path)
for name in os.listdir(example_path):
if os.path.isfile(name) \
and (name == "recompile_grammar.py" or fnmatch.fnmatch(name, 'tst_*.py')):
print(os.path.join(example_path, name))
ret = os.system(interpreter + name)
run += 1
if ret > 0:
failures += 1
os.chdir(save)
print()
print("{} tests run, {} tests failed".format(run, failures))
......@@ -7,7 +7,6 @@ import multiprocessing
import os
import platform
import time
import sys
def run_tests(command):
testtype = 'DOCTEST' if command.find('doctest') >= 0 else 'UNITTEST'
......
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