From c29315c8ac27ce98871cadc4d44de8bba812770a Mon Sep 17 00:00:00 2001 From: di68kap Date: Fri, 26 Apr 2019 12:16:30 +0200 Subject: [PATCH] =?UTF-8?q?-=20Erg=C3=A4nzungen=20der=20Syntax=20f=C3=BCr?= =?UTF-8?q?=20Bedeutungsangaben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DHParser/server.py | 2 +- DHParser/toolkit.py | 4 +++- test/test_ebnf.py | 6 +++--- test/test_parse.py | 2 +- test/test_toolkit.py | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/DHParser/server.py b/DHParser/server.py index cd98cdc..9024a88 100644 --- a/DHParser/server.py +++ b/DHParser/server.py @@ -77,7 +77,7 @@ JSON_Type = Union[Dict, Sequence, str, int, None] RE_IS_JSONRPC = b'\s*{' # b'\s*(?:{|\[|"|\d|true|false|null)' 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" diff --git a/DHParser/toolkit.py b/DHParser/toolkit.py index 9e94e20..4e37c82 100644 --- a/DHParser/toolkit.py +++ b/DHParser/toolkit.py @@ -249,6 +249,8 @@ def isgenerictype(t): # ####################################################################### +RX_FILEPATH = re.compile(r'[^ \t][^\n\t?*]+(? str: """ @@ -264,7 +266,7 @@ def load_if_file(text_or_file) -> str: content = f.read() return content 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" ' 'to distinguish source data from a file name.)') else: diff --git a/test/test_ebnf.py b/test/test_ebnf.py index 0badea6..b24eb3d 100644 --- a/test/test_ebnf.py +++ b/test/test_ebnf.py @@ -185,7 +185,7 @@ class TestParserNameOverwriteBug: assert not has_errors(messages), str(messages) def test_single_mandatory_bug(self): - lang = """series = § /B/""" + lang = """series = § /B/\n""" result, messages, ast = compile_ebnf(lang) assert result.find('Required') < 0 parser = grammar_provider(lang)() @@ -415,8 +415,8 @@ class TestFlowControlOperators: """Tests whether failures to comply with the required operator '§' are correctly reported as such. """ - lang1 = r"nonsense == /\w+/~ # wrong_equal_sign" - lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions" + lang1 = r"nonsense == /\w+/~ # wrong_equal_sign " + lang2 = "nonsense = [^{}%]+ # someone forgot the '/'-delimiters for regular expressions\n" try: parser_class = grammar_provider(lang1) assert False, "Compilation error expected." diff --git a/test/test_parse.py b/test/test_parse.py index 1f803b5..ba17ad9 100644 --- a/test/test_parse.py +++ b/test/test_parse.py @@ -662,7 +662,7 @@ class TestErrorReporting: class TestBorderlineCases: def test_not_matching(self): - minilang = """parser = /X/""" + minilang = """parser = /X/\n""" gr = grammar_provider(minilang)() cst = gr('X', 'parser') assert not cst.error_flag diff --git a/test/test_toolkit.py b/test/test_toolkit.py index 15d6e02..c639d07 100644 --- a/test/test_toolkit.py +++ b/test/test_toolkit.py @@ -38,7 +38,7 @@ class TestLoggingAndLoading: self.filename = os.path.join("test", self.tmpname, "test.py") if os.path.isdir('test') \ else os.path.join(self.tmpname, "test.py") self.dirname = os.path.dirname(self.filename) - self.code1 = "x = 46" + self.code1 = "x = 46\n" self.code2 = "def f():\n return 46" if not os.path.exists(self.dirname): os.mkdir(self.dirname) -- GitLab