From 25c4676dfa805e027564116b9c37fee7aeaf1cc4 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 4 Feb 2013 13:15:17 -0800 Subject: Commenting, test cases, cleanup --- src/libsyntax/ext/base.rs | 12 +++++++----- src/libsyntax/ext/tt/transcribe.rs | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 8c3db21f4ea..a85a7990ace 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -44,8 +44,8 @@ pub struct SyntaxExpanderTT { span: Option } -pub type SyntaxExpanderTTFun = fn@(ext_ctxt, span, ~[ast::token_tree]) - -> MacResult; +pub type SyntaxExpanderTTFun + = fn@(ext_ctxt, span, ~[ast::token_tree]) -> MacResult; pub struct SyntaxExpanderTTItem { expander: SyntaxExpanderTTItemFun, @@ -59,7 +59,7 @@ pub enum MacResult { MRExpr(@ast::expr), MRItem(@ast::item), MRAny(fn@()-> @ast::expr, fn@()-> Option<@ast::item>, fn@()->@ast::stmt), - MRDef(MacroDef) + MRDef(MacroDef), } pub enum SyntaxExtension { @@ -78,9 +78,11 @@ pub enum SyntaxExtension { // A temporary hard-coded map of methods for expanding syntax extension // AST nodes into full ASTs pub fn syntax_expander_table() -> HashMap<~str, SyntaxExtension> { + // utility function to simplify creating NormalTT syntax extensions fn builtin_normal_tt(f: SyntaxExpanderTTFun) -> SyntaxExtension { NormalTT(SyntaxExpanderTT{expander: f, span: None}) } + // utility function to simplify creating ItemTT syntax extensions fn builtin_item_tt(f: SyntaxExpanderTTItemFun) -> SyntaxExtension { ItemTT(SyntaxExpanderTTItem{expander: f, span: None}) } @@ -112,8 +114,8 @@ pub fn syntax_expander_table() -> HashMap<~str, SyntaxExtension> { ext::deriving::expand_deriving_iter_bytes)); // Quasi-quoting expanders - syntax_expanders.insert( - ~"quote_tokens", builtin_normal_tt(ext::quote::expand_quote_tokens)); + syntax_expanders.insert(~"quote_tokens", + builtin_normal_tt(ext::quote::expand_quote_tokens)); syntax_expanders.insert(~"quote_expr", builtin_normal_tt(ext::quote::expand_quote_expr)); syntax_expanders.insert(~"quote_ty", diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index aa9036d295e..75120e9c0bc 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -121,15 +121,15 @@ pure fn lookup_cur_matched_by_matched(r: @mut TtReader, vec::foldl(start, r.repeat_idx, red) } -fn lookup_cur_matched(r: @mut TtReader, name: ident) -> @named_match { +fn lookup_cur_matched(r: &TtReader, name: ident) -> @named_match { lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) } -fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { - fn lis_merge(lhs: lis, rhs: lis, r: @mut TtReader) -> lis { +fn lockstep_iter_size(t: token_tree, r: &TtReader) -> lis { + fn lis_merge(lhs: lis, rhs: lis, r: &TtReader) -> lis { match lhs { lis_unconstrained => rhs, lis_contradiction(_) => lhs, -- cgit 1.4.1-3-g733a5 From 17d3a55362eb6a0b900d1d828e90d583897fa3b1 Mon Sep 17 00:00:00 2001 From: John Clements Date: Sat, 9 Feb 2013 13:25:47 -0800 Subject: @mut fix --- src/libsyntax/ext/tt/transcribe.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 75120e9c0bc..aa9036d295e 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -121,15 +121,15 @@ pure fn lookup_cur_matched_by_matched(r: @mut TtReader, vec::foldl(start, r.repeat_idx, red) } -fn lookup_cur_matched(r: &TtReader, name: ident) -> @named_match { +fn lookup_cur_matched(r: @mut TtReader, name: ident) -> @named_match { lookup_cur_matched_by_matched(r, r.interpolations.get(&name)) } enum lis { lis_unconstrained, lis_constraint(uint, ident), lis_contradiction(~str) } -fn lockstep_iter_size(t: token_tree, r: &TtReader) -> lis { - fn lis_merge(lhs: lis, rhs: lis, r: &TtReader) -> lis { +fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { + fn lis_merge(lhs: lis, rhs: lis, r: @mut TtReader) -> lis { match lhs { lis_unconstrained => rhs, lis_contradiction(_) => lhs, -- cgit 1.4.1-3-g733a5 From f9d789fa083220cc9d84cbea94868606600c64a9 Mon Sep 17 00:00:00 2001 From: John Clements Date: Wed, 13 Feb 2013 15:38:42 -0800 Subject: cleanup, fix test case --- src/libcore/dvec.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/parse/common.rs | 1 - src/libsyntax/parse/mod.rs | 13 +++++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index c7a0300a978..fe36ed15960 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -229,7 +229,7 @@ impl DVec { impl DVec { /** - * Append all elements of a vector to the end of the list. + * Append all elements of a vector to the end of the list * * Equivalent to `append_iter()` but potentially more efficient. */ diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a85a7990ace..c924acd577d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -59,7 +59,7 @@ pub enum MacResult { MRExpr(@ast::expr), MRItem(@ast::item), MRAny(fn@()-> @ast::expr, fn@()-> Option<@ast::item>, fn@()->@ast::stmt), - MRDef(MacroDef), + MRDef(MacroDef) } pub enum SyntaxExtension { diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 7e74163b6bf..e7b5005d8db 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -217,7 +217,6 @@ pub impl Parser { let mut first = true; let mut v = ~[]; while self.token != token::GT - // wait... isn't this going to eat a whole '>>' ? && self.token != token::BINOP(token::SHR) { match sep { Some(ref t) => { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index b863e2bd0e4..12038898a9d 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -244,8 +244,17 @@ mod test { ~[], new_parse_sess(None)); check_equal(to_json_str(tts as Encodable::), - //[["tt_tok",["IDENT","fn"]]] - ~"abc" + ~"[[\"tt_tok\",[,[\"IDENT\",[\"fn\",false]]]],\ + [\"tt_tok\",[,[\"IDENT\",[\"foo\",false]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[,[\"LPAREN\",[]]]],\ + [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[,[\"COLON\",[]]]],\ + [\"tt_tok\",[,[\"IDENT\",[\"int\",false]]]],\ + [\"tt_tok\",[,[\"RPAREN\",[]]]]]]],\ + [\"tt_delim\",[[[\"tt_tok\",[,[\"LBRACE\",[]]]],\ + [\"tt_tok\",[,[\"IDENT\",[\"x\",false]]]],\ + [\"tt_tok\",[,[\"SEMI\",[]]]],\ + [\"tt_tok\",[,[\"RBRACE\",[]]]]]]]]" ); let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts) .parse_item(~[]); -- cgit 1.4.1-3-g733a5