summaryrefslogtreecommitdiffstats
path: root/src/parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/parser.y b/src/parser.y
index a37d217f..c011ae26 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -83,6 +83,7 @@ struct lexer_param;
%token SETDEFINEDOR "//="
%token LESSEQ "<="
%token GREATEREQ ">="
+%token ALTERNATION "?//"
%token QQSTRING_START
%token <literal> QQSTRING_TEXT
@@ -118,7 +119,7 @@ struct lexer_param;
%type <blk> FuncDef FuncDefs
%type <blk> Module Import Imports ImportWhat ImportFrom
%type <blk> Param Params Arg Args
-%type <blk> Pattern ArrayPats ObjPats ObjPat
+%type <blk> Patterns RepPatterns Pattern ArrayPats ObjPats ObjPat
%type <literal> Keyword
%{
#include "lexer.h"
@@ -176,10 +177,6 @@ static jv check_object_key(block k) {
return jv_invalid();
}
-static block gen_dictpair(block k, block v) {
- return BLOCK(gen_subexp(k), gen_subexp(v), gen_op_simple(INSERT));
-}
-
static block gen_index(block obj, block key) {
return BLOCK(gen_subexp(key), obj, gen_op_simple(INDEX));
}
@@ -342,19 +339,18 @@ FuncDef Exp %prec FUNCDEF {
$$ = block_bind_referenced($1, $2, OP_IS_CALL_PSEUDO);
} |
-Term "as" Pattern '|' Exp {
+Term "as" Patterns '|' Exp {
$$ = gen_destructure($1, $3, $5);
} |
-
-"reduce" Term "as" Pattern '(' Exp ';' Exp ')' {
+"reduce" Term "as" Patterns '(' Exp ';' Exp ')' {
$$ = gen_reduce($2, $4, $6, $8);
} |
-"foreach" Term "as" Pattern '(' Exp ';' Exp ';' Exp ')' {
+"foreach" Term "as" Patterns '(' Exp ';' Exp ';' Exp ')' {
$$ = gen_foreach($2, $4, $6, $8, $10);
} |
-"foreach" Term "as" Pattern '(' Exp ';' Exp ')' {
+"foreach" Term "as" Patterns '(' Exp ';' Exp ')' {
$$ = gen_foreach($2, $4, $6, $8, gen_noop());
} |
@@ -778,6 +774,22 @@ Exp {
$$ = gen_lambda($1);
}
+RepPatterns:
+RepPatterns "?//" Pattern {
+ $$ = BLOCK($1, gen_destructure_alt($3));
+} |
+Pattern {
+ $$ = gen_destructure_alt($1);
+}
+
+Patterns:
+RepPatterns "?//" Pattern {
+ $$ = BLOCK($1, $3);
+} |
+Pattern {
+ $$ = $1;
+}
+
Pattern:
'$' IDENT {
$$ = gen_op_unbound(STOREV, jv_string_value($2));