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
8229e7f3
Commit
8229e7f3
authored
Sep 19, 2017
by
Eckhart Arnold
Browse files
- syntaxtree.py: bugfix in Node.content
parent
b1784f9f
Changes
6
Hide whitespace changes
Inline
Side-by-side
DHParser/syntaxtree.py
View file @
8229e7f3
...
...
@@ -362,8 +362,8 @@ class Node(collections.abc.Sized):
"""
s
=
""
.
join
(
child
.
content
()
for
child
in
self
.
children
)
if
self
.
children
\
else
str
(
self
.
result
)
return
(
' <<< Error on "%s" | %s >>> '
%
(
s
,
'; '
.
join
(
self
.
_errors
)))
if
self
.
_errors
else
s
return
(
' <<< Error on "%s" | %s >>> '
%
(
s
,
'; '
.
join
(
e
.
message
for
e
in
self
.
_errors
)))
if
self
.
_errors
else
s
def
find
(
self
,
match_function
:
Callable
)
->
Iterator
[
'Node'
]:
...
...
examples/EBNF/EBNF.ebnf
View file @
8229e7f3
...
...
@@ -5,11 +5,11 @@
@ literalws = right # trailing whitespace of literals will be ignored tacitly
syntax = [~//] { definition | directive } §EOF
definition = symbol §
(
"=" expression
)
directive = "@" §symbol
§
"=" ( regexp | literal | list_ )
definition = symbol §"=" expression
directive = "@" §symbol "=" ( regexp | literal | list_ )
expression = term { "|" term }
term = { factor }+
term = { factor }+
["§" { factor }+ ] # "§" reguired
factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition
| [flowmarker] literal
| [flowmarker] regexp
...
...
@@ -18,7 +18,7 @@ factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be
| repetition
| option
flowmarker = "!" | "&"
| "§" |
# '!' negative lookahead, '&' positive lookahead
, '§' required
flowmarker = "!" | "&"
# '!' negative lookahead, '&' positive lookahead
"-!" | "-&" # '-' negative lookbehind, '-&' positive lookbehind
retrieveop = "::" | ":" # '::' pop, ':' retrieve
...
...
examples/EBNF/EBNF_old.ebnf
0 → 100644
View file @
8229e7f3
# EBNF-Grammar in EBNF
@ comment = /#.*(?:\n|$)/ # comments start with '#' and eat all chars up to and including '\n'
@ whitespace = /\s*/ # whitespace includes linefeed
@ literalws = right # trailing whitespace of literals will be ignored tacitly
syntax = [~//] { definition | directive } §EOF
definition = symbol §("=" expression)
directive = "@" §symbol §"=" ( regexp | literal | list_ )
expression = term { "|" term }
term = { factor }+
factor = [flowmarker] [retrieveop] symbol !"=" # negative lookahead to be sure it's not a definition
| [flowmarker] literal
| [flowmarker] regexp
| [flowmarker] group
| [flowmarker] oneormore
| repetition
| option
flowmarker = "!" | "&" | "§" | # '!' negative lookahead, '&' positive lookahead, '§' required
"-!" | "-&" # '-' negative lookbehind, '-&' positive lookbehind
retrieveop = "::" | ":" # '::' pop, ':' retrieve
group = "(" expression §")"
oneormore = "{" expression "}+"
repetition = "{" expression §"}"
option = "[" expression §"]"
symbol = /(?!\d)\w+/~ # e.g. expression, factor, parameter_list
literal = /"(?:[^"]|\\")*?"/~ # e.g. "(", '+', 'while'
| /'(?:[^']|\\')*?'/~ # whitespace following literals will be ignored tacitly.
regexp = /~?\/(?:\\\/|[^\/])*?\/~?/~ # e.g. /\w+/, ~/#.*(?:\n|$)/~
# '~' is a whitespace-marker, if present leading or trailing
# whitespace of a regular expression will be ignored tacitly.
list_ = /\w+/~ { "," /\w+/~ } # comma separated list of symbols, e.g. BEGIN_LIST, END_LIST,
# BEGIN_QUOTE, END_QUOTE ; see CommonMark/markdown.py for an exmaple
EOF = !/./
examples/EBNF/recompile_grammar.py
0 → 100644
View file @
8229e7f3
#!/usr/bin/python3
"""recompile_grammar.py - recompiles all pdf files in the current directoy
Author: Eckhart Arnold <arnold@badw.de>
Copyright 2017 Bavarian Academy of Sciences and Humanities
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import
sys
sys
.
path
.
extend
([
'../../'
,
'../'
,
'./'
])
from
DHParser
import
dsl
dsl
.
recompile_grammar
(
'.'
)
examples/LaTeX/LaTeX.ebnf
View file @
8229e7f3
# LaTeX-Grammar for DHParser
@ whitespace = /[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?/ # optional whitespace, including at most one linefeed
@ comment = /%.*/
...
...
examples/LaTeX/LaTeXCompiler.py
View file @
8229e7f3
...
...
@@ -49,6 +49,7 @@ class LaTeXGrammar(Grammar):
# LaTeX-Grammar for DHParser
@ whitespace = /[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?/ # optional whitespace, including at most one linefeed
@ comment = /%.*/
...
...
@@ -228,7 +229,7 @@ class LaTeXGrammar(Grammar):
paragraph
=
Forward
()
tabular_config
=
Forward
()
text_element
=
Forward
()
source_hash__
=
"
37585004123d6b80ecf8f67217b43479
"
source_hash__
=
"
2438244cc4ad969a9d12e946b8218eb6
"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
'%.*'
WHITESPACE__
=
r
'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
...
...
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