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
da3181ba
Commit
da3181ba
authored
Jan 24, 2018
by
eckhart
Browse files
- corrected a few static type errors
parent
99ab9629
Changes
5
Hide whitespace changes
Inline
Side-by-side
DHParser/dsl.py
View file @
da3181ba
...
...
@@ -320,7 +320,7 @@ def load_compiler_suite(compiler_suite: str) -> \
else
:
# assume source is an ebnf grammar. Is there really any reasonable application case for this?
with
logging
(
False
):
compiler_py
,
messages
,
_
=
compile_source
(
source
,
None
,
get_ebnf_grammar
(),
compiler_py
,
messages
,
n
=
compile_source
(
source
,
None
,
get_ebnf_grammar
(),
get_ebnf_transformer
(),
get_ebnf_compiler
())
if
has_errors
(
messages
):
raise
GrammarError
(
only_errors
(
messages
),
source
)
...
...
@@ -352,7 +352,7 @@ def is_outdated(compiler_suite: str, grammar_source: str) -> bool:
True, if ``compiler_suite`` seems to be out of date.
"""
try
:
_
,
grammar
,
_
,
_
=
load_compiler_suite
(
compiler_suite
)
n1
,
grammar
,
n2
,
n3
=
load_compiler_suite
(
compiler_suite
)
return
grammar_changed
(
grammar
(),
grammar_source
)
except
ValueError
:
return
True
...
...
DHParser/parse.py
View file @
da3181ba
...
...
@@ -1842,23 +1842,33 @@ class NegativeLookahead(Lookahead):
class
Lookbehind
(
FlowOperator
):
"""
Matches, if the contained parser would match backwards. Requires
the contained parser to be a RegExp
-
parser.
the contained parser to be a RegExp
, Re, PlainText or Token
parser.
"""
def
__init__
(
self
,
parser
:
Parser
,
name
:
str
=
''
)
->
None
:
p
=
parser
while
isinstance
(
p
,
Synonym
):
p
=
p
.
parser
assert
isinstance
(
p
,
RegExp
),
str
(
type
(
p
))
self
.
regexp
=
cast
(
RE
,
p
).
main
.
regexp
if
isinstance
(
p
,
RE
)
else
p
.
regexp
assert
isinstance
(
p
,
RegExp
)
or
isinstance
(
p
,
PlainText
)
or
isinstance
(
p
,
RE
),
str
(
type
(
p
))
self
.
regexp
=
None
self
.
text
=
None
if
isinstance
(
p
,
RE
):
if
isinstance
(
cast
(
RE
,
p
).
main
,
RegExp
):
self
.
regexp
=
cast
(
RegExp
,
cast
(
RE
,
p
).
main
).
regexp
else
:
# p.main is of type PlainText
self
.
text
=
cast
(
PlainText
,
cast
(
RE
,
p
).
main
).
text
elif
isinstance
(
p
,
RegExp
):
self
.
regexp
=
cast
(
RegExp
,
p
).
regexp
else
:
# p is of type PlainText
self
.
text
=
cast
(
PlainText
,
p
).
text
super
().
__init__
(
parser
,
name
)
def
__call__
(
self
,
text
:
StringView
)
->
Tuple
[
Optional
[
Node
],
StringView
]:
# backwards_text = self.grammar.document__[-len(text) - 1::-1]
backwards_text
=
self
.
grammar
.
reversed__
[
len
(
text
):]
if
self
.
sign
(
backwards_text
.
match
(
self
.
regexp
)):
return
Node
(
self
,
''
),
text
else
:
return
None
,
text
if
self
.
regexp
is
None
:
# assert self.text is not None
does_match
=
backwards_text
[:
len
(
self
.
text
)]
==
self
.
text
else
:
# assert self.regexp is not None
does_match
=
backwards_text
.
match
(
self
.
regexp
)
return
(
Node
(
self
,
''
),
text
)
if
self
.
sign
(
does_match
)
else
(
None
,
text
)
def
__repr__
(
self
):
return
'-&'
+
self
.
parser
.
repr
...
...
DHParser/syntaxtree.py
View file @
da3181ba
...
...
@@ -352,7 +352,7 @@ class Node(collections.abc.Sized):
"""
if
self
.
children
:
return
""
.
join
(
child
.
content
for
child
in
self
.
children
)
return
self
.
_result
return
cast
(
str
,
self
.
_result
)
@
property
...
...
DHParser/transform.py
View file @
da3181ba
...
...
@@ -653,7 +653,7 @@ def rstrip(context: List[Node], condition: Callable = is_expendable):
@
transformation_factory
(
Callable
)
def
strip
(
context
:
List
[
Node
],
condition
:
Callable
=
is_expendable
)
->
str
:
def
strip
(
context
:
List
[
Node
],
condition
:
Callable
=
is_expendable
):
"""Removes leading and trailing child-nodes that fulfill a given condition."""
lstrip
(
context
,
condition
)
rstrip
(
context
,
condition
)
...
...
examples/LaTeX/testdata/testdoc2.tex
View file @
da3181ba
0
\documentclass
[12pt, english, a4paper]
{
article
}
\begin{document}
...
...
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