Skip to content

Commit 2b98e5a

Browse files
committed
---
yaml --- r: 8043 b: refs/heads/snap-stage3 c: 4d71285 h: refs/heads/master i: 8041: f68e8cd 8039: 9ce9533 v: v3
1 parent a6ecf30 commit 2b98e5a

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 1c91fb4d91623bd50901ca4f4f215c928790e996
4+
refs/heads/snap-stage3: 4d71285c933586f92497a5b5fb85368fd130f4e6
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/comp/syntax/ext/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn syntax_expander_table() -> hashmap<str, syntax_extension> {
3030
normal(ext::ident_to_str::expand_syntax_ext));
3131
syntax_expanders.insert("log_syntax",
3232
normal(ext::log_syntax::expand_syntax_ext));
33+
syntax_expanders.insert("ast",
34+
normal(ext::qquote::expand_ast));
3335
ret syntax_expanders;
3436
}
3537

branches/snap-stage3/src/comp/syntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
4747
}
4848
}
4949
mac_qq(sp, exp) {
50-
let r = expand_qquote(cx, sp, exp);
50+
let r = expand_qquote(cx, sp, none, exp);
5151
// need to keep going, resuls may contain embedded qquote or
5252
// macro that need expanding
5353
let r2 = fld.fold_expr(r);

branches/snap-stage3/src/comp/syntax/ext/qquote.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import syntax::fold::*;
88
import syntax::visit::*;
99
import syntax::ext::base::*;
1010
import syntax::ext::build::*;
11-
import syntax::parse::parser::parse_expr_from_source_str;
11+
import syntax::parse::parser;
12+
import syntax::parse::parser::{parse_from_source_str};
1213

1314
import syntax::print::*;
1415
import std::io::*;
@@ -42,8 +43,26 @@ fn is_space(c: char) -> bool {
4243
syntax::parse::lexer::is_whitespace(c)
4344
}
4445

45-
fn expand_qquote(ecx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
46-
let str = codemap::span_to_snippet(sp, ecx.session().parse_sess.cm);
46+
fn expand_ast(ecx: ext_ctxt, _sp: span, _arg: ast::mac_arg, body: ast::mac_body)
47+
-> @ast::expr
48+
{
49+
let body = get_mac_body(ecx,_sp,body);
50+
let str = @codemap::span_to_snippet(body.span, ecx.session().parse_sess.cm);
51+
let {node: e, _} = parse_from_source_str(parser::parse_expr,
52+
"<anon>", str,
53+
ecx.session().opts.cfg,
54+
ecx.session().parse_sess);
55+
ret expand_qquote(ecx, e.span, some(*str), e);
56+
}
57+
58+
fn expand_qquote(ecx: ext_ctxt, sp: span, maybe_str: option::t<str>,
59+
e: @ast::expr)
60+
-> @ast::expr
61+
{
62+
let str = alt(maybe_str) {
63+
some(s) {s}
64+
none {codemap::span_to_snippet(sp, ecx.session().parse_sess.cm)}
65+
};
4766
let qcx = gather_anti_quotes(sp.lo, e);
4867
let cx = qcx;
4968
let prev = 0u;

branches/snap-stage3/src/comp/syntax/parse/parser.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr {
10131013
}
10141014
p.bump();
10151015
}
1016-
let hi = p.last_span.hi;
1016+
let hi = p.last_span.lo;
10171017
b = some({span: mk_sp(lo,hi)});
10181018
}
10191019
ret mk_mac_expr(p, lo, p.span.hi, ast::mac_invoc(pth, e, b));
@@ -2543,6 +2543,18 @@ fn parse_expr_from_source_str(name: str, source: @str, cfg: ast::crate_cfg,
25432543
ret r;
25442544
}
25452545

2546+
fn parse_from_source_str<T>(f: fn (p: parser) -> T,
2547+
name: str, source: @str, cfg: ast::crate_cfg,
2548+
sess: parse_sess)
2549+
-> {node: T, fm: codemap::filemap}
2550+
{
2551+
let p = new_parser_from_source_str(sess, cfg, name, source);
2552+
let r = f(p);
2553+
sess.chpos = p.reader.chpos;
2554+
sess.byte_pos = sess.byte_pos + p.reader.pos;
2555+
ret {node: r, fm: option::get(vec::last(sess.cm.files))};
2556+
}
2557+
25462558
fn parse_crate_from_source_str(name: str, source: @str, cfg: ast::crate_cfg,
25472559
sess: parse_sess) -> @ast::crate {
25482560
let p = new_parser_from_source_str(sess, cfg, name, source);

0 commit comments

Comments
 (0)