Skip to content

Commit

Permalink
Add method for create an array by square bracket expression (#1926)
Browse files Browse the repository at this point in the history
* create Array via [...]

* add more tests

* more test on array create and index access

* fix a typo
  • Loading branch information
cosmicshuai authored Mar 23, 2020
1 parent e346703 commit 32b751e
Show file tree
Hide file tree
Showing 10 changed files with 2,240 additions and 2,143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ NEWLINE : '\r'? '\n' -> skip;

STRING : ('\'' (~'\'')* '\'') | ('"' (~'"')* '"');

CONSTANT : ('[' WHITESPACE* ']') | ('{' WHITESPACE* '}');
CONSTANT : ('{' WHITESPACE* '}');

INVALID_TOKEN_DEFAULT_MODE : . ;

Expand All @@ -77,6 +77,4 @@ TEMPLATE : '$' '{' (STRING | ~[\r\n{}'"])*? '}';
ESCAPE_CHARACTER : '\\' ~[\r\n]?;
TEXT_CONTENT : '\\`' | ~[\r\n];
TEXT_CONTENT : '\\`' | ~[\r\n];
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ expression

primaryExpression
: OPEN_BRACKET expression CLOSE_BRACKET #parenthesisExp
| OPEN_SQUARE_BRACKET argsList? CLOSE_SQUARE_BRACKET #arrayCreationExp
| CONSTANT #constantAtom
| NUMBER #numericAtom
| STRING #stringAtom
| IDENTIFIER #idAtom
| stringInterpolation #stringInterpolationAtom
| primaryExpression DOT IDENTIFIER #memberAccessExp
| primaryExpression NON? OPEN_BRACKET argsList? CLOSE_BRACKET #funcInvokeExp
| primaryExpression NON? OPEN_BRACKET argsList? CLOSE_BRACKET #funcInvokeExp
| primaryExpression OPEN_SQUARE_BRACKET expression CLOSE_SQUARE_BRACKET #indexAccessExp
;

Expand Down
5 changes: 5 additions & 0 deletions libraries/adaptive-expressions/src/parser/expressionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export class ExpressionParser implements ExpressionParserInterface {

public visitParenthesisExp = (context: ep.ParenthesisExpContext): Expression => this.visit(context.expression());

public visitArrayCreationExp(context: ep.ArrayCreationExpContext): Expression {
const parameters: Expression[] = this.processArgsList(context.argsList());
return this.makeExpression(ExpressionType.CreateArray, ...parameters);
}

public visitStringAtom(context: ep.StringAtomContext): Expression {
const text: string = context.text;
if (text.startsWith('\'')) {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 32b751e

Please sign in to comment.