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