Skip to content

Commit 8eaabbd

Browse files
authored
add base implementation of intrinsic functions (#7526)
1 parent 499e7bd commit 8eaabbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3136
-855
lines changed
Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
1-
// TODO: playground lexer.
2-
31
lexer grammar ASLIntrinsicLexer;
42

5-
DOLLAR: '$';
6-
DDOLLAR: '$$';
3+
DOLLARDOT: '$.';
74
DOT: '.';
5+
STAR: '*';
86
COMMA: ',';
97
LPAREN: '(';
108
RPAREN: ')';
119
LBRACK: '[';
1210
RBRACK: ']';
13-
LBRACE: '{';
14-
RBRACE: '}';
11+
LDIAM: '<';
12+
RDIAM: '>';
13+
ATDOT: '@.';
14+
ATDOTLENGTHDASH: '@.length-';
15+
ANDAND: '&&';
16+
OROR: '||';
17+
EQEQ: '==';
18+
EQ: '=';
1519

20+
States: 'States';
21+
Format: 'Format';
22+
StringToJson: 'StringToJson';
23+
JsonToString: 'JsonToString';
24+
Array: 'Array';
25+
ArrayPartition: 'ArrayPartition';
26+
ArrayContains: 'ArrayContains';
27+
ArrayRange: 'ArrayRange';
28+
ArrayGetItem: 'ArrayGetItem';
29+
ArrayLength: 'ArrayLength';
30+
ArrayUnique: 'ArrayUnique';
31+
Base64Encode: 'Base64Encode';
32+
Base64Decode: 'Base64Decode';
33+
Hash: 'Hash';
34+
JsonMerge: 'JsonMerge';
35+
MathRandom: 'MathRandom';
36+
MathAdd: 'MathAdd';
37+
StringSplit: 'StringSplit';
38+
UUID: 'UUID';
1639

17-
IDENTIFIER
18-
: ([0-9a-zA-Z_] | UNICODE)+
19-
;
2040

21-
// TODO
2241
STRING
23-
: '\\"' (ESC | SAFECODEPOINT)* '\\"'
42+
: '\'' (ESC | SAFECODEPOINT)* '\''
2443
;
2544

26-
2745
fragment ESC
2846
: '\\' (["\\/bfnrt] | UNICODE)
2947
;
@@ -37,20 +55,22 @@ fragment SAFECODEPOINT
3755
: ~ ["\\\u0000-\u001F]
3856
;
3957

58+
INT
59+
: '0' | [1-9] [0-9]*
60+
;
4061

4162
NUMBER
4263
: '-'? INT ('.' [0-9] +)? EXP?
4364
;
4465

45-
46-
fragment INT
47-
: '0' | [1-9] [0-9]*
48-
;
49-
5066
fragment EXP
5167
: [Ee] [+\-]? INT
5268
;
5369

70+
IDENTIFIER
71+
: ([0-9a-zA-Z_] | UNICODE)+
72+
;
73+
5474
WS
55-
: [ \t] + -> skip
75+
: [ \t\n] + -> skip
5676
;
Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,86 @@
1-
// TODO: playground grammar.
2-
31
parser grammar ASLIntrinsicParser;
42

53
options {
64
tokenVocab=ASLIntrinsicLexer;
75
}
86

9-
// TODO.
10-
compilation_unit
11-
: ( member
12-
| member_access
13-
)+
14-
EOF?
7+
func_decl
8+
: states_func_decl
9+
;
10+
11+
states_func_decl
12+
: States DOT state_fun_name func_arg_list
13+
;
14+
15+
state_fun_name
16+
: Format
17+
| StringToJson
18+
| JsonToString
19+
| Array
20+
| ArrayPartition
21+
| ArrayContains
22+
| ArrayRange
23+
| ArrayGetItem
24+
| ArrayLength
25+
| ArrayUnique
26+
| Base64Encode
27+
| Base64Decode
28+
| Hash
29+
| JsonMerge
30+
| MathRandom
31+
| MathAdd
32+
| StringSplit
33+
| UUID
34+
;
35+
36+
func_arg_list
37+
: LPAREN func_arg (COMMA func_arg)* RPAREN
38+
| LPAREN RPAREN
39+
;
40+
41+
func_arg
42+
: STRING #func_arg_string
43+
| INT #func_arg_int
44+
| NUMBER #func_arg_float
45+
| json_path #func_arg_json_path
46+
| func_decl #func_arg_func_decl
47+
;
48+
49+
json_path
50+
: DOLLARDOT json_path_part (DOT json_path_part)*
51+
;
52+
53+
json_path_part
54+
: json_path_iden
55+
| json_path_iden_qual
56+
;
57+
58+
json_path_iden
59+
: identifier
60+
;
61+
62+
json_path_iden_qual
63+
: json_path_iden json_path_qual
64+
;
65+
66+
json_path_qual
67+
: LBRACK RBRACK #json_path_qual_void
68+
| LBRACK INT RBRACK #json_path_qual_idx
69+
| LBRACK json_path_query RBRACK #json_path_qual_query
1570
;
1671

17-
// TODO. func calls, args, etc.
18-
// TODO json paths https://github.com/json-path/JsonPath
19-
member_access
20-
: member DOT (member | member_access)
72+
json_path_query
73+
: STAR # json_path_query_star
74+
| ATDOT json_path_iden
75+
( (LDIAM | RDIAM | EQEQ) INT
76+
| EQ STRING
77+
) # json_path_query_cmp
78+
| ATDOTLENGTHDASH INT # json_path_query_length
79+
| json_path_query ((ANDAND | OROR) json_path_query)+ # json_path_query_binary
2180
;
2281

23-
member
24-
: DOLLAR
25-
| IDENTIFIER
82+
identifier
83+
: IDENTIFIER
84+
// States.
85+
| state_fun_name
2686
;

localstack/services/stepfunctions/asl/antlr/ASLLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ STRINGPATHCONTEXTOBJ
140140
;
141141

142142
STRINGPATH
143-
: '"$.' (ESC | SAFECODEPOINT)* '"'
143+
: '"$' (ESC | SAFECODEPOINT)* '"'
144144
;
145145

146146
STRING

localstack/services/stepfunctions/asl/antlr/runtime/ASLIntrinsicLexer.interp

Lines changed: 93 additions & 16 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)