Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions oap-formats/oap-template/src/main/antlr4/TemplateGrammar.g4
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package oap.template;
import oap.template.tree.*;
import oap.template.tree.BlockIfElement;
import oap.template.tree.BlockWithElement;
import oap.template.tree.BlockRangeElement;

import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -40,6 +41,7 @@ element[Map<String,String> aliases] returns [Element ret]
| expression[aliases] { $ret = new ExpressionElement( $expression.ret, $expression.trimLeft, $expression.trimRight ); }
| blockIfElement[aliases] { $ret = $blockIfElement.ret; }
| blockWithElement[aliases] { $ret = $blockWithElement.ret; }
| blockRangeElement[aliases] { $ret = $blockRangeElement.ret; }
;

blockIfElement[Map<String,String> aliases] returns [BlockIfElement ret]
Expand Down Expand Up @@ -69,6 +71,20 @@ blockWithElement[Map<String,String> aliases] returns [BlockWithElement ret]
}
;

blockRangeElement[Map<String,String> aliases] returns [BlockRangeElement ret]
: STARTBLOCKRANGE BLOCK_IF_CONTENT BLOCK_IF_RBRACE
thenBranch=blockBody[aliases]
( STARTBLOCKELSE elseBranch=blockBody[aliases] )?
STARTBLOCKEND
{
$ret = new BlockRangeElement(
StringUtils.trim( $BLOCK_IF_CONTENT.text ),
$thenBranch.ret,
$elseBranch.ctx != null ? $elseBranch.ret : null
);
}
;

