Skip to content

Commit

Permalink
StepFunctions: Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Aug 6, 2024
1 parent 769a426 commit 9da88ee
Show file tree
Hide file tree
Showing 46 changed files with 16,708 additions and 15,840 deletions.
2 changes: 1 addition & 1 deletion moto/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
def relative_error_type(self) -> str:
# https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html
# If a # character is present, then take only the contents after the first # character in the value
return self.error_type.split("#")[-1]
return (self.error_type.split("#")[-1]) if self.error_type else ""

def get_body(self, *args: Any, **kwargs: Any) -> str:
return self.description
Expand Down
114 changes: 47 additions & 67 deletions moto/stepfunctions/parser/asl/antlr/ASLIntrinsicLexer.g4
Original file line number Diff line number Diff line change
@@ -1,79 +1,59 @@
// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true

lexer grammar ASLIntrinsicLexer;

DOLLAR: '$';
DOT: '.';
STAR: '*';
COMMA: ',';
LPAREN: '(';
RPAREN: ')';
LBRACK: '[';
RBRACK: ']';
LDIAM: '<';
RDIAM: '>';
ATDOT: '@.';
ATDOTLENGTHDASH: '@.length-';
ANDAND: '&&';
OROR: '||';
EQEQ: '==';
EQ: '=';
CONTEXT_PATH_STRING: DOLLAR DOLLAR JSON_PATH_BODY;

JSON_PATH_STRING: DOLLAR JSON_PATH_BODY;

fragment JSON_PATH_BODY: JSON_PATH_BRACK? (DOT IDENTIFIER? JSON_PATH_BRACK?)*;

fragment JSON_PATH_BRACK: '[' (JSON_PATH_BRACK | ~[\]])* ']';

TRUE: 'true';
FALSE: 'false';
DOLLAR : '$';
LPAREN : '(';
RPAREN : ')';
COMMA : ',';
DOT : '.';

States: 'States';
Format: 'Format';
StringToJson: 'StringToJson';
JsonToString: 'JsonToString';
Array: 'Array';
ArrayPartition: 'ArrayPartition';
ArrayContains: 'ArrayContains';
ArrayRange: 'ArrayRange';
ArrayGetItem: 'ArrayGetItem';
ArrayLength: 'ArrayLength';
ArrayUnique: 'ArrayUnique';
Base64Encode: 'Base64Encode';
Base64Decode: 'Base64Decode';
Hash: 'Hash';
JsonMerge: 'JsonMerge';
MathRandom: 'MathRandom';
MathAdd: 'MathAdd';
StringSplit: 'StringSplit';
UUID: 'UUID';
TRUE : 'true';
FALSE : 'false';

States : 'States';
Format : 'Format';
StringToJson : 'StringToJson';
JsonToString : 'JsonToString';
Array : 'Array';
ArrayPartition : 'ArrayPartition';
ArrayContains : 'ArrayContains';
ArrayRange : 'ArrayRange';
ArrayGetItem : 'ArrayGetItem';
ArrayLength : 'ArrayLength';
ArrayUnique : 'ArrayUnique';
Base64Encode : 'Base64Encode';
Base64Decode : 'Base64Decode';
Hash : 'Hash';
JsonMerge : 'JsonMerge';
MathRandom : 'MathRandom';
MathAdd : 'MathAdd';
StringSplit : 'StringSplit';
UUID : 'UUID';

STRING
: '\'' (ESC | SAFECODEPOINT)*? '\''
;
STRING: '\'' (ESC | SAFECODEPOINT)*? '\'';

fragment ESC
: '\\' (UNICODE | .)
;
fragment UNICODE
: 'u' HEX HEX HEX HEX
;
fragment HEX
: [0-9a-fA-F]
;
fragment SAFECODEPOINT
: ~ ['\\\u0000-\u001F]
;
fragment ESC : '\\' (UNICODE | .);
fragment UNICODE : 'u' HEX HEX HEX HEX;
fragment HEX : [0-9a-fA-F];
fragment SAFECODEPOINT : ~ ['\\\u0000-\u001F];
INT
: '-'? ('0' | [1-9] [0-9]*)
;
INT: '-'? ('0' | [1-9] [0-9]*);
NUMBER
: '-'? INT ('.' [0-9] +)? EXP?
;
NUMBER: '-'? INT ('.' [0-9]+)? EXP?;
fragment EXP
: [Ee] [+\-]? INT
;
fragment EXP: [Ee] [+\-]? INT;
IDENTIFIER
: ([0-9a-zA-Z_] | UNICODE)+
;
IDENTIFIER: ([0-9a-zA-Z_] | UNICODE)+;
WS
: [ \t\n] + -> skip
;
WS: [ \t\n]+ -> skip;
90 changes: 22 additions & 68 deletions moto/stepfunctions/parser/asl/antlr/ASLIntrinsicParser.g4
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true

parser grammar ASLIntrinsicParser;

options {
tokenVocab=ASLIntrinsicLexer;
tokenVocab = ASLIntrinsicLexer;
}

func_decl
: states_func_decl
;
func_decl: states_func_decl EOF;

states_func_decl
: States DOT state_fun_name func_arg_list
;
states_func_decl: States DOT state_fun_name func_arg_list;

state_fun_name
: Format
state_fun_name:
Format
| StringToJson
| JsonToString
| Array
Expand All @@ -31,62 +31,16 @@ state_fun_name
| MathAdd
| StringSplit
| UUID
;

func_arg_list
: LPAREN func_arg (COMMA func_arg)* RPAREN
| LPAREN RPAREN
;

func_arg
: STRING #func_arg_string
| INT #func_arg_int
| NUMBER #func_arg_float
| (TRUE | FALSE) #func_arg_bool
| context_path #func_arg_context_path
| json_path #func_arg_json_path
| func_decl #func_arg_func_decl
;

context_path
: DOLLAR json_path
;

json_path
: DOLLAR DOT json_path_part (DOT json_path_part)*
;

json_path_part
: json_path_iden
| json_path_iden_qual
;

json_path_iden
: identifier
;

json_path_iden_qual
: json_path_iden json_path_qual
;

json_path_qual
: LBRACK RBRACK #json_path_qual_void
| LBRACK INT RBRACK #json_path_qual_idx
| LBRACK json_path_query RBRACK #json_path_qual_query
;

json_path_query
: STAR # json_path_query_star
| ATDOT json_path_iden
( (LDIAM | RDIAM | EQEQ) INT
| EQ STRING
) # json_path_query_cmp
| ATDOTLENGTHDASH INT # json_path_query_length
| json_path_query ((ANDAND | OROR) json_path_query)+ # json_path_query_binary
;

identifier
: IDENTIFIER
// States.
| state_fun_name
;
;

func_arg_list: LPAREN func_arg (COMMA func_arg)* RPAREN | LPAREN RPAREN;

func_arg:
STRING # func_arg_string
| INT # func_arg_int
| NUMBER # func_arg_float
| (TRUE | FALSE) # func_arg_bool
| CONTEXT_PATH_STRING # func_arg_context_path
| JSON_PATH_STRING # func_arg_json_path
| states_func_decl # func_arg_func_decl
;
Loading

0 comments on commit 9da88ee

Please sign in to comment.