Skip to content
Open
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
41 changes: 41 additions & 0 deletions antlr4/CwlEcmaStringLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
lexer grammar CwlEcmaStringLexer;

ANYCHAR: .;
DOLLARPAREN: '$(' -> pushMode(ParenExpr);
LPAREN: '(';
RPAREN: ')';
DOLLARBRACE: '${' -> pushMode(BraceExpr);
LBRACE: '{';
RBRACE: '}';
DOLLARPARENESC: '\\$(';
DOLLARBRACEESC: '\\${';
BACKSLASH: '\\';
BACKSLASHESC: '\\\\';

mode ParenExpr;

EscPart: BACKSLASH ANYCHAR;
SubExprStart: LPAREN -> pushMode(SubExpr);
ExprEnd: RPAREN -> popMode;
ExprPart: ~[)];

mode SubExpr;

SubEscPart: BACKSLASH ANYCHAR -> type(SubExprPart);
SubSubExprStart: LPAREN -> pushMode(SubExpr);
SubExprEnd: RPAREN -> popMode;
SubExprPart: ~[)];

mode BraceExpr;

BraceEscPart: BACKSLASH ANYCHAR -> type(EscPart);
BraceSubExprStart: LBRACE -> pushMode(BraceSubExpr), type(SubExprStart);
BraceExprEnd: RBRACE -> popMode, type(ExprEnd);
BraceExprPart: ~[}] -> type(ExprPart);

mode BraceSubExpr;

BraceSubEscPart: BACKSLASH ANYCHAR -> type(SubExprPart);
BraceSubSubExprStart: LBRACE -> pushMode(BraceSubExpr), type(SubSubExprStart);
BraceSubExprEnd: RBRACE -> popMode, type(SubExprEnd);
BraceSubExprPart: ~[}] -> type(SubExprPart);
45 changes: 45 additions & 0 deletions antlr4/CwlEcmaStringParser.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
parser grammar CwlEcmaStringParser;

options {
tokenVocab=CwlEcmaStringLexer;
}

sub_sub_expr
: SubSubExprStart sub_expr_part* SubExprEnd
;

sub_expr_part
: SubExprPart
| sub_sub_expr
;

sub_expr
: SubExprStart sub_expr_part* SubExprEnd
;

expr_part
: ExprPart
| EscPart
| sub_expr
;

paren_expr
: DOLLARPAREN expr_part+ ExprEnd
;

brace_expr
: DOLLARBRACE expr_part+ ExprEnd
;

interpolated_string_part
: BACKSLASHESC
| DOLLARPARENESC
| DOLLARBRACEESC
| paren_expr
| brace_expr
| ANYCHAR
;

interpolated_string
: interpolated_string_part+
;
67 changes: 67 additions & 0 deletions antlr4/CwlParameterReferenceLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
lexer grammar CwlParameterReferenceLexer;

DOT: '.';
LBRACKET: '[';
RBRACKET: ']';
DOLLARPAREN: '$(' -> pushMode(ParenExpr);
RPAREN: ')';
DOLLARPARENESC: '\\$(';
BACKSLASH: '\\';
BACKSLASHESC: '\\\\';
ANYCHAR: .;
LBRACKETSINGLEQ: '[\'';
LBRACKETDOUBLEQ: '["';
SINGLEQRBRACKET: '\']';
DOUBLEQRBRACKET: '"]';

mode ParenExpr;

ExprDot: DOT;
ExprSymbol: CompleteSymbol;
ExprSingleQ: LBRACKETSINGLEQ -> pushMode(SingleQString);
ExprDoubleQ: LBRACKETDOUBLEQ -> pushMode(DoubleQString);
ExprIntIndex: LBRACKET -> pushMode(IntIndex);
EndParenExpr: RPAREN -> popMode;

mode SingleQString;

StringIndexEscPart: BACKSLASH ANYCHAR;
EndSingleQ: SINGLEQRBRACKET -> popMode, type(ExprSingleQ);
StringIndexPart: ~[\\']+;
LiteralBackslash: BACKSLASH -> type(StringIndexPart);

mode DoubleQString;

DoubleQEscapedChar: BACKSLASH ANYCHAR -> type(StringIndexEscPart);
EndDoubleQ: DOUBLEQRBRACKET -> popMode, type(ExprDoubleQ);
DoubleQStringIndexPart: ~[\\"]+ -> type(StringIndexPart);
DoubleQLiteralBackslash: BACKSLASH -> type(StringIndexPart);

mode IntIndex;

EndIndex: RBRACKET -> popMode, type(ExprIntIndex);
IntIndexPart: DecimalNumber;

fragment CompleteSymbol
: SymbolStart SymbolFollow*
;

fragment SymbolStart
: [a-zA-Z]
;

fragment SymbolFollow
: [a-zA-Z0-9_]+
;

fragment DecimalNumber
: DecimalDigit+
;

fragment DecimalDigit
: [0-9]
;

fragment HexDigit
: [0-9a-fA-F]
;
44 changes: 44 additions & 0 deletions antlr4/CwlParameterReferenceParser.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
parser grammar CwlParameterReferenceParser;

options {
tokenVocab=CwlParameterReferenceLexer;
}

expr_dot_symbol
: ExprDot ExprSymbol
;

int_index
: ExprIntIndex IntIndexPart ExprIntIndex
;

string_index_part
: StringIndexPart
| StringIndexEscPart
;

string_index
: ExprSingleQ string_index_part+ ExprSingleQ
| ExprDoubleQ string_index_part+ ExprDoubleQ
;

expr_segment
: expr_dot_symbol
| int_index
| string_index
;

paren_expr
: DOLLARPAREN ExprSymbol expr_segment* EndParenExpr
;

interpolated_string_part
: BACKSLASHESC
| DOLLARPARENESC
| paren_expr
| ANYCHAR
;

interpolated_string
: interpolated_string_part+
;