Permalink
Browse files

Added '++' operator for lists/binary concatenation.

  • Loading branch information...
1 parent 67e2045 commit 0f2e2dfc7574ac8f21b82cce57933c492c61bc05 @mworrell mworrell committed Aug 30, 2012
Showing with 15 additions and 0 deletions.
  1. +9 −0 src/erlydtl/erlydtl_operators.erl
  2. +3 −0 src/erlydtl/erlydtl_parser.yrl
  3. +3 −0 src/erlydtl/erlydtl_scanner.erl
View
9 src/erlydtl/erlydtl_operators.erl
@@ -25,6 +25,7 @@
'or'/3,
'xor'/3,
+ concat/3,
add/3,
sub/3,
divide/3,
@@ -55,6 +56,14 @@
erlydtl_runtime:is_true(A, Context) xor erlydtl_runtime:is_true(B, Context).
+concat(A, B, _Context) when is_list(A), is_list(B) ->
+ A++B;
+concat(A, B, Context) ->
+ ABin = z_convert:to_binary(A, Context),
+ BBin = z_convert:to_binary(B, Context),
+ <<ABin/binary, BBin/binary>>.
+
+
add(A, B, _Context) ->
case to_numbers(A, B) of
{undefined, _} -> undefined;
View
3 src/erlydtl/erlydtl_parser.yrl
@@ -227,6 +227,7 @@ Terminals
__keyword
hash
'==' '/=' '<' '>' '=<' '>='
+ '++'
'+' '-'
'*' '/' '%'
'(' ')'.
@@ -239,6 +240,7 @@ Left 100 or_keyword.
Left 105 xor_keyword.
Left 110 and_keyword.
Nonassoc 300 '==' '/=' '<' '>' '=<' '>='.
+Left 350 '++'.
Left 400 '+' '-'.
Left 500 '*' '/' '%'.
Unary 600 Uminus Unot.
@@ -461,6 +463,7 @@ E -> E '<' E : {expr, "lt", '$1', '$3'}.
E -> E '>' E : {expr, "gt", '$1', '$3'}.
E -> E '=<' E : {expr, "le", '$1', '$3'}.
E -> E '>=' E : {expr, "ge", '$1', '$3'}.
+E -> E '++' E : {expr, "concat", '$1', '$3'}.
E -> E '+' E : {expr, "add", '$1', '$3'}.
E -> E '-' E : {expr, "sub", '$1', '$3'}.
E -> E '*' E : {expr, "multiply", '$1', '$3'}.
View
3 src/erlydtl/erlydtl_scanner.erl
@@ -330,6 +330,9 @@ scan("<" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
scan(">" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
scan(T, [{'>', {SourceRef, Row, Column}, ">"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});
+scan("++" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
+ scan(T, [{'++', {SourceRef, Row, Column}, "++"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});
+
scan("-" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
scan(T, [{'-', {SourceRef, Row, Column}, "-"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});

0 comments on commit 0f2e2df

Please sign in to comment.