Skip to content

Commit 48e8077

Browse files
committed
---
yaml --- r: 8031 b: refs/heads/snap-stage3 c: 5ef5338 h: refs/heads/master i: 8029: 7437bf3 8027: f116a8d 8023: 499203c 8015: 38d4e66 7999: 80cca77 v: v3
1 parent 2c50ce2 commit 48e8077

File tree

11 files changed

+75
-3
lines changed

11 files changed

+75
-3
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: 75edd9ff69625292b1c4d5f05502d1fd28b39f55
4+
refs/heads/snap-stage3: 5ef53382aeac2de7e6dcc43c156312d2e68c15e4
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/comp/syntax/ast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ enum mac_ {
277277
mac_embed_type(@ty),
278278
mac_embed_block(blk),
279279
mac_ellipsis,
280+
// the span is used by the quoter/anti-quoter ...
281+
mac_qq(span /* span of expr */, @expr), // quasi-quote
282+
mac_aq(span /* span of quote */, @expr), // anti-quote
283+
mac_var(uint),
280284
}
281285

282286
type lit = spanned<lit_>;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import option::{none, some};
55
import std::map::hashmap;
66
import vec;
77

8-
import syntax::ast::{crate, expr_, expr_mac, mac_invoc};
8+
import syntax::ast::{crate, expr_, expr_mac, mac_invoc, mac_qq};
99
import syntax::fold::*;
1010
import syntax::ext::base::*;
1111
import syntax::parse::parser::parse_expr_from_source_str;
@@ -45,13 +45,21 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
4545
}
4646
}
4747
}
48+
mac_qq(sp, exp) { (expand_qquote(cx, sp, exp), s) }
4849
_ { cx.span_bug(mac.span, "naked syntactic bit") }
4950
}
5051
}
5152
_ { orig(e, s, fld) }
5253
};
5354
}
5455

56+
fn expand_qquote(cx: ext_ctxt, sp: span, e: @ast::expr) -> ast::expr_ {
57+
import syntax::ext::build::*;
58+
let str = codemap::span_to_snippet(sp, cx.session().parse_sess.cm);
59+
let expr = make_new_str(cx, e.span, str);
60+
ret expr.node;
61+
}
62+
5563
// FIXME: this is a terrible kludge to inject some macros into the default
5664
// compilation environment. When the macro-definition system is substantially
5765
// more mature, these should move from here, into a compiled part of libcore

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) {
587587
none { no_des(cx, blk.span, "under `#{}`"); }
588588
}
589589
}
590+
ast::mac_qq(_,_) { no_des(cx, mac.span, "quasiquotes"); }
591+
ast::mac_aq(_,_) { no_des(cx, mac.span, "antiquotes"); }
592+
ast::mac_var(_) { no_des(cx, mac.span, "antiquote variables"); }
590593
}
591594
}
592595

branches/snap-stage3/src/comp/syntax/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
138138
mac_embed_type(ty) { mac_embed_type(fld.fold_ty(ty)) }
139139
mac_embed_block(blk) { mac_embed_block(fld.fold_block(blk)) }
140140
mac_ellipsis { mac_ellipsis }
141+
mac_qq(_,_) { /* fixme */ m.node }
142+
mac_aq(_,_) { /* fixme */ m.node }
143+
mac_var(_) { /* fixme */ m.node }
141144
},
142145
span: m.span};
143146
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ fn next_token_inner(rdr: reader) -> token::token {
349349
'#' {
350350
rdr.bump();
351351
if rdr.curr == '<' { rdr.bump(); ret token::POUND_LT; }
352+
if rdr.curr == '(' { rdr.bump(); ret token::POUND_LPAREN; }
352353
if rdr.curr == '{' { rdr.bump(); ret token::POUND_LBRACE; }
353354
ret token::POUND;
354355
}
@@ -361,6 +362,23 @@ fn next_token_inner(rdr: reader) -> token::token {
361362
} else { ret token::COLON; }
362363
}
363364

365+
'$' {
366+
rdr.bump();
367+
if is_dec_digit(rdr.curr) {
368+
let val = dec_digit_val(rdr.curr) as uint;
369+
while is_dec_digit(rdr.next()) {
370+
rdr.bump();
371+
val = val * 10u + (dec_digit_val(rdr.curr) as uint);
372+
}
373+
rdr.bump();
374+
ret token::DOLLAR_NUM(val);
375+
} else if c == '(' {
376+
ret token::DOLLAR_LPAREN;
377+
} else {
378+
rdr.fatal("expected digit3");
379+
}
380+
}
381+
364382

