Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 0f2e2dfc7574ac8f21b82cce57933c492c61bc05 1 parent 67e2045
Marc Worrell authored August 30, 2012
9  src/erlydtl/erlydtl_operators.erl
@@ -25,6 +25,7 @@
25 25
     'or'/3,
26 26
     'xor'/3,
27 27
 
  28
+    concat/3,
28 29
     add/3,
29 30
     sub/3,
30 31
     divide/3,
@@ -55,6 +56,14 @@
55 56
     erlydtl_runtime:is_true(A, Context) xor erlydtl_runtime:is_true(B, Context).
56 57
 
57 58
 
  59
+concat(A, B, _Context) when is_list(A), is_list(B) ->
  60
+    A++B;
  61
+concat(A, B, Context) ->
  62
+    ABin = z_convert:to_binary(A, Context),
  63
+    BBin = z_convert:to_binary(B, Context),
  64
+    <<ABin/binary, BBin/binary>>.
  65
+
  66
+
58 67
 add(A, B, _Context) ->
59 68
     case to_numbers(A, B) of
60 69
         {undefined, _} -> undefined;
3  src/erlydtl/erlydtl_parser.yrl
@@ -227,6 +227,7 @@ Terminals
227 227
 	__keyword
228 228
  	hash
229 229
 	'==' '/=' '<' '>' '=<' '>='
  230
+    '++'
230 231
 	'+' '-'
231 232
 	'*' '/' '%'
232 233
 	'(' ')'.
@@ -239,6 +240,7 @@ Left 100 or_keyword.
239 240
 Left 105 xor_keyword.
240 241
 Left 110 and_keyword.
241 242
 Nonassoc 300 '==' '/=' '<' '>' '=<' '>='.
  243
+Left 350 '++'.
242 244
 Left 400 '+' '-'.
243 245
 Left 500 '*' '/' '%'.
244 246
 Unary 600 Uminus Unot.
@@ -461,6 +463,7 @@ E -> E '<' E  : {expr, "lt", '$1', '$3'}.
461 463
 E -> E '>' E  : {expr, "gt", '$1', '$3'}.
462 464
 E -> E '=<' E  : {expr, "le", '$1', '$3'}.
463 465
 E -> E '>=' E  : {expr, "ge", '$1', '$3'}.
  466
+E -> E '++' E  : {expr, "concat", '$1', '$3'}.
464 467
 E -> E '+' E  : {expr, "add", '$1', '$3'}.
465 468
 E -> E '-' E  : {expr, "sub", '$1', '$3'}.
466 469
 E -> E '*' E  : {expr, "multiply", '$1', '$3'}.
3  src/erlydtl/erlydtl_scanner.erl
@@ -330,6 +330,9 @@ scan("<" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
330 330
 scan(">" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
331 331
     scan(T, [{'>', {SourceRef, Row, Column}, ">"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});
332 332
 
  333
+scan("++" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
  334
+    scan(T, [{'++', {SourceRef, Row, Column}, "++"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});
  335
+
333 336
 scan("-" ++ T, Scanned, {SourceRef, Row, Column}, {_, Closer}) ->
334 337
     scan(T, [{'-', {SourceRef, Row, Column}, "-"} | Scanned], {SourceRef, Row, Column + 1}, {in_code, Closer});
335 338
 

0 notes on commit 0f2e2df

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