Move oracle table generating facilities to grammar.py
This commit is contained in:
parent
f813d91736
commit
5e84e50aa2
|
@ -1,15 +1,8 @@
|
|||
"""
|
||||
Tools for building an oracle table
|
||||
|
||||
If this module is run directly in python, it will spit out valid python which produces an
|
||||
oracle table for the grammar defined in `grammar.py`. It's recommended that this be done
|
||||
using `build_oracle.sh` instead, however, which will build a whole python module
|
||||
containing the oracle table, complete with imports.
|
||||
|
||||
This module can also be used on its own to generate an oracle table on the fly.
|
||||
|
||||
Note that, when run directly, this module will refuse to build an oracle table if ANY of
|
||||
the tests defined within the module fail.
|
||||
See `grammar` and `build_oracle.sh` for scripts which actually produce python code. This
|
||||
module only produces an oracle table in python, without outputting it.
|
||||
"""
|
||||
from emis_funky_funktions import *
|
||||
|
||||
|
@ -331,9 +324,4 @@ def print_oracle_table_enum(
|
|||
if __name__ == '__main__':
|
||||
import doctest
|
||||
from grammar import GRAMMAR, Tok, Variable
|
||||
failure_count, test_count = doctest.testmod()
|
||||
if failure_count:
|
||||
print('\n\nRefusing to build oracle table due to test failures')
|
||||
exit(1)
|
||||
else:
|
||||
print(print_oracle_table_enum(oracle_table(flip(cur2(isinstance))(Tok), GRAMMAR))) #type: ignore
|
||||
doctest.testmod()
|
|
@ -6,7 +6,7 @@ from grammar import Tok, Variable
|
|||
oracle_table = (
|
||||
EOF
|
||||
|
||||
if python build_oracle.py >> oracle_table.py; then
|
||||
if python grammar.py >> oracle_table.py; then
|
||||
echo ")" >> oracle_table.py
|
||||
echo "Built oracle_table.py"
|
||||
else
|
||||
|
|
15
grammar.py
15
grammar.py
|
@ -1,3 +1,11 @@
|
|||
"""
|
||||
A grammar for parsing CNF files
|
||||
|
||||
If this module is run directly in python, it will spit out valid python which produces an
|
||||
oracle table for the grammar it defines. It's recommended that this be done using
|
||||
`build_oracle.sh` instead, however, which will build a whole python module containing the
|
||||
oracle table, complete with imports.
|
||||
"""
|
||||
from enum import auto, IntEnum
|
||||
from re import compile, Pattern
|
||||
|
||||
|
@ -136,4 +144,9 @@ Func? := OpenP <Term> <CSTerms> CloseP
|
|||
|
||||
CSTerms := Comma <Term> <CSTerms>
|
||||
:= ε
|
||||
"""
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
from emis_funky_funktions import cur2, flip
|
||||
from build_oracle import print_oracle_table_enum, oracle_table
|
||||
print(print_oracle_table_enum(oracle_table(flip(cur2(isinstance))(Tok), GRAMMAR))) #type: ignore
|
Loading…
Reference in a new issue