Skip to content

Commit

Permalink
Accept any identifier as attribute (Fixes #177)
Browse files Browse the repository at this point in the history
Now, the . for looking up an attribute of a variable will bypass any other reserved meaning that the
indentifier may normally hold. So, in a way, the attribute lookup opertaion short-circuits the
keyword mechanism. Which makes sense, as it won't make sense to put a keyword after the dot any way.
  • Loading branch information
kaos committed Jun 29, 2014
1 parent b9ec861 commit 96dccf6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Expand Up @@ -6,4 +6,6 @@ Standards](http://www.gnu.org/prep/standards/html_node/NEWS-File.html#NEWS-File)

## master (upcoming release)

* Fixed issue with generated code for `for` loops (#167).
* Fix issue with generated code for `for` loops (#167).

* Fix issue with using keywords as attributes (#177).
6 changes: 5 additions & 1 deletion src/erlydtl_scanner.erl
Expand Up @@ -36,7 +36,7 @@
%%%-------------------------------------------------------------------
-module(erlydtl_scanner).

%% This file was generated 2014-04-15 19:15:09 UTC by slex 0.2.1.
%% This file was generated 2014-06-29 19:46:00 UTC by slex 0.2.1-2-g7814678.
%% http://github.com/erlydtl/slex
-slex_source(["src/erlydtl_scanner.slex"]).

Expand Down Expand Up @@ -563,6 +563,10 @@ post_process([{open_tag, _, _} | _],
post_process([{open_tag, _, _} | _],
{identifier, _, L} = T, _) ->
is_keyword(open_tag, T);
post_process([{'.', _} | _], {identifier, _, L} = T,
_) ->
setelement(3, T,
begin L1 = lists:reverse(L), L2 = to_atom(L1), L2 end);
post_process(_, {identifier, _, L} = T, close_tag) ->
is_keyword(close_tag, T);
post_process(_, {identifier, _, L} = T, _) ->
Expand Down
1 change: 1 addition & 0 deletions src/erlydtl_scanner.slex
Expand Up @@ -266,6 +266,7 @@ close_tag: to_atom.

open_tag identifier, close_tag: expr is_keyword(all, T) end.
open_tag identifier: expr is_keyword(open_tag, T) end.
\. - identifier: lists reverse, to_atom.
identifier, close_tag: expr is_keyword(close_tag, T) end.
identifier: expr is_keyword(any, T) end.

Expand Down
6 changes: 5 additions & 1 deletion test/erlydtl_test_defs.erl
Expand Up @@ -139,7 +139,11 @@ all_test_defs() ->
{"Index all tuple elements 1-based (selected at render time)",
<<"{{ var1.1 }},{{ var1.2 }},{{ var1.3 }}.">>,
[{var1, {a, b, c}}], [], [{tuples_0_based, defer}],
<<"a,b,c.">>}
<<"a,b,c.">>},
{"Index tuple using a \"reserved\" keyword",
<<"{{ list.count }}">>,
[{list, [{count, 123}]}],
<<"123">>}
]},
{"now",
[{"now functional",
Expand Down

0 comments on commit 96dccf6

Please sign in to comment.