Skip to content

Commit

Permalink
Allow range expression as general expressions (not only loops)
Browse files Browse the repository at this point in the history
  • Loading branch information
aisbergg committed Apr 22, 2022
1 parent f491f5e commit f6e93f5
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 158 deletions.
11 changes: 3 additions & 8 deletions expressions/expressions.y
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
loopmods loopModifiers
filter_params []valueFn
}
%type <f> expr rel filtered cond int_or_var loop_expr
%type<f> expr rel filtered cond int_or_var
%type<filter_params> filter_params
%type<exprs> exprs expr2
%type<cycle> cycle
Expand Down Expand Up @@ -84,18 +84,12 @@ string: LITERAL {
$$ = s
};

loop: IDENTIFIER IN loop_expr loop_modifiers {
loop: IDENTIFIER IN filtered loop_modifiers {
name, expr, mods := $1, $3, $4
$$ = Loop{name, &expression{expr}, mods}
}
;

loop_expr : '(' int_or_var DOTDOT int_or_var ')' {
$$ = makeRangeExpr($2, $4)
}
| filtered
;

// TODO DRY w/ expr
int_or_var:
LITERAL { val := $1; $$ = func(Context) values.Value { return values.ValueOf(val) } }
Expand Down Expand Up @@ -144,6 +138,7 @@ expr:
| IDENTIFIER { name := $1; $$ = func(ctx Context) values.Value { return values.ValueOf(ctx.Get(name)) } }
| expr PROPERTY { $$ = makeObjectPropertyExpr($1, $2) }
| expr '[' expr ']' { $$ = makeIndexExpr($1, $3) }
| '(' int_or_var DOTDOT int_or_var ')' { $$ = makeRangeExpr($2, $4) }
| '(' cond ')' { $$ = $2 }
;

Expand Down
Loading

0 comments on commit f6e93f5

Please sign in to comment.