Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
f944249f
Commit
f944249f
authored
Jul 05, 2017
by
Eckhart Arnold
Browse files
- syntaxtree.py, parser.py: __str__ methods adjusted for history recording
parent
1b046e5e
Changes
5
Hide whitespace changes
Inline
Side-by-side
DHParser/parsers.py
View file @
f944249f
...
...
@@ -150,6 +150,8 @@ class HistoryRecord:
@
property
def
stack
(
self
)
->
str
:
def
ptos
(
p
):
return
return
"->"
.
join
(
str
(
parser
)
for
parser
in
self
.
call_stack
)
@
property
...
...
@@ -627,6 +629,9 @@ class RegExp(Parser):
def
__repr__
(
self
):
return
'/%s/'
%
self
.
regexp
.
pattern
def
__str__
(
self
):
return
repr
(
self
)
class
Whitespace
(
RegExp
):
assert
WHITESPACE_PTYPE
==
":Whitespace"
...
...
@@ -692,11 +697,8 @@ class RE(Parser):
wR
=
'~'
if
self
.
wR
else
''
return
wL
+
'/%s/'
%
self
.
main
.
regexp
.
pattern
+
wR
# def __str__(self):
# if self.ptype == TOKEN_PTYPE:
# return 'Token "%s"' % self.main.regexp.pattern.replace('\\', '')
# return self.name or ('RE ' + ('~' if self.wL else '')
# + '/%s/' % self.main.regexp.pattern + ('~' if self.wR else ''))
def
__str__
(
self
):
return
self
.
name
or
repr
(
self
)
def
_grammar_assigned_notifier
(
self
):
if
self
.
grammar
:
...
...
DHParser/syntaxtree.py
View file @
f944249f
...
...
@@ -83,11 +83,8 @@ class ParserBase:
self
.
name
=
name
# type: str
self
.
_ptype
=
':'
+
self
.
__class__
.
__name__
# type: str
def
__repr__
(
self
):
self
.
name
+
self
.
ptype
def
__str__
(
self
):
return
self
.
name
or
repr
(
self
)
return
self
.
name
or
self
.
ptype
@
property
def
ptype
(
self
)
->
str
:
...
...
@@ -113,9 +110,6 @@ class MockParser(ParserBase):
self
.
name
=
name
self
.
_ptype
=
ptype
or
':'
+
self
.
__class__
.
__name__
# def __repr__(self):
# return repr_call(self.__init__, (self.name, self.ptype))
class
ZombieParser
(
MockParser
):
"""
...
...
examples/LaTeX/LaTeX.ebnf
View file @
f944249f
...
...
@@ -20,7 +20,7 @@ inlineenv = beginenv { command | block | text }+ endenv
beginenv = "\begin{" §NAME §"}"
endenv = "\end{" §::NAME §"}"
command = CMDNAME [ config ] block
command = CMDNAME [
[
config ] block
]
config = "[" cfgtext §"]"
block = "{" { text | block } §"}"
...
...
examples/LaTeX/recompile_grammar.py
View file @
f944249f
...
...
@@ -20,6 +20,8 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import
cProfile
import
functools
import
sys
sys
.
path
.
extend
([
'../../'
,
'../'
,
'./'
])
...
...
@@ -27,6 +29,18 @@ sys.path.extend(['../../', '../', './'])
from
DHParser.toolkit
import
logging
from
DHParser.testing
import
recompile_grammar
with
logging
():
if
not
recompile_grammar
(
'.'
,
True
):
def
profile
(
func
):
import
cProfile
pr
=
cProfile
.
Profile
()
pr
.
enable
()
ret
=
func
()
pr
.
disable
()
# after your program ends
pr
.
print_stats
(
sort
=
"tottime"
)
return
ret
with
logging
(
False
):
if
not
profile
(
functools
.
partial
(
recompile_grammar
,
ebnf_filename
=
'.'
,
force
=
True
)):
sys
.
exit
(
1
)
test/test_parsers.py
View file @
f944249f
...
...
@@ -73,7 +73,6 @@ ARITHMETIC2_EBNF = """
#
#
# ARITHMETIC_EBNFTransform = partial(traverse, processing_table=ARITHMETIC_EBNF_transformation_table)
# ARITHMETIC2_EBNFTransform = partial(traverse, processing_table=ARITHMETIC2_EBNF_transformation_table)
class
TestInfiLoopsAndRecursion
:
...
...
@@ -248,8 +247,8 @@ class TestPopRetrieve:
assert
not
syntax_tree
.
error_flag
,
str
(
syntax_tree
.
collect_errors
())
def
test_cache_neutrality
(
self
):
"""Test that packrat-caching does not interfere with
Capture
-
Retrieve
-Stack
."""
"""Test that packrat-caching does not interfere with
the variable-
changing parsers:
Capture
and
Retrieve."""
lang
=
"""
text = opening closing
opening = (unmarked_package | marked_package)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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