diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-07-08 18:18:32 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-07-08 18:18:32 +0200 |
commit | d498fd2dae412054d028921f36ce42b8dfc46c0c (patch) | |
tree | fa5f25b4b8694ff0098e17cfdda212167086c2f4 | |
parent | a545cbab33e7ecc9ea36ad479fc32ec29a106e99 (diff) |
pipe
-rwxr-xr-x | henshin | 26 | ||||
-rw-r--r-- | test/test.test | 4 |
2 files changed, 24 insertions, 6 deletions
@@ -269,6 +269,11 @@ class AstNodeLoop(AstNode): self.value_id = value_id self.body = body +class AstNodePipe(AstNode): + def __init__(self, left, right): + self.left = left + self.right = right + precedence = ( @@ -318,8 +323,9 @@ def p_statement(p): '''statement : variable_declaration_statement | variable_reassignment_statement | function_declaration - | function_call + | function_call SEMICOLON | loop + | pipe SEMICOLON | return_statement''' p[0] = p[1] @@ -355,7 +361,7 @@ def p_function_declaration_parameter(p): def p_function_call(p): - '''function_call : IDENTIFIER PARENTHESIS_LEFT function_call_parameters PARENTHESIS_RIGHT SEMICOLON''' + '''function_call : IDENTIFIER PARENTHESIS_LEFT function_call_parameters PARENTHESIS_RIGHT''' p[0] = AstNodeFunctionCall(p[1], p[3]) @@ -366,7 +372,9 @@ def p_function_call_parameters(p): | function_call_parameter |''' - parameters = [p[1]] + parameters = [] + if len(p) == 2: + parameters.append(p[1]) if len(p) == 4: parameters.extend(p[3]) @@ -375,7 +383,8 @@ def p_function_call_parameters(p): def p_function_call_parameter(p): '''function_call_parameter : IDENTIFIER ASSIGN expression - | expression''' + | expression + | OPERATOR_PIPE_REPLACEMENT''' if len(p) == 4: p[0] = AstNodeFunctionCallParameter(p[1], p[3]) @@ -393,6 +402,15 @@ def p_loop(p): +def p_pipe(p): + '''pipe : expression OPERATOR_PIPE pipe + | expression OPERATOR_PIPE function_call''' + + p[0] = AstNodePipe(p[1], p[3]) + + + + def p_variable_declaration_statement(p): '''variable_declaration_statement : variable_declarator IDENTIFIER COLON variable_type ASSIGN expression SEMICOLON''' diff --git a/test/test.test b/test/test.test index 24059ca..e39eae6 100644 --- a/test/test.test +++ b/test/test.test @@ -32,5 +32,5 @@ for (map) |key, value| { ply = key; } -std.str.format('cool %s', string) - |> print($); +main() |> print($); +main() |> main2($) |> print($); |