blockBody[Map<String,String> aliases] returns [Elements ret = new Elements()]
: ( element[aliases]
{ if( $element.ret != null ) $ret.elements.add( $element.ret ); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ exprs returns [Exprs ret = new Exprs()]
: ROOT DOT expr { $ret.rootScoped = true; $ret.exprs.add( $expr.ret ); }
(DOT expr { $ret.exprs.add( $expr.ret ); })*
math? { if( $math.ctx != null ) $ret.math = $math.ret; }
| VAR_ID { $ret.varName = $VAR_ID.text.substring( 1 ); }
(DOT expr { $ret.exprs.add( $expr.ret ); })*
math? { if( $math.ctx != null ) $ret.math = $math.ret; }
| expr { $ret.exprs.add( $expr.ret ); }
math? { if( $math.ctx != null ) $ret.math = $math.ret; }
| expr { $ret.exprs.add( $expr.ret ); }
Expand Down
1 change: 1 addition & 0 deletions oap-formats/oap-template/src/main/antlr4/TemplateLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fragment EndExpr2 : '}}' ;



STARTBLOCKRANGE : '{{%' [ \t]* 'range' [ \t]+ -> pushMode(BlockIfContent) ;
STARTBLOCKWITH : '{{%' [ \t]* 'with' [ \t]+ -> pushMode(BlockIfContent) ;
STARTBLOCKIF_LTRIM : '{{%-' [ \t]* 'if' [ \t]+ -> pushMode(BlockIfContent) ;
STARTBLOCKIF : '{{%' [ \t]* 'if' [ \t]+ -> pushMode(BlockIfContent) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ THEN : 'then' ;
ELSE : 'else' ;
END : 'end' ;
WITH : 'with' ;
VAR_ID : '$' NameChar (NameChar|DecDigit)* ;
ROOT : '$' ;

BLOCK_COMMENT : BlockComment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ null
null
null
null
null
'{{-'
null
null
Expand All @@ -22,6 +23,7 @@ null

token symbolic names:
null
STARTBLOCKRANGE
STARTBLOCKWITH
STARTBLOCKIF_LTRIM
STARTBLOCKIF
Expand All @@ -47,6 +49,7 @@ elements
element
blockIfElement
blockWithElement
blockRangeElement
blockBody
text
comment
Expand All @@ -55,4 +58,4 @@ expressionContent


atn:
[4, 1, 19, 91, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0,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0, 0, 34, 35, 3, 14, 7, 0, 35, 36, 6, 1, -1, 0, 36, 44, 1, 0, 0, 0, 37, 38, 3, 4, 2, 0, 38, 39, 6, 1, -1, 0, 39, 44, 1, 0, 0, 0, 40, 41, 3, 6, 3, 0, 41, 42, 6, 1, -1, 0, 42, 44, 1, 0, 0, 0, 43, 28, 1, 0, 0, 0, 43, 31, 1, 0, 0, 0, 43, 34, 1, 0, 0, 0, 43, 37, 1, 0, 0, 0, 43, 40, 1, 0, 0, 0, 44, 3, 1, 0, 0, 0, 45, 46, 7, 0, 0, 0, 46, 47, 5, 18, 0, 0, 47, 48, 5, 19, 0, 0, 48, 51, 3, 8, 4, 0, 49, 50, 5, 4, 0, 0, 50, 52, 3, 8, 4, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 54, 5, 5, 0, 0, 54, 55, 6, 2, -1, 0, 55, 5, 1, 0, 0, 0, 56, 57, 5, 1, 0, 0, 57, 58, 5, 18, 0, 0, 58, 59, 5, 19, 0, 0, 59, 60, 3, 8, 4, 0, 60, 61, 5, 5, 0, 0, 61, 62, 6, 3, -1, 0, 62, 7, 1, 0, 0, 0, 63, 64, 3, 2, 1, 0, 64, 65, 6, 4, -1, 0, 65, 67, 1, 0, 0, 0, 66, 63, 1, 0, 0, 0, 67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 9, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 73, 5, 10, 0, 0, 72, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 11, 1, 0, 0, 0, 76, 77, 5, 6, 0, 0, 77, 78, 3, 16, 8, 0, 78, 79, 5, 12, 0, 0, 79, 13, 1, 0, 0, 0, 80, 81, 7, 1, 0, 0, 81, 82, 3, 16, 8, 0, 82, 83, 7, 2, 0, 0, 83, 84, 6, 7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, 68, 1, 0, 0, 0, 10, 84, 1, 0, 0, 0, 12, 88, 1, 0, 0, 0, 14, 92, 1, 0, 0, 0, 16, 96, 1, 0, 0, 0, 18, 102, 1, 0, 0, 0, 20, 21, 3, 2, 1, 0, 21, 22, 6, 0, -1, 0, 22, 24, 1, 0, 0, 0, 23, 20, 1, 0, 0, 0, 24, 27, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 28, 1, 0, 0, 0, 27, 25, 1, 0, 0, 0, 28, 29, 5, 0, 0, 1, 29, 1, 1, 0, 0, 0, 30, 31, 3, 12, 6, 0, 31, 32, 6, 1, -1, 0, 32, 49, 1, 0, 0, 0, 33, 34, 3, 14, 7, 0, 34, 35, 6, 1, -1, 0, 35, 49, 1, 0, 0, 0, 36, 37, 3, 16, 8, 0, 37, 38, 6, 1, -1, 0, 38, 49, 1, 0, 0, 0, 39, 40, 3, 4, 2, 0, 40, 41, 6, 1, -1, 0, 41, 49, 1, 0, 0, 0, 42, 43, 3, 6, 3, 0, 43, 44, 6, 1, -1, 0, 44, 49, 1, 0, 0, 0, 45, 46, 3, 8, 4, 0, 46, 47, 6, 1, -1, 0, 47, 49, 1, 0, 0, 0, 48, 30, 1, 0, 0, 0, 48, 33, 1, 0, 0, 0, 48, 36, 1, 0, 0, 0, 48, 39, 1, 0, 0, 0, 48, 42, 1, 0, 0, 0, 48, 45, 1, 0, 0, 0, 49, 3, 1, 0, 0, 0, 50, 51, 7, 0, 0, 0, 51, 52, 5, 19, 0, 0, 52, 53, 5, 20, 0, 0, 53, 56, 3, 10, 5, 0, 54, 55, 5, 5, 0, 0, 55, 57, 3, 10, 5, 0, 56, 54, 1, 0, 0, 0, 56, 57, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 59, 5, 6, 0, 0, 59, 60, 6, 2, -1, 0, 60, 5, 1, 0, 0, 0, 61, 62, 5, 2, 0, 0, 62, 63, 5, 19, 0, 0, 63, 64, 5, 20, 0, 0, 64, 65, 3, 10, 5, 0, 65, 66, 5, 6, 0, 0, 66, 67, 6, 3, -1, 0, 67, 7, 1, 0, 0, 0, 68, 69, 5, 1, 0, 0, 69, 70, 5, 19, 0, 0, 70, 71, 5, 20, 0, 0, 71, 74, 3, 10, 5, 0, 72, 73, 5, 5, 0, 0, 73, 75, 3, 10, 5, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 5, 6, 0, 0, 77, 78, 6, 4, -1, 0, 78, 9, 1, 0, 0, 0, 79, 80, 3, 2, 1, 0, 80, 81, 6, 5, -1, 0, 81, 83, 1, 0, 0, 0, 82, 79, 1, 0, 0, 0, 83, 86, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 11, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 87, 89, 5, 11, 0, 0, 88, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 88, 1, 0, 0, 0, 90, 91, 1, 0, 0, 0, 91, 13, 1, 0, 0, 0, 92, 93, 5, 7, 0, 0, 93, 94, 3, 18, 9, 0, 94, 95, 5, 13, 0, 0, 95, 15, 1, 0, 0, 0, 96, 97, 7, 1, 0, 0, 97, 98, 3, 18, 9, 0, 98, 99, 7, 2, 0, 0, 99, 100, 6, 8, -1, 0, 100, 17, 1, 0, 0, 0, 101, 103, 7, 3, 0, 0, 102, 101, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 19, 1, 0, 0, 0, 7, 25, 48, 56, 74, 84, 90, 104]
Loading
Loading