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
5c31e8d8
Commit
5c31e8d8
authored
Jun 09, 2020
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DHParser/templaytes/DSLServer.pyi: command line arguments now parsed with the argparse-module
parent
02720456
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
23 deletions
+56
-23
DHParser/parse.py
DHParser/parse.py
+8
-5
tests/test_parse.py
tests/test_parse.py
+48
-18
No files found.
DHParser/parse.py
View file @
5c31e8d8
...
...
@@ -436,9 +436,9 @@ class Parser:
location
=
grammar
.
document_length__
-
text
.
_len
# faster then len(text)?
try
:
# rollback variable changing operation if parser backtracks
#
to a position befo
re the variable changing operation occurred
if
grammar
.
last_rb__loc__
>
location
:
# rollback variable changing operation if parser backtracks
to a position
#
before or at the location whe
re the variable changing operation occurred
if
grammar
.
last_rb__loc__
>
=
location
:
grammar
.
rollback_to__
(
location
)
# if location has already been visited by the current parser, return saved result
...
...
@@ -3080,7 +3080,10 @@ class Pop(Retrieve):
node
,
txt
=
self
.
retrieve_and_match
(
text
)
if
node
is
not
None
and
not
id
(
node
)
in
self
.
grammar
.
tree__
.
error_nodes
:
self
.
values
.
append
(
self
.
grammar
.
variables__
[
self
.
symbol_pname
].
pop
())
location
=
self
.
grammar
.
document_length__
-
text
.
__len__
()
location
=
self
.
grammar
.
document_length__
-
text
.
__len__
()
-
1
# if node is not EMPTY_NODE and len(node) == 0:
# location = self.grammar.document_length__ - txt.__len__() - 1
# print('PUSH:', self.symbol_pname, location, self.values[-1])
self
.
grammar
.
push_rollback__
(
location
,
self
.
_rollback
)
# lambda: stack.append(value))
return
node
,
txt
...
...
@@ -3210,7 +3213,7 @@ class Forward(UnaryParser):
location
=
grammar
.
document_length__
-
text
.
_len
# rollback variable changing operation if parser backtracks
# to a position before the variable changing operation occurred
if
grammar
.
last_rb__loc__
>
location
:
if
grammar
.
last_rb__loc__
>
=
location
:
grammar
.
rollback_to__
(
location
)
# if location has already been visited by the current parser, return saved result
...
...
tests/test_parse.py
View file @
5c31e8d8
...
...
@@ -113,9 +113,9 @@ class TestParserClass:
class
TestInfiLoopsAndRecursion
:
def
setup
(
self
):
pass
set_config_value
(
'history_tracking'
,
True
)
#
set_config_value('history_tracking', True)
# set_config_value('resume_notices', True)
start_logging
(
'LOGS'
)
#
start_logging('LOGS')
def
test_very_simple
(
self
):
minilang
=
"""
...
...
@@ -204,7 +204,7 @@ class TestInfiLoopsAndRecursion:
# BEWARE: EXPERIMENTAL TEST can be long running
def
test_indirect_left_recursion2
(
self
):
arithmetic_syntax
=
"""@literalws = right
arithmetic_syntax
=
r
"""@literalws = right
expression = addition | subtraction # | term
addition = (expression | term) "+" (expression | term)
subtraction = (expression | term) "-" (expression | term)
...
...
@@ -226,7 +226,7 @@ class TestInfiLoopsAndRecursion:
log_parsing_history
(
arithmetic
,
"test_LeftRecursion_indirect2"
)
def
test_indirect_left_recursion3
(
self
):
arithmetic_syntax
=
"""@literalws = right
arithmetic_syntax
=
r
"""@literalws = right
expression = addition | subtraction | term
addition = (expression | term) "+" (expression | term)
subtraction = (expression | term) "-" (expression | term)
...
...
@@ -718,7 +718,7 @@ class TestPopRetrieve:
mini_language
=
r"""
document = { text | codeblock }
codeblock = delimiter { text | (!:delimiter delimiter_sign) } ::delimiter
delimiter = delimiter_sign # never use delimiter between capture and pop except for retrival!
delimiter = delimiter_sign # never use delimiter between capture and pop except for retri
e
val!
delimiter_sign = /`+/
text = /[^`]+/
"""
...
...
@@ -805,21 +805,31 @@ class TestPopRetrieve:
assert
not
syntax_tree
.
error_flag
,
str
(
syntax_tree
.
errors_sorted
)
def
test_optional_match
(
self
):
test1
=
'<info>Hey, you</info>'
st
=
self
.
minilang_parser4
(
test1
)
assert
not
st
.
error_flag
,
str
(
st
.
errors_sorted
)
test12
=
'<info>Hey, <emph>you</emph></info>'
st
=
self
.
minilang_parser4
(
test1
)
assert
not
st
.
error_flag
# from DHParser.dsl import compileEBNF
# src = compileEBNF(self.mini_lang4)
# print(src)
# return
# test1 = '<info>Hey, you</info>'
# st = self.minilang_parser4(test1)
# assert not st.error_flag, str(st.errors_sorted)
# test12 = '<info>Hey, <emph>you</emph></info>'
# st = self.minilang_parser4(test1)
# assert not st.error_flag
test2
=
'<info>Hey, you</>'
set_config_value
(
'history_tracking'
,
True
)
set_tracer
(
self
.
minilang_parser4
,
trace_history
)
start_logging
(
'LOGS'
)
st
=
self
.
minilang_parser4
(
test2
)
log_parsing_history
(
self
.
minilang_parser4
,
"optional_match"
)
print
(
st
.
as_sxpr
())
assert
not
st
.
error_flag
test3
=
'<info>Hey, <emph>you</></>'
st
=
self
.
minilang_parser4
(
test3
)
assert
not
st
.
error_flag
test4
=
'<info>Hey, <emph>you</></info>'
st
=
self
.
minilang_parser4
(
test4
)
assert
not
st
.
error_flag
#
test3 = '<info>Hey, <emph>you</></>'
#
st = self.minilang_parser4(test3)
#
assert not st.error_flag
#
test4 = '<info>Hey, <emph>you</></info>'
#
st = self.minilang_parser4(test4)
#
assert not st.error_flag
def
test_rollback_behaviour_of_optional_match
(
self
):
test1
=
'<info>Hey, you</info*>'
...
...
@@ -831,7 +841,7 @@ class TestPopRetrieve:
assert
not
self
.
minilang_parser4
.
variables__
[
'name'
]
assert
st
.
error_flag
def
test_cache_neutrality
(
self
):
def
test_cache_neutrality
_1
(
self
):
"""Test that packrat-caching does not interfere with the variable-
changing parsers: Capture and Retrieve."""
lang
=
r"""@literalws = right
...
...
@@ -848,6 +858,25 @@ class TestPopRetrieve:
st
=
gr
(
case
)
assert
not
st
.
error_flag
,
str
(
st
.
errors_sorted
)
def
test_cache_neutrality_2
(
self
):
lang
=
r'''document = variantA | variantB
variantA = delimiter `X` ::delimiter `!`
variantB = `A` delimiter ::delimiter `!`
delimiter = `A` | `X`
'''
gr
=
grammar_provider
(
lang
)()
case
=
'AXA!'
st
=
gr
(
case
)
assert
not
st
.
errors
case
=
'AXX!'
set_config_value
(
'history_tracking'
,
True
)
start_logging
(
'LOGS'
)
set_tracer
(
gr
,
trace_history
)
st
=
gr
(
case
)
log_parsing_history
(
gr
,
'test_cache_neutrality_2'
)
print
(
st
.
as_sxpr
())
def
test_single_line
(
self
):
teststr
=
"Anfang ```code block `` <- keine Ende-Zeichen ! ``` Ende"
syntax_tree
=
self
.
minilang_parser
(
teststr
)
...
...
@@ -1502,3 +1531,4 @@ class TestStaticAnalysis:
if
__name__
==
"__main__"
:
from
DHParser.testing
import
runner
runner
(
""
,
globals
())
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