Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for {% elif Expr %} syntax

  • Loading branch information...
commit 9f074aaabcdf49ae721ddfe15917bb7c65c8658d 1 parent 748dc8b
Björn-Egil Dahlberg psyeugenic authored psyeugenic committed
4 src/erlydtl_compiler.erl
View
@@ -541,6 +541,10 @@ body_ast(DjangoParseTree, Context, TreeWalker) ->
({'for', {'in', IteratorList, Variable}, Contents, EmptyPartContents}, TreeWalkerAcc) ->
{EmptyAstInfo, TreeWalker1} = body_ast(EmptyPartContents, Context, TreeWalkerAcc),
for_loop_ast(IteratorList, Variable, Contents, EmptyAstInfo, Context, TreeWalker1);
+ ({'if', Expression, Contents, Elif}, TreeWalkerAcc) ->
+ {IfAstInfo, TreeWalker1} = body_ast(Contents, Context, TreeWalkerAcc),
+ {ElifAstInfo, TreeWalker2} = body_ast(Elif, Context, TreeWalker1),
+ ifelse_ast(Expression, IfAstInfo, ElifAstInfo, Context, TreeWalker2);
({'if', Expression, Contents}, TreeWalkerAcc) ->
{IfAstInfo, TreeWalker1} = body_ast(Contents, Context, TreeWalkerAcc),
{ElseAstInfo, TreeWalker2} = empty_ast(TreeWalker1),
12 src/erlydtl_parser.yrl
View
@@ -79,6 +79,8 @@ Nonterminals
IfBlock
IfBraced
+ ElifBlock
+ ElifBraced
IfExpression
ElseBraced
EndIfBraced
@@ -137,6 +139,7 @@ Terminals
close_var
comment_keyword
cycle_keyword
+ elif_keyword
else_keyword
empty_keyword
endautoescape_keyword
@@ -296,9 +299,14 @@ ForExpression -> ForGroup in_keyword Variable : {'in', '$1', '$3'}.
ForGroup -> identifier : ['$1'].
ForGroup -> ForGroup ',' identifier : '$1' ++ ['$3'].
-IfBlock -> IfBraced Elements ElseBraced Elements EndIfBraced : {ifelse, '$1', '$2', '$4'}.
+IfBlock -> IfBraced Elements ElseBraced Elements EndIfBraced : {'ifelse', '$1', '$2', '$4'}.
IfBlock -> IfBraced Elements EndIfBraced : {'if', '$1', '$2'}.
+IfBlock -> IfBraced Elements ElifBlock : {'if', '$1', '$2', ['$3']}.
+ElifBlock -> ElifBraced Elements ElseBraced Elements EndIfBraced : {'ifelse', '$1', '$2', '$4'}.
+ElifBlock -> ElifBraced Elements EndIfBraced : {'if', '$1', '$2'}.
+ElifBlock -> ElifBraced Elements ElifBlock : {'if', '$1', '$2', ['$3']}.
IfBraced -> open_tag if_keyword IfExpression close_tag : '$3'.
+ElifBraced -> open_tag elif_keyword IfExpression close_tag : '$3'.
IfExpression -> Value in_keyword Value : {'expr', "in", '$1', '$3'}.
IfExpression -> Value not_keyword in_keyword Value : {'expr', "not", {'expr', "in", '$1', '$4'}}.
IfExpression -> Value '==' Value : {'expr', "eq", '$1', '$3'}.
@@ -384,3 +392,5 @@ Args -> Args identifier '=' Value : '$1' ++ [{'$2', '$4'}].
CallTag -> open_tag call_keyword identifier close_tag : {call, '$3'}.
CallWithTag -> open_tag call_keyword identifier with_keyword Value close_tag : {call, '$3', '$5'}.
+
+%% vim: syntax=erlang
2  src/erlydtl_scanner.erl
View
@@ -76,7 +76,7 @@ scan([], Scanned, _, in_text) ->
"for", "in", "empty", "endfor",
- "if", "else", "endif", "not", "or", "and",
+ "if", "elif", "else", "endif", "not", "or", "and",
"ifchanged", "endifchanged",
Please sign in to comment.
Something went wrong with that request. Please try again.