Commit c29315c8 authored by di68kap's avatar di68kap

- Ergänzungen der Syntax für Bedeutungsangaben

parent afda6166
...@@ -77,7 +77,7 @@ JSON_Type = Union[Dict, Sequence, str, int, None] ...@@ -77,7 +77,7 @@ JSON_Type = Union[Dict, Sequence, str, int, None]
RE_IS_JSONRPC = b'\s*{' # b'\s*(?:{|\[|"|\d|true|false|null)' RE_IS_JSONRPC = b'\s*{' # b'\s*(?:{|\[|"|\d|true|false|null)'
RE_GREP_URL = b'GET ([^ \n]+) HTTP' RE_GREP_URL = b'GET ([^ \n]+) HTTP'
RE_FUNCTION_CALL = b'\s*(\w+)\(([^)\n]*)\)' RE_FUNCTION_CALL = b'\s*(\w+)\(([^)]*)\)$'
SERVER_ERROR = "COMPILER-SERVER-ERROR" SERVER_ERROR = "COMPILER-SERVER-ERROR"
......
...@@ -249,6 +249,8 @@ def isgenerictype(t): ...@@ -249,6 +249,8 @@ def isgenerictype(t):
# #
####################################################################### #######################################################################
RX_FILEPATH = re.compile(r'[^ \t][^\n\t?*]+(?<![ \t])') # r'[\w/:. \\]+'
def load_if_file(text_or_file) -> str: def load_if_file(text_or_file) -> str:
""" """
...@@ -264,7 +266,7 @@ def load_if_file(text_or_file) -> str: ...@@ -264,7 +266,7 @@ def load_if_file(text_or_file) -> str:
content = f.read() content = f.read()
return content return content
except FileNotFoundError: except FileNotFoundError:
if re.fullmatch(r'[\w/:. \\]+', text_or_file): if RX_FILEPATH.fullmatch(text_or_file):
raise FileNotFoundError('Not a valid file: ' + text_or_file + '!\n(Add "\\n" ' raise FileNotFoundError('Not a valid file: ' + text_or_file + '!\n(Add "\\n" '
'to distinguish source data from a file name.)') 'to distinguish source data from a file name.)')
else: else:
......
...@@ -185,7 +185,7 @@ class TestParserNameOverwriteBug: ...@@ -185,7 +185,7 @@ class TestParserNameOverwriteBug:
assert not has_errors(messages), str(messages) assert not has_errors(messages), str(messages)
def test_single_mandatory_bug(self): def test_single_mandatory_bug(self):
lang = """series = § /B/""" lang = """series = § /B/\n"""
result, messages, ast = compile_ebnf(lang) result, messages, ast = compile_ebnf(lang)
assert result.find('Required') < 0 assert result.find('Required') < 0
parser = grammar_provider(lang)() parser = grammar_provider(lang)()
...@@ -415,8 +415,8 @@ class TestFlowControlOperators: ...@@ -415,8 +415,8 @@ class TestFlowControlOperators:
"""Tests whether failures to comply with the required operator '§' """Tests whether failures to comply with the required operator '§'
are correctly reported as such. are correctly reported as such.
""" """
lang1 = r"nonsense == /\w+/~ # wrong_equal_sign" lang1 = r"nonsense == /\w+/~ # wrong_equal_sign "
lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions" lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions\n"
try: try:
parser_class = grammar_provider(lang1) parser_class = grammar_provider(lang1)
assert False, "Compilation error expected." assert False, "Compilation error expected."
......
...@@ -662,7 +662,7 @@ class TestErrorReporting: ...@@ -662,7 +662,7 @@ class TestErrorReporting:
class TestBorderlineCases: class TestBorderlineCases:
def test_not_matching(self): def test_not_matching(self):
minilang = """parser = /X/""" minilang = """parser = /X/\n"""
gr = grammar_provider(minilang)() gr = grammar_provider(minilang)()
cst = gr('X', 'parser') cst = gr('X', 'parser')
assert not cst.error_flag assert not cst.error_flag
......
...@@ -38,7 +38,7 @@ class TestLoggingAndLoading: ...@@ -38,7 +38,7 @@ class TestLoggingAndLoading:
self.filename = os.path.join("test", self.tmpname, "test.py") if os.path.isdir('test') \ self.filename = os.path.join("test", self.tmpname, "test.py") if os.path.isdir('test') \
else os.path.join(self.tmpname, "test.py") else os.path.join(self.tmpname, "test.py")
self.dirname = os.path.dirname(self.filename) self.dirname = os.path.dirname(self.filename)
self.code1 = "x = 46" self.code1 = "x = 46\n"
self.code2 = "def f():\n return 46" self.code2 = "def f():\n return 46"
if not os.path.exists(self.dirname): if not os.path.exists(self.dirname):
os.mkdir(self.dirname) os.mkdir(self.dirname)
......
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