File tree Expand file tree Collapse file tree
antlr4/com/github/jknack/handlebars/internal
java/com/github/jknack/handlebars/internal
test/java/com/github/jknack/handlebars/issues Expand file tree Collapse file tree Original file line number Diff line number Diff line change 280280 ' ='
281281 ;
282282
283- INT
283+ NUMBER
284284 :
285- ' -' ? [0-9]+
285+ ' -' ? [0-9]* ' . ' ? [0-9] +
286286 ;
287287
288288BOOLEAN
Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ param
179179 :
180180 DOUBLE_STRING #stringParam
181181 | SINGLE_STRING #charParam
182- | INT #intParam
182+ | NUMBER #numberParam
183183 | BOOLEAN #boolParam
184184 | QID #refParam
185185 | LP sexpr RP #subParamExpr
Original file line number Diff line number Diff line change 5656import com .github .jknack .handlebars .internal .HbsParser .ElseStmtContext ;
5757import com .github .jknack .handlebars .internal .HbsParser .EscapeContext ;
5858import com .github .jknack .handlebars .internal .HbsParser .HashContext ;
59- import com .github .jknack .handlebars .internal .HbsParser .IntParamContext ;
6059import com .github .jknack .handlebars .internal .HbsParser .LiteralPathContext ;
6160import com .github .jknack .handlebars .internal .HbsParser .NewlineContext ;
6261import com .github .jknack .handlebars .internal .HbsParser .ParamContext ;
@@ -504,9 +503,12 @@ public Object visitRefParam(final RefParamContext ctx) {
504503 return new RefParam (PathCompiler .compile (ctx .getText (), handlebars .parentScopeResolution ()));
505504 }
506505
507- @ Override
508- public Object visitIntParam (final IntParamContext ctx ) {
509- return new DefParam (Integer .parseInt (ctx .getText ()));
506+ @ Override public Object visitNumberParam (HbsParser .NumberParamContext ctx ) {
507+ try {
508+ return new DefParam (Integer .parseInt (ctx .getText ()));
509+ } catch (NumberFormatException x ) {
510+ return new DefParam (Double .parseDouble (ctx .getText ()));
511+ }
510512 }
511513
512514 @ Override
Original file line number Diff line number Diff line change 1+ package com .github .jknack .handlebars .issues ;
2+
3+ import com .github .jknack .handlebars .v4Test ;
4+ import org .junit .Test ;
5+
6+ import java .util .Arrays ;
7+
8+ public class Issue573 extends v4Test {
9+
10+ @ Test
11+ public void shouldSupportNumberExpression () throws Exception {
12+ shouldCompileTo ("{{#if 1.5}}OK{{/if}}" , $ , "OK" );
13+ shouldCompileTo ("{{#if 0.5}}OK{{/if}}" , $ , "OK" );
14+ shouldCompileTo ("{{#if .6}}OK{{/if}}" , $ , "OK" );
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments