Commit 90a003a3 authored by eckhart's avatar eckhart

- examples adjusted

parent a8bf0742
......@@ -129,6 +129,8 @@ def logging(dirname="LOGS"):
except AttributeError:
save = ""
GLOBALS.LOGGING = dirname or ""
if dirname and not os.path.exists(dirname):
os.mkdir(dirname)
yield
GLOBALS.LOGGING = save
......
......@@ -22,7 +22,7 @@ from DHParser import is_filename, Grammar, Compiler, Lookbehind, Alternative, Po
ZeroOrMore, Forward, NegativeLookahead, mixin_comment, compile_source, \
PreprocessorFunc, TransformationDict, \
Node, TransformationFunc, traverse, remove_children_if, is_anonymous, \
reduce_single_child, replace_by_single_child, remove_whitespace, \
reduce_single_child, replace_by_single_child, remove_whitespace, reduce_anonymous_nodes, \
flatten, is_empty, collapse, replace_content, replace_content_by, remove_brackets, \
is_one_of, traverse_locally, remove_tokens, remove_nodes, TOKEN_PTYPE, Error, GLOBALS
from DHParser.log import logging
......@@ -191,7 +191,7 @@ def streamline_whitespace(context):
def watch(node):
print(node.as_sxpr())
flatten_structure = flatten(lambda context: is_anonymous(context) or is_one_of(
flatten_structure = flatten(lambda context: is_one_of(
context, {"Chapters", "Sections", "SubSections", "SubSubSections", "Paragraphs",
"SubParagraphs", "sequence"}), recursive=True)
......@@ -219,7 +219,7 @@ drop_expendables = remove_children_if(lambda context: is_empty(context) or
LaTeX_AST_transformation_table = {
# AST Transformations for the LaTeX-grammar
"<": [drop_expendables, flatten_structure],
"<": [reduce_anonymous_nodes, flatten_structure],
"latexdoc": [],
"preamble": [traverse_locally({'<': remove_whitespace, 'block': replace_by_single_child})],
"document": [flatten_structure],
......
......@@ -64,8 +64,6 @@ def count_nodes(tree, condition=lambda n: True):
def tst_func():
with DHParser.log.logging(LOGGING):
if not os.path.exists('REPORT'):
os.mkdir('REPORT')
files = os.listdir('testdata')
files.sort()
for file in files:
......@@ -80,7 +78,7 @@ def tst_func():
# lambda n: not bool(n.result))))
if DHParser.log.is_logging():
print('Saving CST')
with open('REPORT/' + file[:-4] + '.cst', 'w', encoding='utf-8') as f:
with open('LOGS/' + file[:-4] + '.cst', 'w', encoding='utf-8') as f:
f.write(result.as_sxpr(compact=True))
print('Saving parsing history')
log_parsing_history(parser, os.path.basename(file), html=True)
......
......@@ -10,6 +10,7 @@
@ literalws = none # literals have no implicit whitespace
@ comment = // # no implicit comments
@ ignorecase = False # literals and regular expressions are case-sensitive
@ drop = token, whitespace # drop anonymous tokens and whitespace
#######################################################################
......
This diff is collapsed.
......@@ -11,6 +11,7 @@
@ literalws = none # literals have no implicit whitespace
@ comment = // # no implicit comments
@ ignorecase = False # literals and regular expressions are case-sensitive
@ drop = Token, Whitespace
#######################################################################
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment