Commit 9bf2aea1 authored by eckhart's avatar eckhart
Browse files

- stub for a compilation-server-module extended

parent 353390e2
......@@ -123,6 +123,17 @@ CONFIG_PRESET['static_analysis'] = "none"
CONFIG_PRESET['add_grammar_source_to_parser_docstring'] = False
########################################################################
#
# compiler server configuration
#
########################################################################
# Maximum allowed source code size in bytes
# Default value: 16 MB
CONFIG_PRESET['max_source_size'] = 16 * 1024 * 1024
########################################################################
#
# testing framework configuration
......
......@@ -78,7 +78,6 @@ def compile_src(source, log_dir=''):
"""
with logging(log_dir):
compiler = get_compiler()
cname = compiler.__class__.__name__
result_tuple = compile_source(source, get_preprocessor(),
get_grammar(),
get_transformer(), compiler)
......
......@@ -36,10 +36,33 @@ of module `server`, i.e. the compilation-modules, to decide.
import asyncio
from typing import Callable, Any
from DHParser.preprocess import BEGIN_TOKEN, END_TOKEN, TOKEN_DELIMITER
from DHParser.toolkit import get_config_value
# TODO: implement compilation-server!
SERVER_ERROR = "COMPILER-SERVER-ERROR"
CompileFunc = Callable[[str, str], Any] # compiler_src(source: str, log_dir: str) -> Any
class CompilerServer:
def __init__(self, compiler: CompileFunc):
self.compiler = compiler
self.max_source_size = get_config_value('max_source_size')
def handle_compilation_request(self, reader, writer):
data = await reader.read(self.max_source_size + 1)
if len(data) > self.max_source_size:
writer.write(BEGIN_TOKEN + SERVER_ERROR + TOKEN_DELIMITER +
"Source code to large! Only %iMB allowed." %
(self.max_source_size // (1024**2)) + END_TOKEN)
else:
pass # TODO: to be continued
await writer.drain()
writer.close()
async def handle_echo(reader, writer):
# TODO: Add deliver/answer-challenge-mechanism here to verify the source
......
......@@ -115,6 +115,7 @@ ArithmeticSimple_AST_transformation_table = {
def ArithmeticSimpleTransform() -> TransformationFunc:
return partial(traverse, processing_table=ArithmeticSimple_AST_transformation_table.copy())
def get_transformer() -> TransformationFunc:
try:
transformer = GLOBALS.ArithmeticSimple_00000001_transformer_singleton
......@@ -177,13 +178,14 @@ def compile_src(source, log_dir=''):
"""
with logging(log_dir):
compiler = get_compiler()
cname = compiler.__class__.__name__
result_tuple = compile_source(source, get_preprocessor(),
get_grammar(),
get_transformer(), compiler)
return result_tuple
if __name__ == "__main__":
# recompile grammar if needed
grammar_path = os.path.abspath(__file__).replace('Compiler.py', '.ebnf')
......
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