Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
9bf2aea1
Commit
9bf2aea1
authored
Mar 05, 2019
by
eckhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- stub for a compilation-server-module extended
parent
353390e2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
2 deletions
+37
-2
DHParser/configuration.py
DHParser/configuration.py
+11
-0
DHParser/dsl.py
DHParser/dsl.py
+0
-1
DHParser/server.py
DHParser/server.py
+23
-0
examples/ArithmeticSimple/ArithmeticSimpleCompiler.py
examples/ArithmeticSimple/ArithmeticSimpleCompiler.py
+3
-1
No files found.
DHParser/configuration.py
View file @
9bf2aea1
...
...
@@ -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
...
...
DHParser/dsl.py
View file @
9bf2aea1
...
...
@@ -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)
...
...
DHParser/server.py
View file @
9bf2aea1
...
...
@@ -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
...
...
examples/ArithmeticSimple/ArithmeticSimpleCompiler.py
View file @
9bf2aea1
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment