Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
badw-it
DHParser
Commits
9f2e21da
Commit
9f2e21da
authored
Mar 08, 2021
by
Eckhart Arnold
Browse files
parser.py - sequeeze tight added
parent
c6d57343
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/parse.py
View file @
9f2e21da
...
...
@@ -618,10 +618,11 @@ class Parser:
assert
proxy
.
__self__
==
self
self
.
_parse_proxy
=
cast
(
ParseFunc
,
proxy
)
def
with_pname
(
self
,
pname
:
str
)
->
Parser
:
def
with_pname
(
self
,
pname
:
str
)
->
'
Parser
'
:
"""Sets the parser name to `pname` and returns `self`."""
self
.
pname
=
pname
self
.
tag_name
=
pname
or
self
.
ptype
self
.
disposable
=
not
self
.
pname
return
self
@
property
...
...
@@ -2170,6 +2171,33 @@ def OutputOptimization(root_parser: Parser, level: int = CombinedParser.FLATTEN)
>>> tree = grammar('AB')
>>> print(tree.as_sxpr())
(root "AB")
>>> root = Text('A') + Text('B') + (Text('C').with_pname('important') | Text('D'))
>>> grammar = Grammar(OutputOptimization(root, CombinedParser.NO_TREE_REDUCTION))
>>> tree = grammar('ABC')
>>> print(tree.as_sxpr())
(root (:Text "A") (:Text "B") (:Alternative (important "C")))
>>> grammar = Grammar(OutputOptimization(root, CombinedParser.FLATTEN)) # default
>>> tree = grammar('ABC')
>>> print(tree.as_sxpr())
(root (:Text "A") (:Text "B") (important "C"))
>>> tree = grammar('ABD')
>>> print(tree.as_sxpr())
(root (:Text "A") (:Text "B") (:Text "D"))
>>> grammar = Grammar(OutputOptimization(root, CombinedParser.SQUEEZE))
>>> tree = grammar('ABC')
>>> print(tree.as_sxpr())
(root (:Text "A") (:Text "B") (important "C"))
>>> tree = grammar('ABD')
>>> print(tree.as_sxpr())
(root "ABD")
>>> grammar = Grammar(OutputOptimization(root, CombinedParser.SQUEEZE_TIGHT))
>>> tree = grammar('ABC')
>>> print(tree.as_sxpr())
(root (:Text "AB") (important "C"))
>>> tree = grammar('ABD')
>>> print(tree.as_sxpr())
(root "ABD")
"""
def
apply_func
(
context
:
List
[
Parser
])
->
None
:
nonlocal
level
...
...
Write
Preview
Supports
Markdown
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