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
9a6df97d
Commit
9a6df97d
authored
Aug 06, 2017
by
Eckhart Arnold
Browse files
further changes to LaTeX ebnf-transformation
parent
3978f82c
Changes
8
Hide whitespace changes
Inline
Side-by-side
DHParser/ebnf.py
View file @
9a6df97d
...
...
@@ -317,9 +317,9 @@ class EBNFCompiler(Compiler):
self
.
current_symbols
=
[]
# type: List[Node]
self
.
symbols
=
{}
# type: Dict[str, Node]
self
.
variables
=
set
()
# type: Set[str]
self
.
definitions
=
[]
# type: List[Tuple[str, str]]
#
self.definitions = []
# type: List[Tuple[str, str]]
self
.
recursive
=
set
()
# type: Set[str]
self
.
deferred_tasks
=
[]
# type: List[Callable]
self
.
deferred_tasks
=
[]
# type: List[Callable]
self
.
root
=
""
# type: str
self
.
directives
=
{
'whitespace'
:
self
.
WHITESPACE
[
'horizontal'
],
'comment'
:
''
,
...
...
DHParser/testing.py
View file @
9a6df97d
...
...
@@ -98,6 +98,10 @@ def get_report(test_unit):
"""
Returns a text-report of the results of a grammar unit test.
"""
def
indent
(
txt
):
lines
=
txt
.
split
(
'
\n
'
)
lines
[
0
]
=
' '
+
lines
[
0
]
return
"
\n
"
.
join
(
lines
)
report
=
[]
for
parser_name
,
tests
in
test_unit
.
items
():
heading
=
'Test of parser: "%s"'
%
parser_name
...
...
@@ -106,7 +110,7 @@ def get_report(test_unit):
heading
=
'Match-test "%s"'
%
test_name
report
.
append
(
'
\n
%s
\n
%s
\n
'
%
(
heading
,
'-'
*
len
(
heading
)))
report
.
append
(
'### Test-code:'
)
report
.
append
(
test_code
)
report
.
append
(
indent
(
test_code
)
)
error
=
tests
.
get
(
'__err__'
,
{}).
get
(
test_name
,
""
)
if
error
:
report
.
append
(
'
\n
### Error:'
)
...
...
@@ -115,10 +119,10 @@ def get_report(test_unit):
cst
=
tests
.
get
(
'__cst__'
,
{}).
get
(
test_name
,
None
)
if
cst
and
(
not
ast
or
cst
==
ast
):
report
.
append
(
'
\n
### CST'
)
report
.
append
(
cst
.
as_sxpr
())
report
.
append
(
indent
(
cst
.
as_sxpr
())
)
elif
ast
:
report
.
append
(
'
\n
### AST'
)
report
.
append
(
ast
.
as_sxpr
())
report
.
append
(
indent
(
ast
.
as_sxpr
())
)
return
'
\n
'
.
join
(
report
)
...
...
@@ -199,7 +203,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
report_dir
=
"REPORT"
if
not
os
.
path
.
exists
(
report_dir
):
os
.
mkdir
(
report_dir
)
with
open
(
os
.
path
.
join
(
report_dir
,
unit_name
+
'.
report
'
),
'w'
)
as
f
:
with
open
(
os
.
path
.
join
(
report_dir
,
unit_name
+
'.
md
'
),
'w'
)
as
f
:
f
.
write
(
get_report
(
test_unit
))
return
errata
...
...
DHParser/toolkit.py
View file @
9a6df97d
...
...
@@ -314,7 +314,7 @@ def expand_table(compact_table):
value
=
compact_table
[
key
]
for
k
in
smart_list
(
key
):
if
k
in
expanded_table
:
raise
KeyError
(
"
Key %s used more than once in compact table!
"
%
key
)
raise
KeyError
(
'
Key
"
%s
"
used more than once in compact table!
'
%
key
)
expanded_table
[
k
]
=
value
return
expanded_table
...
...
examples/LaTeX/LaTeX.ebnf
View file @
9a6df97d
...
...
@@ -102,7 +102,7 @@ known_command = footnote | includegraphics | caption
generic_command = !no_command CMDNAME [[ //~ config ] //~ block ]
footnote = "\footnote" block_of_paragraphs
includegraphics = "\includegraphics" config block
includegraphics = "\includegraphics"
[
config
]
block
caption = "\caption" block
...
...
examples/LaTeX/LaTeXCompiler.py
View file @
9a6df97d
...
...
@@ -346,7 +346,7 @@ LaTeX_AST_transformation_table = {
"block_environment"
:
replace_by_single_child
,
"known_environment"
:
replace_by_single_child
,
"generic_block"
:
[],
"begin_generic_block, end_generic_block"
:
re
duce
_single_child
,
"begin_generic_block, end_generic_block"
:
re
place_by
_single_child
,
"itemize, enumerate"
:
[
remove_brackets
,
flatten
],
"item"
:
[
remove_first
],
"figure"
:
[],
...
...
@@ -361,7 +361,7 @@ LaTeX_AST_transformation_table = {
"inline_environment"
:
replace_by_single_child
,
"known_inline_env"
:
replace_by_single_child
,
"generic_inline_env"
:
[],
"begin_inline_env, end_inline_env"
:
[
re
duce
_single_child
],
"begin_inline_env, end_inline_env"
:
[
re
place_by
_single_child
],
"begin_environment, end_environment"
:
[
remove_brackets
,
reduce_single_child
],
"inline_math"
:
[
remove_brackets
,
reduce_single_child
],
"command"
:
[],
...
...
@@ -372,11 +372,9 @@ LaTeX_AST_transformation_table = {
"caption"
:
[],
"config"
:
[
remove_brackets
],
"block"
:
[
remove_brackets
,
reduce_single_child
(
is_anonymous
)],
"text"
:
[
reduce_single_child
,
merge_children
(
'word_sequence'
,
':Whitespace'
,
'TEXTCHUNK'
)],
"cfgtext"
:
[
flatten
,
reduce_single_child
,
replace_parser
(
'text'
)],
"word_sequence"
:
collapse
,
# [flatten, merge_children('TEXTCHUNK', ':Whitespace'), reduce_single_child],
"no_command"
:
[],
"blockcmd"
:
[],
"text"
:
collapse
,
"cfgtext, word_sequence"
:
[],
"no_command, blockcmd"
:
[],
"structural"
:
[],
"CMDNAME"
:
[
remove_whitespace
,
reduce_single_child
(
is_anonymous
)],
"NAME"
:
[
reduce_single_child
,
remove_whitespace
,
reduce_single_child
],
...
...
examples/LaTeX/grammar_tests/test_paragraph.ini
View file @
9a6df97d
...
...
@@ -26,6 +26,7 @@
8
:
Unknwon
\xy
commands
within
paragraphs
may
be
simple
or
\xy{complex}.
[fail:paragraph]
1
:
\begin{enumerate}
2
:
\item
...
...
examples/LaTeX/grammar_tests/test_text.ini
0 → 100644
View file @
9a6df97d
[match:text]
1:
Some
plain
text
2:
Text
containing
[ brackets ]
is
distinguished
from
cfgtext
3:
Text
can
also
"escaped"
characters
like
\&,
\%
or
\_
.
4:
Text
can
contain
both
brackets
[]
and
"esacped"
characters
\&
.
examples/LaTeX/tst_LaTeX_grammar.py
View file @
9a6df97d
...
...
@@ -35,7 +35,7 @@ if not DHParser.dsl.recompile_grammar('LaTeX.ebnf', force=True): # recompiles G
from
DHParser
import
toolkit
from
LaTeXCompiler
import
get_grammar
,
get_transformer
with
toolkit
.
logging
(
Tru
e
):
with
toolkit
.
logging
(
Fals
e
):
error_report
=
testing
.
grammar_suite
(
'grammar_tests'
,
get_grammar
,
get_transformer
,
report
=
True
,
verbose
=
True
)
if
error_report
:
...
...
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