Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
25c1605d
Commit
25c1605d
authored
Mar 02, 2019
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- testing.create_test_templates(): don't print "file already exists message" any more
parent
f99743f4
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
222 additions
and
44 deletions
+222
-44
DHParser/ebnf.py
DHParser/ebnf.py
+1
-0
DHParser/parse.py
DHParser/parse.py
+2
-1
DHParser/testing.py
DHParser/testing.py
+2
-3
dhparser.py
dhparser.py
+1
-5
examples/ArithmeticExperimental/ArithmeticExperimental.ebnf
examples/ArithmeticExperimental/ArithmeticExperimental.ebnf
+16
-13
examples/ArithmeticExperimental/ArithmeticExperimentalCompiler.py
.../ArithmeticExperimental/ArithmeticExperimentalCompiler.py
+14
-9
examples/ArithmeticExperimental/grammar_tests/01_test_Tokens.ini
...s/ArithmeticExperimental/grammar_tests/01_test_Tokens.ini
+3
-1
examples/ArithmeticExperimental/grammar_tests/02_test_Numbers.ini
.../ArithmeticExperimental/grammar_tests/02_test_Numbers.ini
+66
-0
examples/ArithmeticExperimental/grammar_tests/03_test_Functions.ini
...rithmeticExperimental/grammar_tests/03_test_Functions.ini
+35
-0
examples/ArithmeticExperimental/grammar_tests/04_test_Elements.ini
...ArithmeticExperimental/grammar_tests/04_test_Elements.ini
+63
-0
examples/ArithmeticExperimental/grammar_tests/05_test_Factors.ini
.../ArithmeticExperimental/grammar_tests/05_test_Factors.ini
+17
-5
examples/ArithmeticExperimental/grammar_tests/06_test_Terms.ini
...es/ArithmeticExperimental/grammar_tests/06_test_Terms.ini
+0
-1
examples/ArithmeticExperimental/grammar_tests/07_test_Expressions.ini
...thmeticExperimental/grammar_tests/07_test_Expressions.ini
+0
-0
examples/ArithmeticExperimental/tst_ArithmeticExperimental_grammar.py
...thmeticExperimental/tst_ArithmeticExperimental_grammar.py
+2
-6
No files found.
DHParser/ebnf.py
View file @
25c1605d
...
...
@@ -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'
):
...
...
DHParser/parse.py
View file @
25c1605d
...
...
@@ -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
...
...
DHParser/testing.py
View file @
25c1605d
...
...
@@ -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
))
...
...
dhparser.py
View file @
25c1605d
...
...
@@ -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,
...
...
examples/ArithmeticExperimental/ArithmeticExperimental.ebnf
View file @
25c1605d
...
...
@@ -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 Value
s
#:
Function
s
#
#######################################################################
special = pi | e
pi = `pi` | `π`
e = `e`
function = sin | cos | tan | log
sin = 'sin(' §expression `)`
cos = 'cos(' §expression `)`
tan = 'tan(' §expression `)`
log = 'log(' §expression `)`
#######################################################################
#
#:
Function
s
#:
Number
s
#
#######################################################################
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]/
examples/ArithmeticExperimental/ArithmeticExperimentalCompiler.py
View file @
25c1605d
...
...
@@ -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__
)
...
...
examples/ArithmeticExperimental/grammar_tests/01_test_Tokens.ini
View file @
25c1605d
...
...
@@ -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
examples/ArithmeticExperimental/grammar_tests/02_test_Numbers.ini
0 → 100644
View file @
25c1605d
[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
examples/ArithmeticExperimental/grammar_tests/03_test_Functions.ini
0 → 100644
View file @
25c1605d
[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]
examples/ArithmeticExperimental/grammar_tests/04_test_Elements.ini
0 → 100644
View file @
25c1605d
[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]
examples/ArithmeticExperimental/grammar_tests/0
2
_test_Factors.ini
→
examples/ArithmeticExperimental/grammar_tests/0
5
_test_Factors.ini
View file @
25c1605d
...
...
@@ -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]
examples/ArithmeticExperimental/grammar_tests/0
3
_test_Terms.ini
→
examples/ArithmeticExperimental/grammar_tests/0
6
_test_Terms.ini
View file @
25c1605d
[match:term]
M1:
"2
*
4"
M2:
"2
/
4"
...
...
examples/ArithmeticExperimental/grammar_tests/0
4
_test_Expressions.ini
→
examples/ArithmeticExperimental/grammar_tests/0
7
_test_Expressions.ini
View file @
25c1605d
File moved
examples/ArithmeticExperimental/tst_ArithmeticExperimental_grammar.py
View file @
25c1605d
...
...
@@ -6,7 +6,7 @@
import
os
import
sys
LOGGING
=
Fals
e
LOGGING
=
Tru
e
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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment