Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parse transform no longer requires a wrapper

The second argument to content/3, map/4, attr/4, id/3, class/3,
add_class/3 and remove_class/3 in module brim will automatically
be preparsed if it is a plain string and brim/include/brim.hrl is
included.
  • Loading branch information...
commit 6cd1e8fb911a31be97e351ac304b4cae99d4b881 1 parent 460eb94
@permelin authored
Showing with 23 additions and 24 deletions.
  1. +23 −10 src/brim_parse_transform.erl
  2. +0 −14 test/brim_parse_transform_tests.erl
View
33 src/brim_parse_transform.erl
@@ -18,8 +18,14 @@ transform(Tree) ->
case erl_syntax:type(Tree) of
application ->
case erl_syntax_lib:analyze_application(Tree) of
- {sel, 1} ->
- replacement_tree(Tree);
+ {brim, FA} when FA == {content, 3};
+ FA == {map, 4};
+ FA == {attr, 4};
+ FA == {id, 3};
+ FA == {class, 3};
+ FA == {add_class, 3};
+ FA == {remove_class, 3} ->
+ maybe_replace(Tree);
_ ->
Tree
end;
@@ -27,14 +33,21 @@ transform(Tree) ->
Tree
end.
-replacement_tree(Tree) ->
- [Arg] = erl_syntax:application_arguments(Tree),
- try brim_selector_lex:scan(erl_syntax:concrete(Arg)) of
- Selector ->
- erl_syntax:abstract(Selector)
- catch
- _:Error ->
- throw({Error, erl_syntax:get_pos(Tree)})
+maybe_replace(Tree) ->
+ [Arg1, Selector|Args] = erl_syntax:application_arguments(Tree),
+ case erl_syntax:type(Selector) of
+ string ->
+ try brim_selector_lex:scan(erl_syntax:concrete(Selector)) of
+ Parsed ->
+ ParsedTree = erl_syntax:abstract(Parsed),
+ Op = erl_syntax:application_operator(Tree),
+ erl_syntax:application(Op, [Arg1, ParsedTree|Args])
+ catch
+ _:Error ->
+ throw({Error, erl_syntax:get_pos(Tree)})
+ end;
+ _ ->
+ Tree
end.
filename(Forms) ->
View
14 test/brim_parse_transform_tests.erl
@@ -1,14 +0,0 @@
--module(brim_parse_transform_tests).
-
--include_lib("eunit/include/eunit.hrl").
--include_lib("brim/include/brim.hrl").
-
-transform_test() ->
- ?assertEqual({selector,
- [{element, "aaa"},
- {class, "bbb"},
- {relation, parent},
- {element, "*"},
- {id, "ccc"},
- {attrib, "ddd"}]},
- sel("aaa.bbb > *#ccc[ddd]")).
Please sign in to comment.
Something went wrong with that request. Please try again.