Commit 25c1605d authored by eckhart's avatar eckhart

- testing.create_test_templates(): don't print "file already exists message" any more

parent f99743f4
......@@ -1261,6 +1261,7 @@ class EBNFCompiler(Compiler):
return 'DropToken('
return 'Token('
def WSPC_PARSER(self):
if DROP_WSPC in self.directives.drop and (self.context[-2].tag_name != "definition"
or self.context[-1].tag_name == 'literal'):
......
......@@ -285,7 +285,8 @@ class Parser:
self.recursion_counter[location] += 1
if grammar.history_tracking__:
grammar.call_stack__.append(self.repr if self.tag_name in (':RegExp', ':Token')
grammar.call_stack__.append(self.repr if self.tag_name in
(':RegExp', ':Token', ':DropToken')
else self.tag_name)
grammar.moving_forward__ = True
......
......@@ -664,9 +664,8 @@ def create_test_templates(symbols_or_ebnf: Union[str, SymbolsDictType],
keys = reversed(list(symbols.keys()))
for i, k in enumerate(keys):
filename = '{num:0>2}_test_{section}'.format(num=i+1, section=k) + fmt
if os.path.exists(filename):
print('File "{name}" not created, because it already exists!')
else:
if not os.path.exists(filename):
print('Creating test file template "{name}".'.format(name=filename))
with open(filename, 'w', encoding='utf-8') as f:
for sym in symbols[k]:
f.write('\n[match:{sym}]\n\n'.format(sym=sym))
......
......@@ -139,11 +139,7 @@ except ModuleNotFoundError:
def recompile_grammar(grammar_src, force):
grammar_tests_dir = os.path.join(scriptpath, 'grammar_tests')
if not os.path.exists(grammar_tests_dir) \
or not any(os.path.isfile(os.path.join(grammar_tests_dir, entry))
for entry in os.listdir(grammar_tests_dir)):
print('No grammar-tests found, generating test templates.')
testing.create_test_templates(grammar_src, grammar_tests_dir)
testing.create_test_templates(grammar_src, grammar_tests_dir)
with DHParser.log.logging(LOGGING):
# recompiles Grammar only if it has changed
if not dsl.recompile_grammar(grammar_src, force=force,
......
......@@ -54,8 +54,8 @@ sign = PLUS | MINUS
#######################################################################
element = pow | value
pow = value `^` pow
value = NUMBER | tail_value
pow = value `^` [sign] element
value = number | tail_value
tail_elem = tail_pow | tail_value
tail_pow = tail_value `^` pow
......@@ -65,26 +65,29 @@ group = `(` §expression `)`
#######################################################################
#
#: Special Values
#: Functions
#
#######################################################################
special = pi | e
pi = `pi` | `π`
e = `e`
function = sin | cos | tan | log
sin = 'sin(' §expression `)`
cos = 'cos(' §expression `)`
tan = 'tan(' §expression `)`
log = 'log(' §expression `)`
#######################################################################
#
#: Functions
#: Numbers
#
#######################################################################
function = sin | cos | tan | log
sin = 'sin(' §expression `)`
cos = 'cos(' §expression `)`
tan = 'tan(' §expression `)`
log = 'log(' §expression `)`
number = special | imaginary | real
special = pi | e
pi = `pi` | `π`
e = `e`
imaginary = [NUMBER] `i`
real = NUMBER !`i`
#######################################################################
......@@ -95,5 +98,5 @@ log = 'log(' §expression `)`
PLUS = /\+/
MINUS = /-/
NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?i?/
NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/
VARIABLE = /[j-z]/
......@@ -58,11 +58,13 @@ def get_preprocessor() -> PreprocessorFunc:
class ArithmeticExperimentalGrammar(Grammar):
r"""Parser for an ArithmeticExperimental source file.
"""
element = Forward()
expression = Forward()
pow = Forward()
sign = Forward()
tail = Forward()
term = Forward()
source_hash__ = "eee86a4b8fdffdf468581501debf2461"
source_hash__ = "728734b427a80706ded8fe35fc451fdf"
static_analysis_pending__ = [True]
parser_initialization__ = ["upon instantiation"]
resume_rules__ = {}
......@@ -72,25 +74,28 @@ class ArithmeticExperimentalGrammar(Grammar):
dwsp__ = DropWhitespace(WSP_RE__)
wsp__ = Whitespace(WSP_RE__)
VARIABLE = RegExp('[j-z]')
NUMBER = RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?i?')
NUMBER = RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?')
MINUS = RegExp('-')
PLUS = RegExp('\\+')
real = Series(NUMBER, NegativeLookahead(DropToken("i")))
imaginary = Series(Option(NUMBER), DropToken("i"))
e = Token("e")
pi = Alternative(DropToken("pi"), DropToken("π"))
special = Alternative(pi, e)
number = Alternative(special, imaginary, real)
log = Series(Series(DropToken('log('), dwsp__), expression, DropToken(")"), mandatory=1)
tan = Series(Series(DropToken('tan('), dwsp__), expression, DropToken(")"), mandatory=1)
cos = Series(Series(DropToken('cos('), dwsp__), expression, DropToken(")"), mandatory=1)
sin = Series(Series(DropToken('sin('), dwsp__), expression, DropToken(")"), mandatory=1)
function = Alternative(sin, cos, tan, log)
e = Token("e")
pi = Alternative(DropToken("pi"), DropToken("π"))
special = Alternative(pi, e)
group = Series(DropToken("("), expression, DropToken(")"), mandatory=1)
tail_value = Alternative(special, function, VARIABLE, group)
tail_pow = Series(tail_value, DropToken("^"), pow)
tail_elem = Alternative(tail_pow, tail_value)
value = Alternative(NUMBER, tail_value)
pow.set(Series(value, DropToken("^"), pow))
element = Alternative(pow, value)
sign = Alternative(PLUS, MINUS)
value = Alternative(number, tail_value)
pow.set(Series(value, DropToken("^"), Option(sign), element))
element.set(Alternative(pow, value))
sign.set(Alternative(PLUS, MINUS))
seq = Series(tail_elem, tail)
tail.set(Alternative(seq, tail_elem))
factor = Series(Option(sign), Option(element), tail, dwsp__)
......
......@@ -20,7 +20,8 @@ F5: -22
[match:VARIABLE]
M1: j
M2: Z
M2: x
M3: z
[fail:VARIABLE]
F1: ä
......@@ -29,4 +30,5 @@ F3: a
F4: e
F5: i
F6: π
F7: X
[match:number]
M1: 2
M2: 2.5
M3: 0.3
M4: i
M5: 2i
M6: π
M7: pi
M8: e
[fail:number]
F1: j
F2: x
F3: X
F4: PI
[match:special]
M1: π
M2: pi
M3: e
[fail:special]
F1: 2
F2: 3.1415
F3: 2.7818
F4: i
F5: 2i
[match:pi]
M1: π
M2: pi
[match:e]
M1: e
[ast:e]
[match:imaginary]
M1: i
M2: 2i
M3: 2.5i
[fail:imaginary]
F1: j
F2: 2j
F3: 3+2j
[match:real]
M1: 0
M2: 1
M3: 2.7818
M4: 3.1415
[fail:real]
F1: i
F2: 2i
F3: 2.5i
F4: 2,5
[match:function]
[ast:function]
[fail:function]
[match:sin]
[ast:sin]
[fail:sin]
[match:cos]
[ast:cos]
[fail:cos]
[match:tan]
[ast:tan]
[fail:tan]
[match:log]
[ast:log]
[fail:log]
[match:element]
M1: 2
M2: 2^3
[ast:element]
[fail:element]
[match:pow]
M1: 2^4
M2: 3^4
M3: 2^-x
M4: 2^3^4
[ast:pow]
[fail:pow]
[match:value]
M1: 2
M2: 2.1
M3: 3i
M4: pi
M5: e
M6: x
[ast:value]
[fail:value]
[match:tail_elem]
[ast:tail_elem]
[fail:tail_elem]
[match:tail_pow]
[ast:tail_pow]
[fail:tail_pow]
[match:tail_value]
[ast:tail_value]
[fail:tail_value]
[match:group]
[ast:group]
[fail:group]
......@@ -10,11 +10,23 @@ M6: "-(a * b)"
F1: "x4"
F2: "- 2"
[match:group]
M1: "(2 * 4)"
M2: "(2 + 4)"
[match:tail]
[ast:group]
[ast:tail]
[fail:group]
[fail:tail]
[match:seq]
[ast:seq]
[fail:seq]
[match:sign]
[ast:sign]
[fail:sign]
......@@ -6,7 +6,7 @@
import os
import sys
LOGGING = False
LOGGING = True
sys.path.extend(['../../', '../', './'])
......@@ -29,11 +29,7 @@ CONFIG_PRESET['test_parallelization'] = True
def recompile_grammar(grammar_src, force):
grammar_tests_dir = os.path.join(scriptpath, 'grammar_tests')
if not os.path.exists(grammar_tests_dir) \
or not any(os.path.isfile(os.path.join(grammar_tests_dir, entry))
for entry in os.listdir(grammar_tests_dir)):
print('No grammar-tests found, generating test templates.')
create_test_templates(grammar_src, grammar_tests_dir)
create_test_templates(grammar_src, grammar_tests_dir)
with DHParser.log.logging(LOGGING):
# recompiles Grammar only if it has changed
name = os.path.splitext(os.path.basename(grammar_src))[0]
......
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