aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/parser.rs
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-02-23 23:48:01 -0500
committerGraydon Hoare <[email protected]>2011-03-02 10:28:14 -0800
commit9528c34774ff27b112c9e66afff6e10fa7021635 (patch)
tree4d5f9bde4c48eed1a188f6002e88daa93f4ea28b /src/comp/front/parser.rs
parentRemove parens from nullary tag constructors in docs (diff)
downloadrust-9528c34774ff27b112c9e66afff6e10fa7021635.tar.xz
rust-9528c34774ff27b112c9e66afff6e10fa7021635.zip
Begin implementing #fmt in rustc
Diffstat (limited to 'src/comp/front/parser.rs')
-rw-r--r--src/comp/front/parser.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index f747c084..8f6db17d 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -656,7 +656,10 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
some(token.COMMA),
pf, p);
hi = es.span;
- ex = ast.expr_ext(pth, es.node, none[@ast.expr], ast.ann_none);
+ ex = ast.expr_ext(pth, es.node, none[@ast.expr],
+ none[@ast.expr], ast.ann_none);
+ // FIXME: Here is probably not the right place for this
+ ex = expand_syntax_ext(p, @spanned(lo, hi, ex)).node;
}
case (token.FAIL) {
@@ -736,6 +739,36 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
ret @spanned(lo, hi, ex);
}
+/*
+ * FIXME: This is a crude approximation of the syntax-extension system,
+ * for purposes of prototyping and/or hard-wiring any extensions we
+ * wish to use while bootstrapping. The eventual aim is to permit
+ * loading rust crates to process extensions, but this will likely
+ * require a rust-based frontend, or an ocaml-FFI-based connection to
+ * rust crates. At the moment we have neither.
+ */
+
+impure fn expand_syntax_ext(parser p, @ast.expr ext) -> @ast.expr {
+ check (ast.is_ext_expr(ext));
+ alt (ext.node) {
+ case (ast.expr_ext(?path, ?args, ?body, _, ?ann)) {
+ check (_vec.len[ast.ident](path.node.idents) > 0u);
+ auto extname = path.node.idents.(0);
+ if (_str.eq(extname, "fmt")) {
+ auto expanded = extfmt.expand_syntax_ext(args, body);
+ check (ast.is_ext_expr(expanded));
+ auto newexpr = ast.expr_ext(path, args, body,
+ some[@ast.expr](expanded), ann);
+
+ ret @spanned(ext.span, ext.span, newexpr);
+ } else {
+ p.err("unknown syntax extension");
+ }
+ }
+ }
+ fail;
+}
+
impure fn extend_expr_by_ident(parser p, span lo, span hi,
@ast.expr e, ast.ident i) -> @ast.expr {
auto e_ = e.node;