Fixing an infinite type, updating code to match new Early parser, remembering to add protocol parser.

This commit is contained in:
Eric Holk 2012-07-05 23:04:56 -07:00
parent 6806aa0e66
commit fa4134611d
4 changed files with 72 additions and 3 deletions

View File

@ -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);

View 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();
}
}

View File

@ -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)}
}
}

View File

@ -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 {
@ -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" }
}
}
}