Fixing an infinite type, updating code to match new Early parser, remembering to add protocol parser.
This commit is contained in:
parent
6806aa0e66
commit
fa4134611d
4 changed files with 72 additions and 3 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
63
src/libsyntax/ext/pipes/parse_proto.rs
Normal file
63
src/libsyntax/ext/pipes/parse_proto.rs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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)}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue