GeezerVison is showing github.com — Add: input · CrazyProger1/FastPy@c2bffc0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: config/builtin.json +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "builtin_functions": { | 3 | 3 | "import": "import", | 4 | | - "log": "log" | | 4 | + "log": "log", | | 5 | + "log_error": "log_error", | | 6 | + "log_warning": "log_waring", | | 7 | + "log_info": "log_info", | | 8 | + "input": "input" | 5 | 9 | }, | 6 | 10 | "builtin_types": { | 7 | 11 | "string": "str", | |
Collapse file Copy file name to clipboardExpand all lines: config/parser.json +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 42 | 42 | "possible_node_classes": [ | 43 | 43 | "fastpy.parser.nodes.ValueNode", | 44 | 44 | "fastpy.parser.nodes.VariableNode", | 45 | | - "fastpy.parser.nodes.BinOpNode" | | 45 | + "fastpy.parser.nodes.BinOpNode", | | 46 | + "fastpy.parser.nodes.CallNode" | 46 | 47 | ], | 47 | 48 | "tokens_slice": { | 48 | 49 | "start_index": 4 | | 298 | 299 | "condition": { | 299 | 300 | "parser_class": "fastpy.parser.node_parsers.ConditionParser", | 300 | 301 | "possible_node_classes": [ | 301 | | - "fastpy.parser.nodes.LogicOpNode" | | 302 | + "fastpy.parser.nodes.LogicOpNode", | | 303 | + "fastpy.parser.nodes.BinOpNode" | 302 | 304 | ], | 303 | 305 | "tokens_slice": { | 304 | 306 | "start_index": 1 | | 309 | 311 | ] | 310 | 312 | }, | 311 | 313 | "LogicOpNode": { | 312 | | - "parser_class": "fastpy.parser.node_parsers.BinOpNodeParser", | | 314 | + "parser_class": "fastpy.parser.node_parsers.OperationNodeParser", | 313 | 315 | "node_class": "fastpy.parser.nodes.LogicOpNode", | 314 | 316 | "cases": [ | 315 | 317 | { | | 321 | 323 | ] | 322 | 324 | }, | 323 | 325 | "BinOpNode": { | 324 | | - "parser_class": "fastpy.parser.node_parsers.BinOpNodeParser", | | 326 | + "parser_class": "fastpy.parser.node_parsers.OperationNodeParser", | 325 | 327 | "node_class": "fastpy.parser.nodes.BinOpNode", | 326 | 328 | "cases": [ | 327 | 329 | { | |
Collapse file Copy file name to clipboardExpand all lines: cpp_code/libs/builtin.hpp +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,3 +44,15 @@ void log_warning(const T &t, bool endl = false) { | 44 | 44 | std::cout << termcolor::on_yellow << termcolor::grey; | 45 | 45 | log(t, endl); | 46 | 46 | } | | 47 | + | | 48 | +template<typename T> | | 49 | +T input(const str &t) { | | 50 | + if (!t.empty()) { | | 51 | + log(t); | | 52 | + } | | 53 | + | | 54 | + T inp; | | 55 | + | | 56 | + std::cin >> inp; | | 57 | + return inp; | | 58 | +} |
Collapse file Copy file name to clipboardExpand all lines: fastpy/parser/node_parsers.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -113,7 +113,7 @@ def parse(self, | 113 | 113 |
| 114 | 114 |
| 115 | 115 | @singleton | 116 | | -class BinOpNodeParser(BaseNodeParser): | | 116 | +class OperationNodeParser(BaseNodeParser): | 117 | 117 | parses = (BinOpNode, LogicOpNode) | 118 | 118 |
| 119 | 119 | def validate(self, | @@ -294,7 +294,7 @@ def parse(self, | 294 | 294 | expr_tokens.clear() | 295 | 295 | continue | 296 | 296 | elif token.type == TokenTypes.end_parenthesis: | 297 | | - if BinOpNodeParser().validate(expr_tokens, BinOpNode): | | 297 | + if OperationNodeParser().validate(expr_tokens, BinOpNode): | 298 | 298 | try: | 299 | 299 | node = parse_node_clb(expr_tokens) | 300 | 300 | except ParsingError: | @@ -323,6 +323,6 @@ def parse(self, | 323 | 323 | **extra_data) -> BaseNode | list[BaseNode]: | 324 | 324 | return parse_node_clb( | 325 | 325 | tokens[0:-1], | 326 | | - (LogicOpNode,), | 327 | | - BinOpNodeParser() | | 326 | + (LogicOpNode, BinOpNode), | | 327 | + OperationNodeParser() | 328 | 328 | ) |
Collapse file Copy file name to clipboardExpand all lines: fastpy/parser/nodes.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,11 +70,13 @@ def __init__(self, | 70 | 70 | identifier: BaseToken, | 71 | 71 | arguments: list[AssignNode] = None, | 72 | 72 | body: list[BaseNode] = None, | 73 | | - return_type: BaseToken = None): | | 73 | + return_type: BaseToken = None, | | 74 | + template: bool = False): | 74 | 75 | self.identifier = identifier | 75 | 76 | self.arguments = arguments or [] | 76 | 77 | self.body = body or [] | 77 | 78 | self.return_type = return_type | | 79 | + self.template = template | 78 | 80 |
| 79 | 81 | @property | 80 | 82 | def line(self) -> int: | |
Collapse file Copy file name to clipboardExpand all lines: fastpy/transpiler/node_transpilers.py +21-3Lines changed: 21 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,10 +17,19 @@ def transpile(self, | 17 | 17 | class AssignNodeTranspiler(BaseNodeTranspiler): | 18 | 18 | def transpile(self, node: AssignNode, transpile_node_clb: callable, **kwargs) -> BaseCode: | 19 | 19 | code = Code() | | 20 | + value_node = node.value | | 21 | + value = '' | | 22 | + if value_node: | | 23 | + value = transpile_node_clb( | | 24 | + node=value_node, | | 25 | + **kwargs, | | 26 | + type=node.value_type.text if node.value_type else None | | 27 | + ).internal | | 28 | + | 20 | 29 | code.push_internal( | 21 | 30 | f'{node.value_type.text if node.value_type is not None else "auto"} ' | 22 | | - f'{node.identifier.text}{" = " if node.value else ""}' | 23 | | - f'{transpile_node_clb(node=node.value, **kwargs).internal if node.value else ""}', | | 31 | + f'{node.identifier.text}{" = " if value else ""}' | | 32 | + f'{value}', | 24 | 33 | **kwargs | 25 | 34 | ) | 26 | 35 |
| @@ -117,8 +126,17 @@ def transpile(self, | 117 | 126 | transpile_node_clb: callable, | 118 | 127 | **kwargs) -> BaseCode: | 119 | 128 | code = Code() | | 129 | + | | 130 | + cast_type = kwargs.get('type') | | 131 | + specify_type = False | | 132 | + | | 133 | + if node.identifier.text == BUILTIN_FUNCTIONS['input']: | | 134 | + specify_type = True | | 135 | + | 120 | 136 | code.push_internal( | 121 | | - f'{node.identifier.text}({self._transpile_arguments(node.arguments, transpile_node_clb)})', | | 137 | + f'{node.identifier.text}' | | 138 | + f'{("<" + cast_type + ">") if specify_type else ""}' | | 139 | + f'({self._transpile_arguments(node.arguments, transpile_node_clb)})', | 122 | 140 | **kwargs | 123 | 141 | ) | 124 | 142 | return code | |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: fastpy_build/src/include/builtin.hpp +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,3 +44,15 @@ void log_warning(const T &t, bool endl = false) { | 44 | 44 | std::cout << termcolor::on_yellow << termcolor::grey; | 45 | 45 | log(t, endl); | 46 | 46 | } | | 47 | + | | 48 | +template<typename T> | | 49 | +T input(const str &t) { | | 50 | + if (!t.empty()) { | | 51 | + log(t); | | 52 | + } | | 53 | + | | 54 | + T inp; | | 55 | + | | 56 | + std::cin >> inp; | | 57 | + return inp; | | 58 | +} |
Collapse file Copy file name to clipboardExpand all lines: fastpy_build/src/main.cpp +15-3Lines changed: 15 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 |
| 16 | 16 | int main(){ | 17 | | - auto a = 1 + 1 - 1 * 1; | | 17 | + str d = input<str>("hello>"); | 18 | 18 |
| | 19 | + log(d); | 19 | 20 |
| 20 | | -if (a) { | 21 | | -log("hello"); | | 21 | +auto a = 123123; | | 22 | + | | 23 | + | | 24 | +auto b = 123412; | | 25 | + | | 26 | + | | 27 | +auto c = a + b; | | 28 | + | | 29 | + | | 30 | +log(c, true); | | 31 | + | | 32 | +if (c - 246535) { | | 33 | +log("hello, world!"); | 22 | 34 |
| 23 | 35 | } | 24 | 36 |
| |
Collapse file Copy file name to clipboardExpand all lines: main.fpy +19-3Lines changed: 19 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | # print_text(world_text) | 17 | 17 | # | 18 | 18 | #print('First FastPy run from IDE!!!!!!') # imported print function from print lib | 19 | | -a = 1 + 1 - 1 * 1 | | 19 | +#a = 1 - 1 * 1 | | 20 | +# | | 21 | +#if a: | | 22 | +# log('hello') | | 23 | + | | 24 | +#a = 10 | | 25 | +# | | 26 | +#if true and (1 + 1 * a): | | 27 | +# log('hello') | | 28 | + | | 29 | +d: int = input('hello>') | | 30 | + | | 31 | +a = 123123 | | 32 | +b = 123412 | | 33 | + | | 34 | +c = a + b | | 35 | +log(c, true) | 20 | 36 |
| 21 | | -if a: | 22 | | - log('hello') | | 37 | +if c - 246535: | | 38 | + log('hello, world!') |
|