diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-08-03 10:19:36 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-08-03 10:26:41 +0200 |
| commit | d08c0f0ec12d5fb238a3a9992e2da4fadcf9d1d4 (patch) | |
| tree | 521b2010c06562e08e8a0a61565a533b1c14a3e2 /src/comp/syntax | |
| parent | 948f8090ae66ea9207473bf97d5c0dfaee4244ed (diff) | |
Make ast::pat_bindings an iterator
And use it to get rid of some repetetive code
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 5dfe6ba7463..ff8e6c0893c 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -154,23 +154,29 @@ fn pat_id_map(pat: &@pat) -> pat_id_map { ret map; } -// FIXME This wanted to be an iter, but bug #791 got in the way. -fn pat_bindings(pat: &@pat) -> (@pat)[] { - let found = ~[]; - fn recur(found: &mutable (@pat)[], pat: &@pat) { - alt pat.node { - pat_bind(_) { found += ~[pat]; } - pat_tag(_, sub) { - for p in sub { recur(found, p); } - } - pat_rec(fields, _) { - for f: field_pat in fields { recur(found, f.pat); } - } - pat_box(sub) { recur(found, sub); } - pat_wild. | pat_lit(_) {} +iter pat_bindings(pat: &@pat) -> @pat { + alt pat.node { + pat_bind(_) { put pat; } + pat_tag(_, sub) { + for p in sub { + for each b in pat_bindings(p) { put b; } + } + } + pat_rec(fields, _) { + for f in fields { + for each b in pat_bindings(f.pat) { put b; } } + } + pat_box(sub) { + for each b in pat_bindings(sub) { put b; } + } + pat_wild. | pat_lit(_) {} } - recur(found, pat); +} + +fn pat_binding_ids(pat: &@pat) -> node_id[] { + let found = ~[]; + for each b in pat_bindings(pat) { found += ~[b.id]; } ret found; } |
