aboutsummaryrefslogtreecommitdiffstats
path: root/lib/syntax_tools/src/erl_syntax.erl
diff options
context:
space:
mode:
authorRichard Carlsson <[email protected]>2012-04-22 22:32:20 +0200
committerFredrik Gustafsson <[email protected]>2012-08-08 10:58:29 +0200
commit53746070b5de7d1e9f809d516648948b0a246561 (patch)
treea44465d5a456626503d255b35ecc8a08e0aaec27 /lib/syntax_tools/src/erl_syntax.erl
parent7dc58ca03d6c59dadfb6c570b97e05c08644041b (diff)
downloadotp-53746070b5de7d1e9f809d516648948b0a246561.tar.gz
otp-53746070b5de7d1e9f809d516648948b0a246561.tar.bz2
otp-53746070b5de7d1e9f809d516648948b0a246561.zip
make list_suffix/1 and list_prefix/1 handle erl_parse() cons sequences
Diffstat (limited to 'lib/syntax_tools/src/erl_syntax.erl')
-rw-r--r--lib/syntax_tools/src/erl_syntax.erl26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/syntax_tools/src/erl_syntax.erl b/lib/syntax_tools/src/erl_syntax.erl
index beae6f4a01..76a6a6dc36 100644
--- a/lib/syntax_tools/src/erl_syntax.erl
+++ b/lib/syntax_tools/src/erl_syntax.erl
@@ -2061,12 +2061,18 @@ revert_nil(Node) ->
list_prefix(Node) ->
case unwrap(Node) of
- {cons, _, Head, _} ->
- [Head];
+ {cons, _, Head, Tail} ->
+ [Head | cons_prefix(Tail)];
Node1 ->
(data(Node1))#list.prefix
end.
+%% collects sequences of conses; cf. cons_suffix/1 below
+cons_prefix({cons, _, Head, Tail}) ->
+ [Head | cons_prefix(Tail)];
+cons_prefix(_) ->
+ [].
+
%% =====================================================================
%% @doc Returns the suffix subtree of a `list' node, if one
@@ -2090,18 +2096,22 @@ list_prefix(Node) ->
list_suffix(Node) ->
case unwrap(Node) of
{cons, _, _, Tail} ->
- %% If there could be comments/annotations on the tail node,
- %% we should not return `none' even if it has type `nil'.
- case Tail of
+ case cons_suffix(Tail) of
{nil, _} ->
- none; % no interesting information is lost
- _ ->
- Tail
+ none;
+ Tail1 ->
+ Tail1
end;
Node1 ->
(data(Node1))#list.suffix
end.
+%% skips sequences of conses; cf. cons_prefix/1 above
+cons_suffix({cons, _, _, Tail}) ->
+ cons_suffix(Tail);
+cons_suffix(Tail) ->
+ Tail.
+
%% =====================================================================
%% @doc "Optimising" list skeleton cons operation. Creates an abstract