Skip to content

Commit

Permalink
Support {key}
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Pavlov committed Feb 7, 2020
1 parent d98bd8f commit 528ec18
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/grammars/Soy.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
IFEMPTY = "ifempty"
IN = "in"
INDEX_NULL_CHECK = "?["
KEY = "key"
LB = "lb"
LBRACE = "{"
LBRACE_LBRACE = "{{"
Expand Down Expand Up @@ -460,6 +461,8 @@ private SingleTagStatement ::=
LetSingleStatement
|
SkipStatement
|
KeyStatement
|
SpecialCharacterStatement
|
Expand Down Expand Up @@ -731,6 +734,14 @@ private LetSingleTagBody ::= LET VariableDefinitionIdentifier COLON Expr {

SkipStatement ::= <<BracedTag SKIP>>

// Key statement

KeyStatement ::= <<BracedTag KeyBody>>

private KeyBody ::= KEY Expr {
pin = 1
}

// Special character statement

SpecialCharacterStatement ::=
Expand Down
1 change: 1 addition & 0 deletions src/main/grammars/Soy.flex
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ NonSemantical=({WhiteSpace}|{LineComment}|{DocCommentBlock}|{BlockComment})*
"let" { return SoyTypes.LET; }
"msg" { return SoyTypes.MSG; }

"key" { return SoyTypes.KEY; }
"nbsp" { return SoyTypes.NBSP; }
"nil" { return SoyTypes.NIL; }
"param" { return SoyTypes.PARAM; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SoyTokenTypes {
SoyTypes.IF,
SoyTypes.IN,
SoyTypes.IFEMPTY,
SoyTypes.KEY,
SoyTypes.LB,
SoyTypes.LET,
SoyTypes.LITERAL,
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/parser/SimpleStatements.soy
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@
{css($base, $Foo)}
{literal}{/literal}
<div {skip}></div>
<div {key 1}></div>
<div {key "1"}></div>
<div {key $var}></div>
<div {key $var1 + $var2 + $var3}></div>
{/template}
49 changes: 49 additions & 0 deletions src/test/resources/parser/SimpleStatements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,55 @@ Closure Template File
PsiElement(SoyTokenType.{)('{')
PsiElement(SoyTokenType.skip)('skip')
PsiElement(SoyTokenType.})('}')
PsiElement(SoyTokenType.OTHER)('></div>\n <div ')
SoyKeyStatementImpl(KEY_STATEMENT)
PsiElement(SoyTokenType.{)('{')
PsiElement(SoyTokenType.key)('key')
PsiWhiteSpace(' ')
SoyLiteralExprImpl(LITERAL_EXPR)
PsiElement(SoyTokenType.INTEGER_LITERAL)('1')
PsiElement(SoyTokenType.})('}')
PsiElement(SoyTokenType.OTHER)('></div>\n <div ')
SoyKeyStatementImpl(KEY_STATEMENT)
PsiElement(SoyTokenType.{)('{')
PsiElement(SoyTokenType.key)('key')
PsiWhiteSpace(' ')
SoyLiteralExprImpl(LITERAL_EXPR)
SoyAnyStringLiteralImpl(ANY_STRING_LITERAL)
PsiElement(SoyTokenType.STRING_LITERAL)('"1"')
PsiElement(SoyTokenType.})('}')
PsiElement(SoyTokenType.OTHER)('></div>\n <div ')
SoyKeyStatementImpl(KEY_STATEMENT)
PsiElement(SoyTokenType.{)('{')
PsiElement(SoyTokenType.key)('key')
PsiWhiteSpace(' ')
SoyVariableReferenceIdentifierImpl(VARIABLE_REFERENCE_IDENTIFIER)
PsiElement(SoyTokenType.$)('$')
PsiElement(SoyTokenType.IDENTIFIER_WORD)('var')
PsiElement(SoyTokenType.})('}')
PsiElement(SoyTokenType.OTHER)('></div>\n <div ')
SoyKeyStatementImpl(KEY_STATEMENT)
PsiElement(SoyTokenType.{)('{')
PsiElement(SoyTokenType.key)('key')
PsiWhiteSpace(' ')
SoyAddBinExprImpl(ADD_BIN_EXPR)
SoyAddBinExprImpl(ADD_BIN_EXPR)
SoyVariableReferenceIdentifierImpl(VARIABLE_REFERENCE_IDENTIFIER)
PsiElement(SoyTokenType.$)('$')
PsiElement(SoyTokenType.IDENTIFIER_WORD)('var1')
PsiWhiteSpace(' ')
PsiElement(SoyTokenType.+)('+')
PsiWhiteSpace(' ')
SoyVariableReferenceIdentifierImpl(VARIABLE_REFERENCE_IDENTIFIER)
PsiElement(SoyTokenType.$)('$')
PsiElement(SoyTokenType.IDENTIFIER_WORD)('var2')
PsiWhiteSpace(' ')
PsiElement(SoyTokenType.+)('+')
PsiWhiteSpace(' ')
SoyVariableReferenceIdentifierImpl(VARIABLE_REFERENCE_IDENTIFIER)
PsiElement(SoyTokenType.$)('$')
PsiElement(SoyTokenType.IDENTIFIER_WORD)('var3')
PsiElement(SoyTokenType.})('}')
PsiElement(SoyTokenType.OTHER)('></div>\n')
SoyEndTagImpl(END_TAG)
PsiElement(SoyTokenType.{/)('{/')
Expand Down

0 comments on commit 528ec18

Please sign in to comment.