diff options
| author | bors <bors@rust-lang.org> | 2013-03-27 21:51:53 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-27 21:51:53 -0700 |
| commit | 84ddff3909b5920228642649b7f5cc011c0b900a (patch) | |
| tree | 25cfe9b7ddd20bc08ea56de4fe87dbabf9a885f0 /src/libsyntax/parse | |
| parent | 4954d3e50177c46d260a5340ff91bfada8590ef0 (diff) | |
| parent | c317d3f6fa9475e65b6276743c09444441059ca7 (diff) | |
| download | rust-84ddff3909b5920228642649b7f5cc011c0b900a.tar.gz rust-84ddff3909b5920228642649b7f5cc011c0b900a.zip | |
auto merge of #5578 : erickt/rust/incoming, r=jbclements,erickt
Hey folks,
This patch series does some work on the json decoder, specifically with auto decoding of enums. Previously, we would take this code:
```
enum A {
B,
C(~str, uint)
}
```
and would encode a value of this enum to either `["B", []]` or `["C", ["D", 123]]`. I've changed this to `"B"` or `["C", "D", 123]`. This matches the style of the O'Caml json library [json-wheel](http://mjambon.com/json-wheel.html). I've added tests to make sure all this work.
In order to make this change, I added passing a `&[&str]` vec to `Decode::emit_enum_variant` so the json decoder can convert the name of a variant into it's position. I also changed the impl of `Encodable` for `Option<T>` to have the right upper casing.
I also did some work on the parser, which allows for `fn foo<T: ::cmp::Eq>() { ... }` statements (#5572), fixed the pretty printer properly expanding `debug!("...")` expressions, and removed `ast::expr_vstore_fixed`, which doesn't appear to be used anymore.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 39 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 |
2 files changed, 31 insertions, 25 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a0c73668a05..0ddf9111e02 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -326,19 +326,32 @@ mod test { @~"fn foo (x : int) { x; }", ~[], new_parse_sess(None)); - assert_eq!(to_json_str(@tts), - ~"[[\"tt_tok\",[null,[\"IDENT\",[\"fn\",false]]]],\ - [\"tt_tok\",[null,[\"IDENT\",[\"foo\",false]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[null,[\"LPAREN\",[]]]],\ - [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[null,[\"COLON\",[]]]],\ - [\"tt_tok\",[null,[\"IDENT\",[\"int\",false]]]],\ - [\"tt_tok\",[null,[\"RPAREN\",[]]]]]]],\ - [\"tt_delim\",[[[\"tt_tok\",[null,[\"LBRACE\",[]]]],\ - [\"tt_tok\",[null,[\"IDENT\",[\"x\",false]]]],\ - [\"tt_tok\",[null,[\"SEMI\",[]]]],\ - [\"tt_tok\",[null,[\"RBRACE\",[]]]]]]]]" - ); + assert_eq!( + to_json_str(@tts), + ~"[\ + [\"tt_tok\",null,[\"IDENT\",\"fn\",false]],\ + [\"tt_tok\",null,[\"IDENT\",\"foo\",false]],\ + [\ + \"tt_delim\",\ + [\ + [\"tt_tok\",null,\"LPAREN\"],\ + [\"tt_tok\",null,[\"IDENT\",\"x\",false]],\ + [\"tt_tok\",null,\"COLON\"],\ + [\"tt_tok\",null,[\"IDENT\",\"int\",false]],\ + [\"tt_tok\",null,\"RPAREN\"]\ + ]\ + ],\ + [\ + \"tt_delim\",\ + [\ + [\"tt_tok\",null,\"LBRACE\"],\ + [\"tt_tok\",null,[\"IDENT\",\"x\",false]],\ + [\"tt_tok\",null,\"SEMI\"],\ + [\"tt_tok\",null,\"RBRACE\"]\ + ]\ + ]\ + ]" + ); let ast1 = new_parser_from_tts(new_parse_sess(None),~[],tts) .parse_item(~[]); let ast2 = parse_item_from_source_str( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c2e7ecacd20..6ca91791ffd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -28,7 +28,7 @@ use ast::{expr_lit, expr_log, expr_loop, expr_loop_body, expr_mac}; use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_swap, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box, expr_inline_asm}; -use ast::{expr_vstore_fixed, expr_vstore_slice, expr_vstore_box}; +use ast::{expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod}; @@ -1223,7 +1223,7 @@ pub impl Parser { let lvl = self.parse_expr(); self.expect(&token::COMMA); let e = self.parse_expr(); - ex = expr_log(ast::log_other, lvl, e); + ex = expr_log(lvl, e); hi = self.span.hi; self.expect(&token::RPAREN); } else if self.eat_keyword(&~"return") { @@ -2721,8 +2721,9 @@ pub impl Parser { } self.bump(); } - token::IDENT(*) => { + token::MOD_SEP | token::IDENT(*) => { let maybe_bound = match *self.token { + token::MOD_SEP => None, token::IDENT(copy sid, _) => { match *self.id_to_str(sid) { ~"send" | @@ -2750,7 +2751,7 @@ pub impl Parser { result.push(bound); } None => { - let ty = self.parse_ty(false); + let ty = self.parse_ty(true); result.push(TraitTyParamBound(ty)); } } @@ -3099,14 +3100,6 @@ pub impl Parser { // impl<T> Foo { ... } // impl<T> ToStr for ~[T] { ... } fn parse_item_impl(&self, visibility: ast::visibility) -> item_info { - fn wrap_path(p: &Parser, pt: @path) -> @Ty { - @Ty { - id: p.get_id(), - node: ty_path(pt, p.get_id()), - span: pt.span, - } - } - // First, parse type parameters if necessary. let generics = self.parse_generics(); |
