aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs2
-rw-r--r--src/comp/front/parser.rs27
2 files changed, 28 insertions, 1 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 0b0f571c..34df06ad 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -76,7 +76,7 @@ tag stmt_ {
type decl = spanned[decl_];
tag decl_ {
- decl_local(ident, bool, option[@ty]);
+ decl_local(ident, option[@ty], option[@expr]);
decl_item(name, @item);
}
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 2571c5d7..877119de 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -541,6 +541,27 @@ io fn parse_expr(parser p) -> @ast.expr {
}
}
+io fn parse_let(parser p) -> @ast.decl {
+ auto lo = p.get_span();
+
+ expect(p, token.LET);
+ auto ty = parse_ty(p);
+ auto id = parse_ident(p);
+
+ auto init;
+ if (p.peek() == token.EQ) {
+ p.bump();
+ init = some(parse_expr(p));
+ } else {
+ init = none[@ast.expr];
+ }
+
+ expect(p, token.SEMI);
+
+ auto hi = p.get_span();
+ ret @spanned(lo, hi, ast.decl_local(id, some(ty), init));
+}
+
io fn parse_stmt(parser p) -> @ast.stmt {
auto lo = p.get_span();
alt (p.peek()) {
@@ -553,6 +574,12 @@ io fn parse_stmt(parser p) -> @ast.stmt {
ret @spanned(lo, hi, ast.stmt_log(e));
}
+ case (token.LET) {
+ auto leht = parse_let(p);
+ auto hi = p.get_span();
+ ret @spanned(lo, hi, ast.stmt_decl(leht));
+ }
+
// Handle the (few) block-expr stmts first.
case (token.IF) {