Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
84aa440d
Commit
84aa440d
authored
Dec 21, 2017
by
eckhart
Browse files
- slight cleanups
parent
0fe428f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
DHParser/parsers.py
View file @
84aa440d
...
...
@@ -1040,7 +1040,6 @@ def dsl_error_msg(parser: Parser, error_str: str) -> str:
return
" "
.
join
(
msg
)
########################################################################
#
# Token and Regular Expression parser classes (i.e. leaf classes)
...
...
@@ -2081,7 +2080,7 @@ class Compiler:
"""
Class Compiler is the abstract base class for compilers. Compiler
objects are callable and take the root node of the abstract
syntax tree (AST) as a
g
rument and return the compiled code in a
syntax tree (AST) as ar
g
ument and return the compiled code in a
format chosen by the compiler itself.
Subclasses implementing a compiler must define `on_XXX()`-methods
...
...
@@ -2170,7 +2169,7 @@ class Compiler:
Calls the compilation method for the given node and returns the
result of the compilation.
The method's name is d
r
eived from either the node's parser
The method's name is de
r
ived from either the node's parser
name or, if the parser is anonymous, the node's parser's class
name by adding the prefix 'on_'.
...
...
@@ -2230,7 +2229,7 @@ def compile_source(source: str,
1. The result as returned by the compiler or ``None`` in case
of failure,
2. A list of error or warning messages
3. The root-node of the abstract syntax tree
low
3. The root-node of the abstract syntax tree
"""
source_text
=
load_if_file
(
source
)
log_file_name
=
logfile_basename
(
source
,
compiler
)
...
...
TODO.md
View file @
84aa440d
...
...
@@ -4,4 +4,5 @@ General TODO-List
-
Position Handling:
`Node._pos`
and
`Node._len`
should be set by
parser guard to allow for early dropping of nodes. (Should speed
up tree-traversal later)
\ No newline at end of file
-
Position handling should provide for position shifts during preprocessing
examples/CommonMark/README.md
View file @
84aa440d
OUTDATED
CommonMark
==========
...
...
examples/unit_test_praesentation/beipiel1.py
deleted
100644 → 0
View file @
0fe428f6
import
functools
import
sys
sys
.
path
.
extend
([
'../../'
,
'../'
,
'./'
])
from
DHParser
import
*
arithmetik_ebnf
=
"""
expr = expr ("+"|"-") term | term
term = term ("*"|"/") factor | factor
factor = /[0-9]+/~ | "(" expr ")"
"""
ASTTable
=
{
"+"
:
remove_expendables
,
"*"
:
replace_by_single_child
,
"factor"
:
[
reduce_single_child
,
remove_brackets
]
}
parser
=
grammar_provider
(
arithmetik_ebnf
)()
transformer
=
functools
.
partial
(
traverse
,
processing_table
=
ASTTable
.
copy
())
syntax_tree
=
parser
(
"5 + 3 * 4"
)
assert
not
syntax_tree
.
error_flag
,
str
(
syntax_tree
.
collect_errors
())
transformer
(
syntax_tree
)
print
(
">>>>> Ausdruck ohne Klammern:
\n
"
)
print
(
syntax_tree
.
as_sxpr
(
compact
=
True
))
syntax_tree
=
parser
(
"(5 + 3) * 4"
)
assert
not
syntax_tree
.
error_flag
,
str
(
syntax_tree
.
collect_errors
())
transformer
(
syntax_tree
)
print
(
"
\n\n
>>>>> Ausdruck mit Klammern:
\n
"
)
print
(
syntax_tree
.
as_sxpr
(
compact
=
True
))
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