Lexer is in src/core/lexer.py.
parse_op: Parses one operationArgs:
op_str(str): The command as stringfile_path(str): Which file this line is loaded fromline_number(int): Which line number this code loaded fromreturns a dict. Strructure:
{
"command": "<the command>",
"args_str": "arguments of command as string",
"str": "all of command as string",
"args": ["arguments", "as", "list"], // seprated by ` ` space
"file_path": "/path/to/file/that/this/line/loaded/from",
"strings": ["<output of `parse_string`>"],
"line_number": 12
}
Example:
print(lexer.parse_op("println('hello world')", "/path/to/file/that/this/line/loaded/from", 12))
# OR: `println 'hello world'`
output:
{
"command": "println",
"args_str": "('hello world')",
"str": "println('hello world')",
"args": ["('hello", "world')"], // seprated by ` ` space
"file_path": "/path/to/file/that/this/line/loaded/from",
"strings": ["<output of `parse_string`>"],
"line_number": 12
}
parse_string: Splits strings and codesArgs:
command(str): That thing you want to parseReturns a list from other lists:
[
[false, "println("],
[true, "'hello world'"],
[false, ")"],
]
(the above output is for println('hello world')).
The first boolean item, if is True, means that this part is a string,
But if is False, means this is a native code.
And the second item is the code as string.
This function is useful when you want to replace/etc something on a code, But only in native code and not on strings.
parse_eval: Converts the Pashmak eval code Python codeArgs:
command(str): The commandReturns a string from generated python code.
Example:
$name + '.' -> [['v', 'name', 'self.get_var("name")'], ['l', '.'], ['s', "'.'"]]some_func($i + 1) -> []output = lexer.parse_eval('$name + "."')
py_code = ''
for item in output:
py_code += item[-1]
eval(py_code)
multi_char_split: Splits by more than 1 characterExample:
print(lexer.multi_char_split('12+19*14', '+*'))
output:
['12', '19', '14']
Also you can give the count:
print(lexer.multi_char_split('12+19*14', '+*'), 1)
output:
['12', '19*14']
Parser is in src/core/parser.py.
parse: Parses a codeThis is The main parser function.
Args:
content(str): The code you want to parsefilepath(str): The file path you loaded file fromonly_parse(bool): if is True, do not parses if statement(default is False)Returns a list:
[
{<output of lexer.parse_op>},
{<output of lexer.parse_op>},
{<output of lexer.parse_op>},
...
]
Handles multiline and if statements.
split_by_equals: Splits <something> = <something> syntaxArgs:
string(str): The commandReturns a list.
Example for $name = 'pashmak': [‘$name’, “‘pashmak’”]
Example for println($name): [‘println($name)’]
If output is a list with 1 item, means this is a not <a> = <b>.
But if yes, first item is <a>(before =) and second it after =.
Other example:
print(parser.split_by_equals('$age = 30'))
output:
["$age", "30"]
Also:
print(parser.split_by_equals('somefunc()'))
output:
["somefunc()"]