Skip to content

Commit

Permalink
handlebars: add decimal support instead of integer (see handlebars-la…
Browse files Browse the repository at this point in the history
  • Loading branch information
anstarovoyt committed Sep 22, 2014
1 parent b5b55c6 commit caeef17
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 197 deletions.
351 changes: 176 additions & 175 deletions handlebars/gen/com/dmarcotte/handlebars/parsing/_HbLexer.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion handlebars/src/com/dmarcotte/handlebars/HbHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Lexer getHighlightingLexer() {
keys1.put(HbTokenTypes.UNCLOSED_COMMENT, COMMENTS);
keys1.put(HbTokenTypes.EQUALS, OPERATORS);
keys1.put(HbTokenTypes.SEP, OPERATORS);
keys1.put(HbTokenTypes.INTEGER, VALUES);
keys1.put(HbTokenTypes.NUMBER, VALUES);
keys1.put(HbTokenTypes.ELSE, IDENTIFIERS);
keys1.put(HbTokenTypes.BOOLEAN, VALUES);
keys1.put(HbTokenTypes.STRING, STRINGS);
Expand Down
16 changes: 8 additions & 8 deletions handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,12 @@ private boolean parseParams(PsiBuilder builder) {
* param
* : path
* | STRING
* | INTEGER
* | NUMBER
* | BOOLEAN
* | dataName
* ;
*/
private boolean parseParam(PsiBuilder builder) {
protected boolean parseParam(PsiBuilder builder) {
PsiBuilder.Marker paramMarker = builder.mark();

if (parsePath(builder)) {
Expand All @@ -505,7 +505,7 @@ private boolean parseParam(PsiBuilder builder) {
}

PsiBuilder.Marker integerMarker = builder.mark();
if (parseLeafToken(builder, INTEGER)) {
if (parseLeafToken(builder, NUMBER)) {
integerMarker.drop();
paramMarker.done(PARAM);
return true;
Expand Down Expand Up @@ -590,7 +590,7 @@ private boolean parseHashSegments(PsiBuilder builder) {
* hashSegment
* : ID EQUALS path
* | ID EQUALS STRING
* | ID EQUALS INTEGER
* | ID EQUALS NUMBER
* | ID EQUALS BOOLEAN
* | ID EQUALS dataName
* ;
Expand All @@ -609,7 +609,7 @@ && parseLeafToken(builder, EQUALS)
* partialName
* : path
* | STRING
* | INTEGER
* | NUMBER
* ;
*/
private boolean parsePartialName(PsiBuilder builder) {
Expand All @@ -635,7 +635,7 @@ private boolean parsePartialName(PsiBuilder builder) {
}

PsiBuilder.Marker integerMarker = builder.mark();
if (parseLeafToken(builder, INTEGER)) {
if (parseLeafToken(builder, NUMBER)) {
integerMarker.drop();
partialNameMarker.done(PARTIAL_NAME);
return true;
Expand Down Expand Up @@ -702,7 +702,7 @@ private boolean parsePath(PsiBuilder builder) {
* : <epsilon>
* | SEP ID pathSegments'
*/
private boolean parsePathSegments(PsiBuilder builder) {
protected boolean parsePathSegments(PsiBuilder builder) {
PsiBuilder.Marker pathSegmentsMarker = builder.mark();

/* HB_CUSTOMIZATION: see isHashNextLookAhead docs for details */
Expand All @@ -725,7 +725,7 @@ private boolean parsePathSegments(PsiBuilder builder) {
/**
* See {@link #parsePathSegments(com.intellij.lang.PsiBuilder)} for more info on this method
*/
private void parsePathSegmentsPrime(PsiBuilder builder) {
protected void parsePathSegmentsPrime(PsiBuilder builder) {
PsiBuilder.Marker pathSegmentsPrimeMarker = builder.mark();

if (!parseLeafToken(builder, SEP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private HbTokenTypes() {
public static final IElementType CLOSE_UNESCAPED = new HbElementType("CLOSE_UNESCAPED", "hb.parsing.element.expected.close.unescaped");
public static final IElementType ELSE = new HbElementType("ELSE", "");
public static final IElementType BOOLEAN = new HbElementType("BOOLEAN", "hb.parsing.element.expected.boolean");
public static final IElementType INTEGER = new HbElementType("INTEGER", "hb.parsing.element.expected.integer");
public static final IElementType NUMBER = new HbElementType("NUMBER", "hb.parsing.element.expected.integer");
public static final IElementType STRING = new HbElementType("STRING", "hb.parsing.element.expected.string");
public static final IElementType ESCAPE_CHAR = new HbElementType("ESCAPE_CHAR", "");
public static final IElementType INVALID = new HbElementType("INVALID", "hb.parsing.element.expected.invalid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ WhiteSpace = {LineTerminator} | [ \t\f]
"else"/["}"\t \n\x0B\f\r] { return HbTokenTypes.ELSE; } // create a custom token for "else" so that we can highlight it independently of the "{{" but still parse it as an inverse operator
"true"/["}"\t \n\x0B\f\r] { return HbTokenTypes.BOOLEAN; }
"false"/["}"\t \n\x0B\f\r] { return HbTokenTypes.BOOLEAN; }
\-?[0-9]+/[}\t \n\x0B\f\r] { return HbTokenTypes.INTEGER; }
\-?[0-9]+(\.[0-9]+)?/[}\t \n\x0B\f\r] { return HbTokenTypes.NUMBER; }
/*
ID is the inverse of control characters.
Control characters ranges:
Expand Down
8 changes: 4 additions & 4 deletions handlebars/test/data/parser/MustachesWithHashArguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ HbFile:MustachesWithHashArguments.hbs
HbPsiElementImpl([Hb] EQUALS)
PsiElement([Hb] EQUALS)('=')
HbParamImpl(PARAM)
HbPsiElementImpl([Hb] INTEGER)
PsiElement([Hb] INTEGER)('1')
HbPsiElementImpl([Hb] NUMBER)
PsiElement([Hb] NUMBER)('1')
HbPsiElementImpl([Hb] CLOSE)
PsiElement([Hb] CLOSE)('}}')
PsiWhiteSpace('\n')
Expand Down Expand Up @@ -203,8 +203,8 @@ HbFile:MustachesWithHashArguments.hbs
HbPsiElementImpl([Hb] EQUALS)
PsiElement([Hb] EQUALS)('=')
HbParamImpl(PARAM)
HbPsiElementImpl([Hb] INTEGER)
PsiElement([Hb] INTEGER)('1')
HbPsiElementImpl([Hb] NUMBER)
PsiElement([Hb] NUMBER)('1')
HbPsiElementImpl([Hb] CLOSE)
PsiElement([Hb] CLOSE)('}}')
PsiWhiteSpace('\n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ HbFile:MustachesWithIntegerParameters.hbs
PsiElement([Hb] ID)('foo')
PsiWhiteSpace(' ')
HbParamImpl(PARAM)
HbPsiElementImpl([Hb] INTEGER)
PsiElement([Hb] INTEGER)('1')
HbPsiElementImpl([Hb] NUMBER)
PsiElement([Hb] NUMBER)('1')
HbPsiElementImpl([Hb] CLOSE)
PsiElement([Hb] CLOSE)('}}')
1 change: 1 addition & 0 deletions handlebars/test/data/parser/ParamWithDecimal.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{name 10.1}}
15 changes: 15 additions & 0 deletions handlebars/test/data/parser/ParamWithDecimal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HbFile:ParamWithDecimal.hbs
HbStatementsImpl(STATEMENTS)
HbSimpleMustacheImpl(MUSTACHE)
HbPsiElementImpl([Hb] OPEN)
PsiElement([Hb] OPEN)('{{')
HbMustacheNameImpl(MUSTACHE_NAME)
HbPathImpl(PATH)
HbPsiElementImpl([Hb] ID)
PsiElement([Hb] ID)('name')
PsiWhiteSpace(' ')
HbParamImpl(PARAM)
HbPsiElementImpl([Hb] NUMBER)
PsiElement([Hb] NUMBER)('10.1')
HbPsiElementImpl([Hb] CLOSE)
PsiElement([Hb] CLOSE)('}}')
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,22 @@ public void testOpenCloseUnescapedWhitespaceStrip() {
result = tokenize("{{~{ foo }~}}");
result.shouldMatchTokenTypes(OPEN_UNESCAPED, WHITE_SPACE, ID, WHITE_SPACE, CLOSE_UNESCAPED);
}

public void testDecimalNumberAsMustacheParam() {
TokenizerResult result = tokenize("{{name 10.123}}");
result.shouldMatchTokenTypes(OPEN, ID, WHITE_SPACE, NUMBER, CLOSE);
result.shouldMatchTokenContent("{{", "name", " ", "10.123", "}}");
}

public void testThreeDecimalNumberAsMustacheParam() {
TokenizerResult result = tokenize("{{name 42 10.1 42}}");
result.shouldMatchTokenTypes(OPEN, ID, WHITE_SPACE, NUMBER, WHITE_SPACE, NUMBER, WHITE_SPACE, NUMBER, CLOSE);
result.shouldMatchTokenContent("{{", "name", " ", "42", " ", "10.1", " ", "42", "}}");
}

public void testDecimalNumberAsMustacheHashParam() {
TokenizerResult result = tokenize("{{name paramValue=10.1}}");
result.shouldMatchTokenTypes(OPEN, ID, WHITE_SPACE, ID, EQUALS, NUMBER, CLOSE);
result.shouldMatchTokenContent("{{", "name", " ", "paramValue", "=", "10.1", "}}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ public void testUnclosedSimpleComment() {
public void testUnclosedBlockComment() {
doTest(true);
}

public void testParamWithDecimal() {
doTest(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ public void testTokenizeMustacheWithStringParamWithEscapeQuotes() {
*/
public void testTokenizesNumbers() {
TokenizerResult result = tokenize("{{ foo 1 }}");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, INTEGER, WHITE_SPACE, CLOSE);
result.shouldBeToken(4, INTEGER, "1");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, NUMBER, WHITE_SPACE, CLOSE);
result.shouldBeToken(4, NUMBER, "1");

result = tokenize("{{ foo -1 }}");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, INTEGER, WHITE_SPACE, CLOSE);
result.shouldBeToken(4, INTEGER, "-1");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, NUMBER, WHITE_SPACE, CLOSE);
result.shouldBeToken(4, NUMBER, "-1");
}

/**
Expand All @@ -388,7 +388,7 @@ public void testTokenizeHashArguments() {
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, ID, WHITE_SPACE, ID, EQUALS, ID, WHITE_SPACE, CLOSE);

result = tokenize("{{ foo bar baz=1 }}");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, ID, WHITE_SPACE, ID, EQUALS, INTEGER, WHITE_SPACE, CLOSE);
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, ID, WHITE_SPACE, ID, EQUALS, NUMBER, WHITE_SPACE, CLOSE);

result = tokenize("{{ foo bar baz=true }}");
result.shouldMatchTokenTypes(OPEN, WHITE_SPACE, ID, WHITE_SPACE, ID, WHITE_SPACE, ID, EQUALS, BOOLEAN, WHITE_SPACE, CLOSE);
Expand Down

0 comments on commit caeef17

Please sign in to comment.