365383

366384

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ fn parse_seq<T: copy>(bra: token::token, ket: token::token,
628628
ret spanned(lo, hi, result);
629629
}
630630

631+
fn have_dollar(p: parser) -> option::t<ast::mac_> {
632+
alt p.token {
633+
token::DOLLAR_NUM(num) {p.bump(); some(ast::mac_var(num))}
634+
_ {none}
635+
}
636+
}
637+
631638
fn lit_from_token(p: parser, tok: token::token) -> ast::lit_ {
632639
alt tok {
633640
token::LIT_INT(i, it) { ast::lit_int(i, it) }
@@ -755,6 +762,12 @@ fn parse_bottom_expr(p: parser) -> pexpr {
755762
let hi = p.span.hi;
756763

757764
let ex: ast::expr_;
765+
766+
alt have_dollar(p) {
767+
some(x) {ret pexpr(mk_mac_expr(p, lo, p.span.hi, x));}
768+
_ {}
769+
}
770+
758771
if p.token == token::LPAREN {
759772
p.bump();
760773
if p.token == token::RPAREN {
@@ -843,6 +856,12 @@ fn parse_bottom_expr(p: parser) -> pexpr {
843856
} else if p.token == token::ELLIPSIS {
844857
p.bump();
845858
ret pexpr(mk_mac_expr(p, lo, p.span.hi, ast::mac_ellipsis));
859+
} else if p.token == token::POUND_LPAREN {
860+
p.bump();
861+
let e = parse_expr(p);
862+
expect(p, token::RPAREN);
863+
ret pexpr(mk_mac_expr(p, lo, p.span.hi,
864+
ast::mac_qq(e.span, e)));
846865
} else if eat_word(p, "bind") {
847866
let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
848867
fn parse_expr_opt(p: parser) -> option<@ast::expr> {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ enum token {
5353
LBRACE,
5454
RBRACE,
5555
POUND,
56+
POUND_LPAREN,
5657
POUND_LBRACE,
5758
POUND_LT,
5859

60+
DOLLAR_LPAREN,
61+
DOLLAR_NUM(uint),
62+
5963
/* Literals */
6064
LIT_INT(i64, ast::int_ty),
6165
LIT_UINT(u64, ast::uint_ty),
@@ -69,6 +73,7 @@ enum token {
6973
UNDERSCORE,
7074
BRACEQUOTE(str_num),
7175
EOF,
76+
7277
}
7378

7479
fn binop_to_str(o: binop) -> str {
@@ -123,9 +128,15 @@ fn to_str(r: reader, t: token) -> str {
123128
LBRACE { ret "{"; }
124129
RBRACE { ret "}"; }
125130
POUND { ret "#"; }
131+
POUND_LPAREN { ret "#("; }
126132
POUND_LBRACE { ret "#{"; }
127133
POUND_LT { ret "#<"; }
128134

135+
DOLLAR_LPAREN { ret "$("; }
136+
DOLLAR_NUM(u) {
137+
ret "$" + uint::to_str(u as uint, 10u);
138+
}
139+
129140
/* Literals */
130141
LIT_INT(c, ast::ty_char) {
131142
// FIXME: escape.

branches/snap-stage3/src/comp/syntax/print/pprust.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ fn print_mac(s: ps, m: ast::mac) {
739739
print_possibly_embedded_block(s, blk, block_normal, indent_unit);
740740
}
741741
ast::mac_ellipsis { word(s.s, "..."); }
742+
ast::mac_var(v) { word(s.s, #fmt("$%u", v)); }
743+
_ { /* fixme */ }
742744
}
743745
}
744746

branches/snap-stage3/src/comp/syntax/visit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
277277
ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); }
278278
ast::mac_embed_block(blk) { v.visit_block(blk, e, v); }
279279
ast::mac_ellipsis { }
280+
ast::mac_qq(_, e) { /* FIXME: maybe visit */ }
281+
ast::mac_aq(_, e) { /* FIXME: maybe visit */ }
282+
ast::mac_var(_) { }
280283
}
281284
}
282285

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
// xfail-test
12
// error-pattern:expected a syntax expander name
23

34
fn main() {
45
#();
5-
}
6+
}

0 commit comments

Comments
 (0)