aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/parser.y b/src/parser.y
index ccff211..97a700e 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -69,7 +69,9 @@
%token RBRACE "}"
%token LBRACKET "["
%token RBRACKET "]"
-%token AS "as"
+%token IF "if"
+%token ELSE "else"
+%token MUT "mut"
%token DOT "."
%token SCOPE "::"
%token FATARROW "=>"
@@ -94,11 +96,12 @@
%nterm <node> vars exprs statements closures
%nterm <node> opt_vars opt_exprs opt_statements
%nterm <node> rev_vars rev_exprs rev_closures rev_statements
-%nterm <node> let unop binop construct
+%nterm <node> let if unop binop construct
%nterm <type> type rev_types types opt_types
+
%{
/** Modifies the signature of yylex to fit our parser better. */
@@ -176,7 +179,7 @@ static char *strip(const char *s);
%start input;
%%
var
- : ID { $$ = gen_var($1, src_loc(@$)); }
+ : type ID { $$ = gen_var($2, $1, src_loc(@$)); }
rev_vars
: rev_vars "," var { $$ = $3; $$->n = $1; }
@@ -219,6 +222,9 @@ type
| APPLY "[" opt_types "]" {
$$ = tgen_construct($[APPLY], $[opt_types], src_loc(@$));
}
+ | "(" opt_types ")" { $$ = tgen_callable($2, src_loc(@$)); }
+ | "&" type { $$ = tgen_ref($2, src_loc(@$)); }
+ | "*" type { $$ = tgen_ptr($2, src_loc(@$)); }
rev_types
: rev_types "," type { $$ = $3; $3->n = $$; }
@@ -290,11 +296,17 @@ call
}
let
- : expr "=>" ID ";" { $$ = gen_let($3, $1, src_loc(@$)); }
+ : expr "=>" var ";" { $$ = gen_let($3, $1, src_loc(@$)); }
+
+if
+ : "if" expr body { $$ = gen_if($2, $3, NULL, src_loc(@$)); }
+ | "if" expr body "else" body { $$ = gen_if($2, $3, $5, src_loc(@$)); }
+ | "if" expr body "else" if { $$ = gen_if($2, $3, $5, src_loc(@$)); }
statement
: call
| let
+ | if
| ";" { $$ = gen_empty(src_loc(@$)); }
rev_statements
@@ -419,14 +431,8 @@ static char *strip(const char *str)
/* skip quotation marks */
size_t j = 0;
- for (size_t i = 1; i < len - 2; ++i) {
- char c = str[i];
-
- if (c == '\\')
- c = match_escape(str[++i]);
-
- buf[j++] = c;
- }
+ for (size_t i = 1; i < len - 2; ++i)
+ buf[j++] = str[i];
buf[j] = 0;
free((void *)str);