Adding Post-Processor

This commit is contained in:
Martin Karkowski 2022-07-23 07:34:58 +02:00
parent 4535821e8c
commit 976f2d06e5
2 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,7 @@ __copyright__ = 'Copyright 2022 M.Karkowski'
__version__ = '0.1.0'
from .logger import get_logger
from .post_processor import post_process
from .js import get_parser as get_parser_js, transform as transform_js
from .ts import get_parser as get_parser_ts, transform as transform_ts
from .main import main

View File

@ -0,0 +1,27 @@
replacers = {
"console.log": "print",
"console.error": "print",
"Error(": "Exception(",
"true": "True",
"false": "False",
"JSON.stringify": "json.dumps",
"JSON.parse": "json.loads"
}
def post_process(code: str) -> str:
""" Post processes the code. This results in adapting the code by replacing default
elements like console.log
Args:
code (str): The code that have to be adapted
Returns:
str: The adapted code
"""
for org, new in replacers.items():
code = code.replace(org, new)
return code