From 83afcdc5b85702850ed051b64b44148b8d6702da Mon Sep 17 00:00:00 2001 From: TechStudent11 Date: Wed, 29 Sep 2021 17:51:46 -0400 Subject: [PATCH] added more easier way to add internal functions, among other things --- .gitignore | 5 +- orange/_parser.py | 31 ++++++++----- orange/comments.py | 49 ++++++++++++++++++++ orange/constants.py | 7 +-- orange/internal_functions/print.py | 4 +- orange/keywords.py | 5 ++ pyinstaller.json | 73 ++++++++++++++++++++++++++++++ test.or | 2 +- 8 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 orange/comments.py create mode 100644 orange/keywords.py create mode 100644 pyinstaller.json diff --git a/.gitignore b/.gitignore index 09bf5d6..0134269 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.pyc -__pycache__/ \ No newline at end of file +__pycache__/ +output/ +pyinstaller_beta.json +venv/ \ No newline at end of file diff --git a/orange/_parser.py b/orange/_parser.py index fd701e9..3f10ac0 100644 --- a/orange/_parser.py +++ b/orange/_parser.py @@ -1,10 +1,8 @@ -from . import constants - from .internal_functions._get_value import get_value - -functions = constants.KEYWORDS +from .keywords import KEYWORDS variables = {} +functions = {} def parse(code): code_lines = code.split('\n') @@ -14,19 +12,30 @@ def parse(code): if line == '': continue line_split = line.split(':') - # print(line_split) name = line_split[0] + if name.startswith('#'): + continue + del line_split[0] val_not_convert = ':'.join(line_split) + args = val_not_convert.split(',') + new_args = [] + for arg in args: + if arg.startswith(' '): + arg = arg[1:] + + new_arg = get_value(arg, variables=variables, line_number=line_number) + new_args.append(new_arg) + + if val_not_convert.startswith(' '): val_not_convert = val_not_convert[1:] - value = get_value(val_not_convert, line_number=line_number + 1, variables=variables) - # print("val", value) - if name in constants.KEYWORDS: + + val_not_convert = ',' + val_not_convert + if name in KEYWORDS: if name.startswith(' '): name = name[1:] - if name == 'print': - functions['print'](value) + KEYWORDS[name](new_args) else: - variables[name] = value + variables[name] = ' '.join(new_args) diff --git a/orange/comments.py b/orange/comments.py new file mode 100644 index 0000000..6aae060 --- /dev/null +++ b/orange/comments.py @@ -0,0 +1,49 @@ +# print(new_args) +# print(name) +# print(value) +# if name == 'function': +# function = {} +# function_name = val_not_convert.split(',')[0] +# function_lines = [] +# current_num = line_number + 1 +# current_space_count = 0 +# while 1: +# function_line = code_lines[current_num] +# print('func line:', function_line) +# if len(function_lines) == 0: +# print('no function lines') +# space_count = 0 +# print('no space count') +# for char in function_line: +# if char == ' ': +# print('char is a space character') +# space_count += 1 +# elif char == ' ': +# print('char is a tab character') +# space_count += 4 + +# current_space_count = space_count +# print('current space_count:', current_space_count) + +# if function_line.startswith(' '*current_space_count): +# print('function line starts with space with space count') +# function_lines.append(function_line.strip(' '*current_space_count)) +# elif function_line.startswith("}"): +# print('function lines end') +# break + +# function['name'] = function_name +# function['lines'] = function_lines +# print(function) +# functions[function_name] = function +# print(val_not_convert) +# value = get_value(val_not_convert, line_number=line_number + 1, variables=variables) +# print("val", value) + +# if name=="blah": print(new_args) +# print(line_split) +# function: functionName, ( name, another ) { +# print: name +# } +# execute: "functionName", "another" +# from .internal_functions import print diff --git a/orange/constants.py b/orange/constants.py index 5d72425..6961903 100644 --- a/orange/constants.py +++ b/orange/constants.py @@ -1,5 +1,6 @@ from .internal_functions import _print -KEYWORDS = { - 'print':_print, -} \ No newline at end of file +KEYWORDS = [ + 'print', + 'function' +] \ No newline at end of file diff --git a/orange/internal_functions/print.py b/orange/internal_functions/print.py index d1b110e..579ff0a 100644 --- a/orange/internal_functions/print.py +++ b/orange/internal_functions/print.py @@ -1,2 +1,2 @@ -def _print(*args, **kwargs): - print(*args, **kwargs) \ No newline at end of file +def _print(args): + print(' '.join(args)) \ No newline at end of file diff --git a/orange/keywords.py b/orange/keywords.py new file mode 100644 index 0000000..9cb0c4f --- /dev/null +++ b/orange/keywords.py @@ -0,0 +1,5 @@ +from .internal_functions.print import _print + +KEYWORDS = { + 'print': _print, +} diff --git a/pyinstaller.json b/pyinstaller.json new file mode 100644 index 0000000..22ad7eb --- /dev/null +++ b/pyinstaller.json @@ -0,0 +1,73 @@ +{ + "version": "auto-py-to-exe-configuration_v1", + "pyinstallerOptions": [ + { + "optionDest": "noconfirm", + "value": true + }, + { + "optionDest": "filenames", + "value": "P:/Orange/run.py" + }, + { + "optionDest": "onefile", + "value": true + }, + { + "optionDest": "console", + "value": true + }, + { + "optionDest": "name", + "value": "orange" + }, + { + "optionDest": "ascii", + "value": false + }, + { + "optionDest": "clean_build", + "value": false + }, + { + "optionDest": "strip", + "value": false + }, + { + "optionDest": "noupx", + "value": false + }, + { + "optionDest": "uac_admin", + "value": false + }, + { + "optionDest": "uac_uiaccess", + "value": false + }, + { + "optionDest": "win_private_assemblies", + "value": false + }, + { + "optionDest": "win_no_prefer_redirects", + "value": false + }, + { + "optionDest": "bootloader_ignore_signals", + "value": false + }, + { + "optionDest": "disable_windowed_traceback", + "value": false + }, + { + "optionDest": "datas", + "value": "P:/Orange/orange;orange/" + } + ], + "nonPyinstallerOptions": { + "increaseRecursionLimit": true, + "manualArguments": "" + } +} \ No newline at end of file diff --git a/test.or b/test.or index c305eb1..3646444 100644 --- a/test.or +++ b/test.or @@ -1,2 +1,2 @@ var1: "yep" -print: var1 \ No newline at end of file +print: var1