Commit 8a2697ae authored by di68kap's avatar di68kap
Browse files

- renamed parser.py to parsercombinators.py to avoid possible name conflicts...

- renamed parser.py to parsercombinators.py to avoid possible name conflicts with the parser module from the Python standard library
parent d38fa945
......@@ -14,7 +14,6 @@ testdata/*.pdf
*~
*.old
DEBUG*
LOGS*
LOGS/
external_resources/
tmp/
......
......@@ -29,8 +29,8 @@ except ImportError:
import re
from EBNFcompiler import EBNFGrammar, EBNFCompiler, EBNFTransTable, load_if_file, md5
from logs import LOGGING
from parser import *
from logs import IS_LOGGING
from parsercombinators import *
from syntaxtree import *
from version import __version__
......@@ -313,7 +313,7 @@ def run_compiler(source_file, compiler_suite="", extension=".xml"):
print(result)
finally:
if f: f.close()
if LOGGING:
if IS_LOGGING():
print(ast)
return []
......
......@@ -27,7 +27,7 @@ try:
except ImportError:
import re
from parser import *
from parsercombinators import *
from syntaxtree import *
from version import __version__
......
......@@ -24,7 +24,7 @@ from functools import partial
from DSLsupport import compileDSL, run_compiler
from EBNFcompiler import EBNFGrammar, EBNFTransTable, EBNFCompiler
from parser import full_compilation
from parsercombinators import full_compilation
def selftest(file_name):
......
......@@ -42,7 +42,7 @@ class MLWGrammar(GrammarBase):
# EBNF-Syntax für MLW-Artikel
@ comment = /#.*(?:\n|$)/ # Kommentare beginnen mit '#' und reichen bis zum Zeilenende
@ whitespace = /[\t\r\ ]*/ # Auch Zeilensprünge zählen als Leerraum
@ whitespace = /[\t ]*/ # Zeilensprünge zählen nicht als Leerraum
@ literalws = both # Leerraum vor und nach Literalen wird automatisch entfernt
......@@ -138,11 +138,12 @@ class MLWGrammar(GrammarBase):
DATEI_ENDE = !/./
NIEMALS = /(?!.)/
"""
source_hash__ = "cf1ef8acfc5e15dffc53b1b48eda89b0"
source_hash__ = "f373a397a48cc57bcca18b90dd7028bf"
parser_initialization__ = "upon instatiation"
wsp__ = mixin_comment(whitespace=r'[\t\r\ ]*', comment=r'#.*(?:\n|$)')
wspL__ = wsp__
wspR__ = wsp__
COMMENT__ = r'#.*(?:\n|$)'
WSP__ = mixin_comment(whitespace=r'[\t ]*', comment=r'#.*(?:\n|$)')
wspL__ = WSP__
wspR__ = WSP__
NIEMALS = RE('(?!.)', wR='', wL='')
DATEI_ENDE = NegativeLookahead(RE('.', wR='', wL=''))
LEER = RE('\\s+', wR='', wL='')
......
......@@ -31,7 +31,7 @@ already exists.
import os
__all__ = ['logging_on', 'logging_off', 'LOGGING', 'LOGS_DIR']
__all__ = ['logging_on', 'logging_off', 'IS_LOGGING', 'LOGS_DIR']
LOGGING: str = "LOGS" # LOGGING = "" turns logging off!
......@@ -49,6 +49,11 @@ def logging_off():
LOGGING = ""
def IS_LOGGING():
"""-> True, if logging is turned on."""
return bool(LOGGING)
def LOGS_DIR() -> str:
"""Returns a path of a directory where log files will be stored.
......
#!/usr/bin/python3
"""parser.py - parser combinators for for DHParser
"""parsercombinators.py - parser combinators for for DHParser
Copyright 2016 by Eckhart Arnold (arnold@badw.de)
Bavarian Academy of Sciences an Humanities (badw.de)
......@@ -59,7 +59,7 @@ try:
except ImportError:
import re
from logs import LOGGING, LOGS_DIR
from logs import IS_LOGGING, LOGS_DIR
from syntaxtree import WHITESPACE_KEYWORD, TOKEN_KEYWORD, ZOMBIE_PARSER, Node, \
error_messages, ASTTransform
......@@ -283,7 +283,7 @@ class GrammarBase:
def __init__(self):
self.all_parsers = set()
self.dirty_flag = False
self.history_tracking = LOGGING
self.history_tracking = IS_LOGGING()
self._reset()
self._assign_parser_names()
self.root__ = copy.deepcopy(self.__class__.root__)
......@@ -376,7 +376,7 @@ class GrammarBase:
elif os.path.exists(path):
os.remove(path)
if LOGGING:
if IS_LOGGING():
assert self.history
if not log_file_name:
name = self.__class__.__name__
......@@ -394,7 +394,6 @@ class GrammarBase:
write_log(errors_only, log_file_name + '_errors')
########################################################################
#
# Token and Regular Expression parser classes (i.e. leaf classes)
......
......@@ -29,7 +29,7 @@ except ImportError:
import re
from typing import NamedTuple
from logs import LOGGING, LOGS_DIR
from logs import IS_LOGGING, LOGS_DIR
__all__ = ['WHITESPACE_KEYWORD',
......@@ -320,8 +320,7 @@ class Node:
return []
def log(self, log_file_name, ext):
# global LOGGING
if LOGGING:
if IS_LOGGING():
st_file_name = log_file_name + ext
with open(os.path.join(LOGS_DIR(), st_file_name), "w", encoding="utf-8") as f:
f.write(self.as_sexpr())
......
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