Skip to content
Browse files

handle limitation in the core erlang compiler

This fixes a problem where erlang compiler blows up when a binary
literal appears in a pattern.
  • Loading branch information...
1 parent e549c73 commit 55907f364a796a21161d1198ca69fbd5ec896be7 @ericbmerritt ericbmerritt committed Jan 2, 2012
Showing with 18 additions and 3 deletions.
  1. +18 −3 src/jxa_parser.erl
View
21 src/jxa_parser.erl
@@ -152,9 +152,24 @@ transform_ast(Path0, Annotations0, {literal_list, List, Idx}) ->
[list | lists:reverse(TransformList)]};
transform_ast(Path0, Annotations0,
{binary, {string, String,_}, Idx})->
- {jxa_annot:add(jxa_path:path(Path0),
- binary, Idx, Annotations0),
- erlang:list_to_binary(String)};
+ %% binary literals in pattern matches do *not* work. So in the interests of
+ %% the least code possible, we translate all binary literals into
+ %% binary/integer calls.
+ {_, Annotations3, TransformList} =
+ lists:foldl(fun(El, {Path1, Annotations1, Elements}) ->
+ {jxa_path:incr(Path1),
+ jxa_annot:add(jxa_path:add_path(Path1), integer,
+ Idx, Annotations1),
+ [El | Elements]}
+ end, {jxa_path:incr(Path0),
+ Annotations0, []}, String),
+ %% We need to put in the annotation for the programatically inserted
+ %% 'list' argument
+ Annotations4 = jxa_annot:add(jxa_path:add_path(Path0), ident, Idx,
+ Annotations3),
+ {jxa_annot:add(jxa_path:path(Path0), binary, Idx, Annotations4),
+ [binary | lists:reverse(TransformList)]};
+
transform_ast(Path0, Annotations0, {binary, List, Idx}) ->
{_, Annotations3, TransformList} =
lists:foldl(fun(El, {Path1, Annotations1, Elements}) ->

0 comments on commit 55907f3

Please sign in to comment.
Something went wrong with that request. Please try again.