summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-07-08 16:23:17 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-07-08 16:23:17 +0200
commita545cbab33e7ecc9ea36ad479fc32ec29a106e99 (patch)
tree3a51470ae6de84db2cde35ed6a2c78ee13ef4398
parentb858cc223a936a522bb5f88065f6686489841955 (diff)
loop
-rwxr-xr-xhenshin20
-rw-r--r--test/test.test11
2 files changed, 31 insertions, 0 deletions
diff --git a/henshin b/henshin
index d8a1de8..d393f23 100755
--- a/henshin
+++ b/henshin
@@ -57,6 +57,8 @@ reserved = {
"and": "AND",
"or": "OR",
+
+ "for": "LOOP",
}
tokens = [
@@ -76,6 +78,7 @@ tokens = [
"BRACE_RIGHT",
"BRACKET_LEFT",
"BRACKET_RIGHT",
+ "PIPE",
"NAMESPACE_ACCESSOR",
@@ -110,6 +113,7 @@ t_BRACKET_LEFT = r'\['
t_BRACKET_RIGHT = r'\]'
t_BRACE_LEFT = r'{'
t_BRACE_RIGHT = r'}'
+t_PIPE = r'\|'
t_NAMESPACE_ACCESSOR = r'\.'
@@ -258,6 +262,13 @@ class AstNodeFunctionCallParameter(AstNode):
self.name = name
self.value = value
+class AstNodeLoop(AstNode):
+ def __init__(self, iteratee, key_id, value_id, body):
+ self.iteratee = iteratee
+ self.key_id = key_id
+ self.value_id = value_id
+ self.body = body
+
precedence = (
@@ -308,6 +319,7 @@ def p_statement(p):
| variable_reassignment_statement
| function_declaration
| function_call
+ | loop
| return_statement'''
p[0] = p[1]
@@ -373,6 +385,14 @@ def p_function_call_parameter(p):
+def p_loop(p):
+ '''loop : LOOP PARENTHESIS_LEFT expression PARENTHESIS_RIGHT PIPE identifier COMMA identifier PIPE BRACE_LEFT statements BRACE_RIGHT'''
+
+ p[0] = AstNodeLoop(p[3], p[6], p[8], p[11])
+
+
+
+
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 af1bf76..24059ca 100644
--- a/test/test.test
+++ b/test/test.test
@@ -23,3 +23,14 @@ const map: [string][string or integer] = [
"third": "3",
"fourth": 4,
];
+
+for (array) |index, value| {
+ ply = value;
+}
+
+for (map) |key, value| {
+ ply = key;
+}
+
+std.str.format('cool %s', string)
+ |> print($);