Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing an infinite type, updating code to match new Early parser, rem…
…embering to add protocol parser.
  • Loading branch information
eholk committed Jul 6, 2012
1 parent 6806aa0 commit fa41346
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/libsyntax/ext/pipes.rs
Expand Up @@ -17,7 +17,9 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, tt: ast::token_tree)
let cfg = cx.cfg();
let body_core = alt tt { tt_delim(tts) { tts } _ {fail}};
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, body_core);
cx.parse_sess().interner,
none,
body_core);
let rdr = tt_rdr as reader;
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);

Expand Down
63 changes: 63 additions & 0 deletions src/libsyntax/ext/pipes/parse_proto.rs
@@ -0,0 +1,63 @@
// Parsing pipes protocols from token trees.

import parse::parser;
import ast::ident;
import parse::token;

import pipec::*;

impl proto_parser for parser {
fn parse_proto(id: ident) -> protocol {
let proto = protocol(id);

self.expect(token::LBRACE);

while self.token != token::RBRACE {
self.parse_state(proto);
}

ret proto;
}

fn parse_state(proto: protocol) {
let id = self.parse_ident();
self.expect(token::COLON);
let dir = alt copy self.token {
token::IDENT(n, _) {
self.get_str(n)
}
_ { fail }
};
self.bump();
let dir = alt dir {
@"send" { send }
@"recv" { recv }
_ { fail }
};

let state = proto.add_state(id, dir);
// TODO: add typarams too.

self.expect(token::LBRACE);

while self.token != token::RBRACE {
let mname = self.parse_ident();

// TODO: parse data

self.expect(token::RARROW);

let next = self.parse_ident();
// TODO: parse next types

state.add_message(mname, ~[], next, ~[]);

alt copy self.token {
token::COMMA { self.bump() }
token::RBRACE { }
_ { fail }
}
}
self.bump();
}
}
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/earley_parser.rs
Expand Up @@ -272,7 +272,7 @@ fn parse_nt(p: parser, name: str) -> whole_nt {
+ token::to_str(*p.reader.interner(), copy p.token)) }
} }
"path" { token::w_path(p.parse_path_with_tps(false)) }
"tt" { token::w_tt(p.parse_token_tree()) }
"tt" { token::w_tt(@p.parse_token_tree()) }
_ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/parse/token.rs
Expand Up @@ -96,7 +96,10 @@ enum whole_nt {
w_ty( @ast::ty),
w_ident(str_num, bool),
w_path(@ast::path),
w_tt(ast::token_tree),
// TODO: this seems to cause infinite recursion in
// type_structually_contains if it's not an @-box. We should at least get
// failure instead.
w_tt(@ast::token_tree),
}

fn binop_to_str(o: binop) -> str {
Expand Down Expand Up @@ -190,6 +193,7 @@ fn to_str(in: interner<@str>, t: token) -> str {
w_stmt(*) { "statement" } w_pat(*) { "pattern" }
w_expr(*) { "expression" } w_ty(*) { "type" }
w_ident(*) { "identifier" } w_path(*) { "path" }
w_tt(*) { "tt" }
}
}
}
Expand Down

0 comments on commit fa41346

Please sign in to comment.