Skip to content
Browse files

support string binary literals <<"like this">>

  • Loading branch information...
1 parent 09304a8 commit c13d8d7b1e4a89cc67563b67a6e07772862c6a59 @ericbmerritt ericbmerritt committed
Showing with 23 additions and 2 deletions.
  1. +4 −0 src/jxa_clause.erl
  2. +4 −0 src/jxa_expression.erl
  3. +4 −0 src/jxa_literal.erl
  4. +11 −2 src/jxa_parser.erl
View
4 src/jxa_clause.erl
@@ -15,6 +15,10 @@
comp(Path0, Ctx0, Clauses) ->
comp(Path0, Ctx0, Clauses, []).
+comp_pattern(Path0, Acc0={Ctx0, _}, Arg) when is_binary(Arg) ->
+ {_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
+ jxa_ctx:annots(Ctx0)),
+ {Acc0, cerl:ann_make_data([Line], {atomic, Arg}, [])};
comp_pattern(Path0, {Ctx0, Guards0}, '_') ->
{_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
jxa_ctx:annots(Ctx0)),
View
4 src/jxa_expression.erl
@@ -25,6 +25,10 @@ eval_args(Path0, Ctx0, Args0) ->
end, {Path0, Ctx0, []}, Args0),
{Ctx3, lists:reverse(Args1)}.
+comp(Path0, Ctx0, Arg) when is_binary(Arg) ->
+ {_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
+ jxa_ctx:annots(Ctx0)),
+ {Ctx0, cerl:ann_make_data([Line], {atomic, Arg}, [])};
comp(Path0, Ctx0, Arg) when is_atom(Arg) ->
{_, Idx = {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
jxa_ctx:annots(Ctx0)),
View
4 src/jxa_literal.erl
@@ -12,6 +12,10 @@
%% Public API
%%=============================================================================
-spec comp(jxa_path:state(), jxa_ctx:context(), term()) -> cerl:cerl().
+comp(Path0, Ctx0, Arg) when is_binary(Arg) ->
+ {_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
+ jxa_ctx:annots(Ctx0)),
+ {Ctx0, cerl:ann_make_data([Line], {atomic, Arg}, [])};
comp(Path0, Ctx0, Symbol) when is_atom(Symbol) ->
{_, {Line, _}} = jxa_annot:get(jxa_path:path(Path0),
jxa_ctx:annots(Ctx0)),
View
13 src/jxa_parser.erl
@@ -142,7 +142,9 @@ transform_ast(Path0, Annotations0, {literal_list, List, Idx}) ->
Annotations3),
{jxa_annot:add(jxa_path:path(Path0), {literal_list, Idx}, Annotations4),
[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)};
transform_ast(Path0, Annotations0, {binary, List, Idx}) ->
{_, Annotations3, TransformList} =
lists:foldl(fun(El, {Path1, Annotations1, Elements}) ->
@@ -242,6 +244,7 @@ int_part(Input, Index) ->
p_seq([p_optional(p_string(<<"-">>)),
p_one_or_more(fun digit/2)])).
+%% Done
-spec frac_part(binary(), index()) -> intermediate_ast().
frac_part(Input, Index) ->
p(Input, Index, frac_part,
@@ -287,12 +290,18 @@ binary(Input, Index) ->
fun list/2])])),
fun ignorable/2,
p_string(<<">>">>)]),
- fun string/2,
+ p_seq([p_string(<<"<<">>),
+ fun ignorable/2,
+ fun string/2,
+ fun ignorable/2,
+ p_string(<<">>">>)]),
p_seq([p_string(<<"<<">>),
fun ignorable/2,
p_string(<<">>">>)])]),
fun([_, _, H, T, _, _], Idx) ->
{binary, lists:flatten([H, T]), Idx};
+ ([_, _, String, _, _], Idx) ->
+ {binary, String, Idx};
([_, _, _], Idx) ->
{binary, [], Idx}
end).

0 comments on commit c13d8d7

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