Implement pattern ranges for all numeric types.
This commit is contained in:
parent
e6a84f252a
commit
ce0f054f9d
14 changed files with 451 additions and 25 deletions
|
|
@ -92,6 +92,7 @@ tag pat_ {
|
|||
pat_rec([field_pat], bool);
|
||||
pat_tup([@pat]);
|
||||
pat_box(@pat);
|
||||
pat_range(@lit, @lit);
|
||||
}
|
||||
|
||||
tag mutability { mut; imm; maybe_mut; }
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ iter pat_bindings(pat: @pat) -> @pat {
|
|||
for elt in elts { for each b in pat_bindings(elt) { put b; } }
|
||||
}
|
||||
pat_box(sub) { for each b in pat_bindings(sub) { put b; } }
|
||||
pat_wild. | pat_lit(_) { }
|
||||
pat_wild. | pat_lit(_) | pat_range(_, _) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,3 +229,4 @@ fn ret_by_ref(style: ret_style) -> bool {
|
|||
// buffer-file-coding-system: utf-8-unix
|
||||
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
// End:
|
||||
|
||||
|
|
|
|||
|
|
@ -291,6 +291,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
|||
}
|
||||
pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
|
||||
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
|
||||
pat_range(_, _) { p }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1494,8 +1494,14 @@ fn parse_pat(p: parser) -> @ast::pat {
|
|||
tok {
|
||||
if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") {
|
||||
let lit = parse_lit(p);
|
||||
hi = lit.span.hi;
|
||||
pat = ast::pat_lit(@lit);
|
||||
if eat_word(p, "to") {
|
||||
let end = parse_lit(p);
|
||||
hi = end.span.hi;
|
||||
pat = ast::pat_range(@lit, @end);
|
||||
} else {
|
||||
hi = lit.span.hi;
|
||||
pat = ast::pat_lit(@lit);
|
||||
}
|
||||
} else if is_plain_ident(p) &&
|
||||
alt p.look_ahead(1u) {
|
||||
token::DOT. | token::LPAREN. | token::LBRACKET. {
|
||||
|
|
|
|||
|
|
@ -1113,6 +1113,12 @@ fn print_pat(s: ps, pat: @ast::pat) {
|
|||
pclose(s);
|
||||
}
|
||||
ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); }
|
||||
ast::pat_range(begin, end) {
|
||||
print_literal(s, begin);
|
||||
space(s.s);
|
||||
word_space(s, "to");
|
||||
print_literal(s, end);
|
||||
}
|
||||
}
|
||||
s.ann.post(ann_node);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue