Commit 64ae1483 authored by eckhart's avatar eckhart
Browse files

- sync commit

parent d4d487d1
No preview for this file type
......@@ -641,7 +641,8 @@ class EBNFCompiler(Compiler):
'',
' def _reset(self):',
' super()._reset()',
' # initialize your variables here, not in the constructor!']
' # initialize your variables here, not in the constructor!',
'']
for name in self.rules:
method_name = visitor_name(name)
if name == self.root_symbol:
......
......@@ -32,8 +32,13 @@ file system an merely return an success or failure message. Module `server`
does not define any of these message. This is completely up to the clients
of module `server`, i.e. the compilation-modules, to decide.
The communication, i.e. requests and responses, follows the json-rpc protocol
(https://www.jsonrpc.org/specification)
The communication, i.e. requests and responses, follows the json-rpc protocol:
https://www.jsonrpc.org/specification
For JSON see:
https://json.org/
"""
......@@ -42,7 +47,7 @@ import json
from multiprocessing import Process, Value, Queue
from typing import Callable, Optional, Union, Dict, List, Sequence, cast
from DHParser.toolkit import get_config_value
from DHParser.toolkit import get_config_value, re
RPC_Table = Dict[str, Callable]
RPC_Type = Union[RPC_Table, List[Callable], Callable]
......@@ -55,6 +60,9 @@ SERVER_ONLINE = 2
SERVER_TERMINATE = 3
RX_MAYBE_JSON = re.compile('\s*(?:\{|\[|"|\d|true|false|null)')
class Server:
def __init__(self, rpc_functions: RPC_Type):
if isinstance(rpc_functions, Dict):
......@@ -70,7 +78,7 @@ class Server:
self.max_source_size = get_config_value('max_rpc_size')
self.stage = Value('b', SERVER_OFFLINE)
self.server = None # type: Optional[asyncio.base_events.Server]
self.server = None
self.server_messages = Queue() # type: Queue
self.server_process = None # type: Optional[Process]
......
......@@ -18,8 +18,10 @@
"""
Module ``toolkit`` contains utility functions that are needed across
several of the the other DHParser-Modules or that are just very generic
so that they are best defined in a toolkit-module.
several of the the other DHParser-Modules Helper funcions that are not
needed in more than one module are best placed within that module and
not in the toolkit-module. An acceptable exception from this rule are
functions that are very generic.
"""
import hashlib
......
......@@ -151,6 +151,7 @@ class ArithmeticRightRecursiveCompiler(Compiler):
def _reset(self):
super()._reset()
# initialize your variables here, not in the constructor!
def on_expression(self, node):
return self.fallback_compiler(node)
......
......@@ -42,6 +42,7 @@ class TestParserError:
pe = ParserError(Node('TAG', 'test').with_pos(0), StringView('Beispiel'), True)
assert str(pe).find('Beispiel') >= 0 and str(pe).find('TAG') >= 0
class TestParserClass:
def test_apply(self):
minilang ="""
......@@ -66,7 +67,7 @@ class TestParserClass:
class TestInfiLoopsAndRecursion:
def test_direct_left_recursion1(self):
minilang ="""
minilang = """
expr = expr ("+"|"-") term | term
term = term ("*"|"/") factor | factor
factor = /[0-9]+/~
......@@ -176,6 +177,7 @@ class TestInfiLoopsAndRecursion:
# assert not res
# set_config_value('static_analysis', save)
class TestFlowControl:
def setup(self):
self.t1 = """
......@@ -237,8 +239,8 @@ class TestRegex:
def test_multilineRegex_wo_Comments(self):
mlregex = r"""
regex = /\w+
[+]
regex = /\w+
[+]
\w* /
"""
result, messages, syntax_tree = compile_source(mlregex, None, get_ebnf_grammar(),
......@@ -293,8 +295,9 @@ class TestRegex:
test
\end{document}
"""
result, messages, syntax_tree = compile_source(tokenlang, None, get_ebnf_grammar(),
get_ebnf_transformer(), get_ebnf_compiler("TokenTest"))
result, messages, syntax_tree = compile_source(
tokenlang, None, get_ebnf_grammar(), get_ebnf_transformer(),
get_ebnf_compiler("TokenTest"))
assert result
assert not messages, str(messages)
parser = compile_python_object(DHPARSER_IMPORTS + result, r'\w+Grammar$')()
......@@ -635,7 +638,7 @@ class TestWhitespaceHandling:
class TestErrorReporting:
grammar = """
root = series alpha | anything
series = subseries &alpha
series = subseries &alpha
subseries = alpha §beta
alpha = /[a-z]+/
beta = /[A-Z]+/
......@@ -805,12 +808,12 @@ class TestEarlyTokenWhitespaceDrop:
@ drop = token, whitespace
expression = term { ("+" | "-") term}
term = factor { ("*"|"/") factor}
factor = number | variable | "(" expression ")"
factor = number | variable | "(" expression ")"
| constant | fixed
variable = /[a-z]/~
number = /\d+/~
constant = "A" | "B"
fixed = "X"
fixed = "X"
"""
self.gr = grammar_provider(self.lang)()
......@@ -891,7 +894,7 @@ class TestMetaParser:
term = factor { (DIV|MUL) factor}
factor = NUMBER | VARIABLE
MUL = "*" | &factor
DIV = "/"
DIV = "/"
NUMBER = /(?:0|(?:[1-9]\d*))(?:\.\d+)?/~
VARIABLE = /[A-Za-z]/~
"""
......@@ -899,6 +902,7 @@ class TestMetaParser:
cst = gr("2x")
assert bool(cst.pick('MUL')), "Named empty nodes should not be dropped!!!"
if __name__ == "__main__":
from DHParser.testing import runner
with logging(False):
......
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