Add support for matchers nonterminals.
This commit is contained in:
parent
cabee6391d
commit
caa83b41bb
3 changed files with 19 additions and 11 deletions
|
@ -272,7 +272,13 @@ fn parse_nt(p: parser, name: str) -> whole_nt {
|
||||||
+ token::to_str(*p.reader.interner(), copy p.token)) }
|
+ token::to_str(*p.reader.interner(), copy p.token)) }
|
||||||
} }
|
} }
|
||||||
"path" { token::w_path(p.parse_path_with_tps(false)) }
|
"path" { token::w_path(p.parse_path_with_tps(false)) }
|
||||||
"tt" { token::w_tt(@p.parse_token_tree()) }
|
"tt" {
|
||||||
|
p.quote_depth += 1u;
|
||||||
|
let res = token::w_tt(@p.parse_token_tree());
|
||||||
|
p.quote_depth -= 1u;
|
||||||
|
res
|
||||||
|
}
|
||||||
|
"mtcs" { token::w_mtcs(p.parse_matchers()) }
|
||||||
_ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
|
_ { p.fatal("Unsupported builtin nonterminal parser: " + name)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1249,13 +1249,17 @@ class parser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_matchers() -> ~[matcher] {
|
||||||
|
let name_idx = @mut 0u;
|
||||||
|
ret self.parse_seq(token::LBRACE, token::RBRACE,
|
||||||
|
common::seq_sep_none(),
|
||||||
|
|p| p.parse_matcher(name_idx)).node;
|
||||||
|
}
|
||||||
|
|
||||||
/* temporary */
|
/* temporary */
|
||||||
fn parse_tt_mac_demo() -> @expr {
|
fn parse_tt_mac_demo() -> @expr {
|
||||||
import ext::tt::earley_parser::{parse,success,failure};
|
import ext::tt::earley_parser::{parse,success,failure};
|
||||||
let name_idx = @mut 0u;
|
let ms = self.parse_matchers();
|
||||||
let ms = self.parse_seq(token::LBRACE, token::RBRACE,
|
|
||||||
common::seq_sep_none(),
|
|
||||||
|p| p.parse_matcher(name_idx)).node;
|
|
||||||
self.quote_depth += 1u;
|
self.quote_depth += 1u;
|
||||||
let tt_rhs= self.parse_token_tree();
|
let tt_rhs= self.parse_token_tree();
|
||||||
self.quote_depth -= 1u;
|
self.quote_depth -= 1u;
|
||||||
|
|
|
@ -96,10 +96,8 @@ enum whole_nt {
|
||||||
w_ty( @ast::ty),
|
w_ty( @ast::ty),
|
||||||
w_ident(str_num, bool),
|
w_ident(str_num, bool),
|
||||||
w_path(@ast::path),
|
w_path(@ast::path),
|
||||||
// TODO: this seems to cause infinite recursion in
|
w_tt( @ast::token_tree), //needs @ed to break a circularity
|
||||||
// type_structually_contains if it's not an @-box. We should at least get
|
w_mtcs(~[ast::matcher])
|
||||||
// failure instead.
|
|
||||||
w_tt(@ast::token_tree),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn binop_to_str(o: binop) -> str {
|
fn binop_to_str(o: binop) -> str {
|
||||||
|
@ -193,8 +191,8 @@ fn to_str(in: interner<@str>, t: token) -> str {
|
||||||
w_stmt(*) { "statement" } w_pat(*) { "pattern" }
|
w_stmt(*) { "statement" } w_pat(*) { "pattern" }
|
||||||
w_expr(*) { "expression" } w_ty(*) { "type" }
|
w_expr(*) { "expression" } w_ty(*) { "type" }
|
||||||
w_ident(*) { "identifier" } w_path(*) { "path" }
|
w_ident(*) { "identifier" } w_path(*) { "path" }
|
||||||
w_tt(*) { "tt" }
|
w_tt(*) { "tt" } w_mtcs(*) { "matcher sequence" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue