diff --git a/amazon-states-language-intrinsic-functions/ASLIntrinsicLexer.g4 b/amazon-states-language-intrinsic-functions/ASLIntrinsicLexer.g4 new file mode 100644 index 0000000000..77387b912a --- /dev/null +++ b/amazon-states-language-intrinsic-functions/ASLIntrinsicLexer.g4 @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2017+ LocalStack contributors + * Copyright (c) 2016 Atlassian Pty Ltd + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Amazon States Lanaguage (ASL) Grammar for ANTLR v4 + * + * Based on: + * http://github.com/localstack/localstack + * and + * https://states-language.net/spec.html + */ + +// $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; + +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 | ~[\]])* ']'; + +DOLLAR : '$'; +LPAREN : '('; +RPAREN : ')'; +COMMA : ','; +DOT : '.'; + +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)*? '\''; + +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]*); + +NUMBER: '-'? INT ('.' [0-9]+)? EXP?; + +fragment EXP: [Ee] [+\-]? INT; + +IDENTIFIER: ([0-9a-zA-Z_] | UNICODE)+; + +WS: [ \t\n]+ -> skip; \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/ASLIntrinsicParser.g4 b/amazon-states-language-intrinsic-functions/ASLIntrinsicParser.g4 new file mode 100644 index 0000000000..037319559e --- /dev/null +++ b/amazon-states-language-intrinsic-functions/ASLIntrinsicParser.g4 @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2017+ LocalStack contributors + * Copyright (c) 2016 Atlassian Pty Ltd + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Amazon States Lanaguage (ASL) Grammar for ANTLR v4 + * + * Based on: + * http://github.com/localstack/localstack + * and + * https://states-language.net/spec.html + */ + +// $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; +} + +intrinsic_function: states_func_decl EOF; + +states_func_decl: States DOT state_fun_name func_arg_list; + +state_fun_name: + Format + | StringToJson + | JsonToString + | Array + | ArrayPartition + | ArrayContains + | ArrayRange + | ArrayGetItem + | ArrayLength + | ArrayUnique + | Base64Encode + | Base64Decode + | Hash + | JsonMerge + | MathRandom + | 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_STRING # func_arg_context_path + | JSON_PATH_STRING # func_arg_json_path + | states_func_decl # func_arg_func_decl +; \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/README.md b/amazon-states-language-intrinsic-functions/README.md new file mode 100644 index 0000000000..babf0b2d0e --- /dev/null +++ b/amazon-states-language-intrinsic-functions/README.md @@ -0,0 +1,39 @@ +# Amazon States Language Intrinsic Functions ANTLR4 Grammar + +The ANTLR4 grammar for the Intrinsic Functions of Amazon States Language (ASL), initially developed by +[LocalStack](github.com/localstack/localstack). + +The module includes grammars (`ASLIntrinsicLexer.g4` and `ASLIntrinsicParser.g4`) for parsing intrinsic +functions within ASL derivations. + +## License +```txt +Copyright (c) 2017+ LocalStack contributors +Copyright (c) 2016 Atlassian Pty Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` + +## Links + +* [LocalStack](https://github.com/localstack/localstack) - LocalStack, the project +that developed the grammar and an Amazon States Language interpreter. +* [Amazon Language Specification](https://states-language.net/spec.html) - The original +language specification for Amazon States Language provided by Amazon. + + +## Examples +The `examples/` directory contains examples illustrating the utilisation of intrinsic functions. + +## Original source + diff --git a/amazon-states-language-intrinsic-functions/desc.xml b/amazon-states-language-intrinsic-functions/desc.xml new file mode 100644 index 0000000000..26bde4cec2 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/desc.xml @@ -0,0 +1,4 @@ + + + CSharp;Cpp;Dart;Go;Java;JavaScript;PHP;Python3;TypeScript + diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array.txt new file mode 100644 index 0000000000..c64c33fcf2 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array.txt @@ -0,0 +1 @@ +States.Array($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_contains.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_contains.txt new file mode 100644 index 0000000000..4e16236564 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_contains.txt @@ -0,0 +1 @@ +States.ArrayContains($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_get_item.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_get_item.txt new file mode 100644 index 0000000000..1ca712ce1e --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_get_item.txt @@ -0,0 +1 @@ +States.ArrayGetItem($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_length.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_length.txt new file mode 100644 index 0000000000..bb86241275 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_length.txt @@ -0,0 +1 @@ +States.ArrayLength($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_partition.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_partition.txt new file mode 100644 index 0000000000..195a2159a7 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_partition.txt @@ -0,0 +1 @@ +States.ArrayPartition($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_range.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_range.txt new file mode 100644 index 0000000000..1f9f2c65b1 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_range.txt @@ -0,0 +1 @@ +States.ArrayRange($.FunctionInput.fst, $.FunctionInput.snd, $.FunctionInput.trd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_unique.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_unique.txt new file mode 100644 index 0000000000..3282162435 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_unique.txt @@ -0,0 +1 @@ +States.ArrayUnique($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_decode.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_decode.txt new file mode 100644 index 0000000000..4d21217e13 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_decode.txt @@ -0,0 +1 @@ +States.Base64Decode($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_encode.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_encode.txt new file mode 100644 index 0000000000..c08bce4369 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_encode.txt @@ -0,0 +1 @@ +States.Base64Encode($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_format.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_format.txt new file mode 100644 index 0000000000..677d0c4967 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_format.txt @@ -0,0 +1 @@ +States.Format('Formatting arguments fst={} and snd={}.', $.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_hash.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_hash.txt new file mode 100644 index 0000000000..4f8e40543f --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_hash.txt @@ -0,0 +1 @@ +States.Hash($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_merge.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_merge.txt new file mode 100644 index 0000000000..1b416796cf --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_merge.txt @@ -0,0 +1 @@ +States.JsonMerge($.FunctionInput.fst, $.FunctionInput.snd, false) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_to_string.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_to_string.txt new file mode 100644 index 0000000000..f732308869 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_to_string.txt @@ -0,0 +1 @@ +States.JsonToString($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_add.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_add.txt new file mode 100644 index 0000000000..f4620ac4f2 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_add.txt @@ -0,0 +1 @@ +States.MathAdd($.FunctionInput.fst, $.FunctionInput.snd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_random.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_random.txt new file mode 100644 index 0000000000..cbde2a0375 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_random.txt @@ -0,0 +1 @@ +States.MathRandom($.FunctionInput.fst, $.FunctionInput.snd, $.FunctionInput.trd) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_nested_calls.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_nested_calls.txt new file mode 100644 index 0000000000..fc412e7700 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_nested_calls.txt @@ -0,0 +1 @@ +States.ArrayGetItem(States.StringSplit($$.StateMachine.Name, '-'), States.MathAdd(States.ArrayLength(States.StringSplit($$.StateMachine.Name, '-')), -1)) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_split.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_split.txt new file mode 100644 index 0000000000..3a7aafca18 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_split.txt @@ -0,0 +1 @@ +States.StringSplit('Hello\nWorld', '\n') \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_to_json.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_to_json.txt new file mode 100644 index 0000000000..d4d97a44ff --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_to_json.txt @@ -0,0 +1 @@ +States.StringToJson($.FunctionInput) \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/examples/intrinsic_states_uuid.txt b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_uuid.txt new file mode 100644 index 0000000000..7b1d7d2798 --- /dev/null +++ b/amazon-states-language-intrinsic-functions/examples/intrinsic_states_uuid.txt @@ -0,0 +1 @@ +States.UUID() \ No newline at end of file diff --git a/amazon-states-language-intrinsic-functions/pom.xml b/amazon-states-language-intrinsic-functions/pom.xml new file mode 100644 index 0000000000..193d42e90a --- /dev/null +++ b/amazon-states-language-intrinsic-functions/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + amazon-states-language-intrinsic-functions + jar + localstack.cloud amazon-states-language intrinsic-functions + + org.antlr.grammars + grammarsv4 + 1.0-SNAPSHOT + + + + + org.antlr + antlr4-maven-plugin + ${antlr.version} + + ${basedir} + + ASLIntrinsicLexer.g4 + ASLIntrinsicParser.g4 + + true + true + + + + + antlr4 + + + + + + com.khubla.antlr + antlr4test-maven-plugin + ${antlr4test-maven-plugin.version} + + false + false + intrinsic_function + ASLIntrinsic + + examples/ + + + + + test + + + + + + + diff --git a/amazon-states-language/ASLLexer.g4 b/amazon-states-language/ASLLexer.g4 new file mode 100644 index 0000000000..5f562c7408 --- /dev/null +++ b/amazon-states-language/ASLLexer.g4 @@ -0,0 +1,210 @@ +/** + * Copyright (c) 2017+ LocalStack contributors + * Copyright (c) 2016 Atlassian Pty Ltd + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Amazon States Lanaguage (ASL) Grammar for ANTLR v4 + * + * Based on: + * http://github.com/localstack/localstack + * and + * https://states-language.net/spec.html + */ + +// $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 ASLLexer; + +// Symbols. +COMMA : ','; +COLON : ':'; +LBRACK : '['; +RBRACK : ']'; +LBRACE : '{'; +RBRACE : '}'; + +// Literals. +TRUE : 'true'; +FALSE : 'false'; +NULL : 'null'; + +// Keywords. +COMMENT : '"Comment"'; +STATES : '"States"'; +STARTAT : '"StartAt"'; +VERSION : '"Version"'; + +TYPE : '"Type"'; +TASK : '"Task"'; +CHOICE : '"Choice"'; +FAIL : '"Fail"'; +SUCCEED : '"Succeed"'; +PASS : '"Pass"'; +WAIT : '"Wait"'; +PARALLEL : '"Parallel"'; +MAP : '"Map"'; + +CHOICES : '"Choices"'; +VARIABLE : '"Variable"'; +DEFAULT : '"Default"'; +BRANCHES : '"Branches"'; + +AND : '"And"'; +BOOLEANEQUALS : '"BooleanEquals"'; +BOOLEANQUALSPATH : '"BooleanEqualsPath"'; +ISBOOLEAN : '"IsBoolean"'; +ISNULL : '"IsNull"'; +ISNUMERIC : '"IsNumeric"'; +ISPRESENT : '"IsPresent"'; +ISSTRING : '"IsString"'; +ISTIMESTAMP : '"IsTimestamp"'; +NOT : '"Not"'; +NUMERICEQUALS : '"NumericEquals"'; +NUMERICEQUALSPATH : '"NumericEqualsPath"'; +NUMERICGREATERTHAN : '"NumericGreaterThan"'; +NUMERICGREATERTHANPATH : '"NumericGreaterThanPath"'; +NUMERICGREATERTHANEQUALS : '"NumericGreaterThanEquals"'; +NUMERICGREATERTHANEQUALSPATH : '"NumericGreaterThanEqualsPath"'; +NUMERICLESSTHAN : '"NumericLessThan"'; +NUMERICLESSTHANPATH : '"NumericLessThanPath"'; +NUMERICLESSTHANEQUALS : '"NumericLessThanEquals"'; +NUMERICLESSTHANEQUALSPATH : '"NumericLessThanEqualsPath"'; +OR : '"Or"'; +STRINGEQUALS : '"StringEquals"'; +STRINGEQUALSPATH : '"StringEqualsPath"'; +STRINGGREATERTHAN : '"StringGreaterThan"'; +STRINGGREATERTHANPATH : '"StringGreaterThanPath"'; +STRINGGREATERTHANEQUALS : '"StringGreaterThanEquals"'; +STRINGGREATERTHANEQUALSPATH : '"StringGreaterThanEqualsPath"'; +STRINGLESSTHAN : '"StringLessThan"'; +STRINGLESSTHANPATH : '"StringLessThanPath"'; +STRINGLESSTHANEQUALS : '"StringLessThanEquals"'; +STRINGLESSTHANEQUALSPATH : '"StringLessThanEqualsPath"'; +STRINGMATCHES : '"StringMatches"'; +TIMESTAMPEQUALS : '"TimestampEquals"'; +TIMESTAMPEQUALSPATH : '"TimestampEqualsPath"'; +TIMESTAMPGREATERTHAN : '"TimestampGreaterThan"'; +TIMESTAMPGREATERTHANPATH : '"TimestampGreaterThanPath"'; +TIMESTAMPGREATERTHANEQUALS : '"TimestampGreaterThanEquals"'; +TIMESTAMPGREATERTHANEQUALSPATH : '"TimestampGreaterThanEqualsPath"'; +TIMESTAMPLESSTHAN : '"TimestampLessThan"'; +TIMESTAMPLESSTHANPATH : '"TimestampLessThanPath"'; +TIMESTAMPLESSTHANEQUALS : '"TimestampLessThanEquals"'; +TIMESTAMPLESSTHANEQUALSPATH : '"TimestampLessThanEqualsPath"'; + +SECONDSPATH : '"SecondsPath"'; +SECONDS : '"Seconds"'; +TIMESTAMPPATH : '"TimestampPath"'; +TIMESTAMP : '"Timestamp"'; + +TIMEOUTSECONDS : '"TimeoutSeconds"'; +TIMEOUTSECONDSPATH : '"TimeoutSecondsPath"'; + +HEARTBEATSECONDS : '"HeartbeatSeconds"'; +HEARTBEATSECONDSPATH : '"HeartbeatSecondsPath"'; + +PROCESSORCONFIG : '"ProcessorConfig"'; +MODE : '"Mode"'; +INLINE : '"INLINE"'; +DISTRIBUTED : '"DISTRIBUTED"'; +EXECUTIONTYPE : '"ExecutionType"'; +STANDARD : '"STANDARD"'; + +ITEMPROCESSOR : '"ItemProcessor"'; +ITERATOR : '"Iterator"'; +ITEMSELECTOR : '"ItemSelector"'; +MAXCONCURRENCY : '"MaxConcurrency"'; + +RESOURCE : '"Resource"'; +INPUTPATH : '"InputPath"'; +OUTPUTPATH : '"OutputPath"'; +ITEMSPATH : '"ItemsPath"'; +RESULTPATH : '"ResultPath"'; +RESULT : '"Result"'; +PARAMETERS : '"Parameters"'; +RESULTSELECTOR : '"ResultSelector"'; + +ITEMREADER : '"ItemReader"'; +READERCONFIG : '"ReaderConfig"'; +INPUTTYPE : '"InputType"'; +CSVHEADERLOCATION : '"CSVHeaderLocation"'; +CSVHEADERS : '"CSVHeaders"'; +MAXITEMS : '"MaxItems"'; +MAXITEMSPATH : '"MaxItemsPath"'; + +NEXT : '"Next"'; +END : '"End"'; + +CAUSE : '"Cause"'; +CAUSEPATH : '"CausePath"'; +ERROR : '"Error"'; +ERRORPATH : '"ErrorPath"'; + +// Retry. +RETRY : '"Retry"'; +ERROREQUALS : '"ErrorEquals"'; +INTERVALSECONDS : '"IntervalSeconds"'; +MAXATTEMPTS : '"MaxAttempts"'; +BACKOFFRATE : '"BackoffRate"'; +MAXDELAYSECONDS : '"MaxDelaySeconds"'; +JITTERSTRATEGY : '"JitterStrategy"'; +FULL : '"FULL"'; +NONE : '"NONE"'; + +// Catch. +CATCH: '"Catch"'; + +// ErrorNames +ERRORNAMEStatesALL : '"States.ALL"'; +ERRORNAMEStatesHeartbeatTimeout : '"States.HeartbeatTimeout"'; +ERRORNAMEStatesTimeout : '"States.Timeout"'; +ERRORNAMEStatesTaskFailed : '"States.TaskFailed"'; +ERRORNAMEStatesPermissions : '"States.Permissions"'; +ERRORNAMEStatesResultPathMatchFailure : '"States.ResultPathMatchFailure"'; +ERRORNAMEStatesParameterPathFailure : '"States.ParameterPathFailure"'; +ERRORNAMEStatesBranchFailed : '"States.BranchFailed"'; +ERRORNAMEStatesNoChoiceMatched : '"States.NoChoiceMatched"'; +ERRORNAMEStatesIntrinsicFailure : '"States.IntrinsicFailure"'; +ERRORNAMEStatesExceedToleratedFailureThreshold : '"States.ExceedToleratedFailureThreshold"'; +ERRORNAMEStatesItemReaderFailed : '"States.ItemReaderFailed"'; +ERRORNAMEStatesResultWriterFailed : '"States.ResultWriterFailed"'; +// Read-only: +ERRORNAMEStatesRuntime: '"States.Runtime"'; + +// Strings. +STRINGDOLLAR: '"' (ESC | SAFECODEPOINT)* '.$"'; + +STRINGPATHCONTEXTOBJ: '"$$' (ESC | SAFECODEPOINT)* '"'; + +STRINGPATH: '"$' (ESC | SAFECODEPOINT)* '"'; + +STRING : '"' (ESC | SAFECODEPOINT)* '"'; +fragment ESC : '\\' (["\\/bfnrt] | UNICODE); +fragment UNICODE : 'u' HEX HEX HEX HEX; +fragment HEX : [0-9a-fA-F]; +fragment SAFECODEPOINT : ~ ["\\\u0000-\u001F]; + +// Numbers. +INT: '0' | [1-9] [0-9]*; + +NUMBER: '-'? INT ('.' [0-9]+)? EXP?; + +fragment EXP: [Ee] [+\-]? INT; + +// Whitespace. +WS: [ \t\n\r]+ -> skip; \ No newline at end of file diff --git a/amazon-states-language/ASLParser.g4 b/amazon-states-language/ASLParser.g4 new file mode 100644 index 0000000000..cc84817664 --- /dev/null +++ b/amazon-states-language/ASLParser.g4 @@ -0,0 +1,489 @@ +/** + * Copyright (c) 2017+ LocalStack contributors + * Copyright (c) 2016 Atlassian Pty Ltd + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Amazon States Lanaguage (ASL) Grammar for ANTLR v4 + * + * Based on: + * http://github.com/localstack/localstack + * and + * https://states-language.net/spec.html + */ + +// $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 ASLParser; + +options { + tokenVocab = ASLLexer; +} + +state_machine: program_decl EOF; + +program_decl: LBRACE top_layer_stmt (COMMA top_layer_stmt)* RBRACE; + +top_layer_stmt: comment_decl | version_decl | startat_decl | states_decl | timeout_seconds_decl; + +startat_decl: STARTAT COLON keyword_or_string; + +comment_decl: COMMENT COLON keyword_or_string; + +version_decl: VERSION COLON keyword_or_string; + +state_stmt: + comment_decl + | type_decl + | input_path_decl + | resource_decl + | next_decl + | result_decl + | result_path_decl + | output_path_decl + | end_decl + | default_decl + | choices_decl + | error_decl + | error_path_decl + | cause_decl + | cause_path_decl + | seconds_decl + | seconds_path_decl + | timestamp_decl + | timestamp_path_decl + | items_path_decl + | item_processor_decl + | iterator_decl + | item_selector_decl + | item_reader_decl + | max_concurrency_decl + | timeout_seconds_decl + | timeout_seconds_path_decl + | heartbeat_seconds_decl + | heartbeat_seconds_path_decl + | branches_decl + | parameters_decl + | retry_decl + | catch_decl + | result_selector_decl +; + +states_decl: STATES COLON LBRACE state_decl (COMMA state_decl)* RBRACE; + +state_name: keyword_or_string; + +// TODO: avoid redefinitions? -> check listener ok? +state_decl: state_name COLON state_decl_body; + +state_decl_body: LBRACE state_stmt (COMMA state_stmt)* RBRACE; + +type_decl: TYPE COLON state_type; + +next_decl: NEXT COLON keyword_or_string; + +resource_decl: RESOURCE COLON keyword_or_string; + +input_path_decl: INPUTPATH COLON (NULL | keyword_or_string); + +result_decl: RESULT COLON json_value_decl; + +result_path_decl: RESULTPATH COLON (NULL | keyword_or_string); + +output_path_decl: OUTPUTPATH COLON (NULL | keyword_or_string); + +end_decl: END COLON (TRUE | FALSE); + +default_decl: DEFAULT COLON keyword_or_string; + +error_decl: ERROR COLON keyword_or_string; + +error_path_decl: + ERRORPATH COLON STRINGPATH # error_path_decl_path + | ERRORPATH COLON intrinsic_func # error_path_decl_intrinsic +; + +cause_decl: CAUSE COLON keyword_or_string; + +cause_path_decl: + CAUSEPATH COLON STRINGPATH # cause_path_decl_path + | CAUSEPATH COLON intrinsic_func # cause_path_decl_intrinsic +; + +seconds_decl: SECONDS COLON INT; + +seconds_path_decl: SECONDSPATH COLON keyword_or_string; + +timestamp_decl: TIMESTAMP COLON keyword_or_string; + +timestamp_path_decl: TIMESTAMPPATH COLON keyword_or_string; + +items_path_decl: ITEMSPATH COLON keyword_or_string; + +max_concurrency_decl: MAXCONCURRENCY COLON INT; + +parameters_decl: PARAMETERS COLON payload_tmpl_decl; + +timeout_seconds_decl: TIMEOUTSECONDS COLON INT; + +timeout_seconds_path_decl: TIMEOUTSECONDSPATH COLON STRINGPATH; + +heartbeat_seconds_decl: HEARTBEATSECONDS COLON INT; + +heartbeat_seconds_path_decl: HEARTBEATSECONDSPATH COLON STRINGPATH; + +payload_tmpl_decl: LBRACE payload_binding (COMMA payload_binding)* RBRACE | LBRACE RBRACE; + +payload_binding: + STRINGDOLLAR COLON STRINGPATH # payload_binding_path + | STRINGDOLLAR COLON STRINGPATHCONTEXTOBJ # payload_binding_path_context_obj + | STRINGDOLLAR COLON intrinsic_func # payload_binding_intrinsic_func + | keyword_or_string COLON payload_value_decl # payload_binding_value +; + +intrinsic_func: STRING; + +payload_arr_decl: LBRACK payload_value_decl (COMMA payload_value_decl)* RBRACK | LBRACK RBRACK; + +payload_value_decl: payload_binding | payload_arr_decl | payload_tmpl_decl | payload_value_lit; + +payload_value_lit: + NUMBER # payload_value_float + | INT # payload_value_int + | (TRUE | FALSE) # payload_value_bool + | NULL # payload_value_null + | keyword_or_string # payload_value_str +; + +result_selector_decl: RESULTSELECTOR COLON payload_tmpl_decl; + +state_type: TASK | PASS | CHOICE | FAIL | SUCCEED | WAIT | MAP | PARALLEL; + +choices_decl: CHOICES COLON LBRACK choice_rule (COMMA choice_rule)* RBRACK; + +choice_rule: + LBRACE comparison_variable_stmt (COMMA comparison_variable_stmt)+ RBRACE # choice_rule_comparison_variable + | LBRACE comparison_composite_stmt (COMMA comparison_composite_stmt)* RBRACE # choice_rule_comparison_composite +; + +comparison_variable_stmt: variable_decl | comparison_func | next_decl | comment_decl; + +comparison_composite_stmt: comparison_composite | next_decl; + +comparison_composite: // TODO: this allows for Next definitions in nested choice_rules, is this supported at parse time? + choice_operator COLON (choice_rule | LBRACK choice_rule (COMMA choice_rule)* RBRACK) +; + +variable_decl: VARIABLE COLON keyword_or_string; + +comparison_func: comparison_op COLON json_value_decl; + +branches_decl: BRANCHES COLON LBRACK program_decl (COMMA program_decl)* RBRACK; + +item_processor_decl: + ITEMPROCESSOR COLON LBRACE item_processor_item (COMMA item_processor_item)* RBRACE +; + +item_processor_item: processor_config_decl | startat_decl | states_decl | comment_decl; + +processor_config_decl: + PROCESSORCONFIG COLON LBRACE processor_config_field (COMMA processor_config_field)* RBRACE +; + +processor_config_field: mode_decl | execution_decl; + +mode_decl: MODE COLON mode_type; + +mode_type: INLINE | DISTRIBUTED; + +execution_decl: EXECUTIONTYPE COLON execution_type; + +execution_type: STANDARD; + +iterator_decl: ITERATOR COLON LBRACE iterator_decl_item ( COMMA iterator_decl_item)* RBRACE; + +iterator_decl_item: startat_decl | states_decl | comment_decl; + +item_selector_decl: ITEMSELECTOR COLON payload_tmpl_decl; + +item_reader_decl: ITEMREADER COLON LBRACE items_reader_field ( COMMA items_reader_field)* RBRACE; + +items_reader_field: resource_decl | parameters_decl | reader_config_decl; + +reader_config_decl: + READERCONFIG COLON LBRACE reader_config_field (COMMA reader_config_field)* RBRACE +; + +reader_config_field: + input_type_decl + | csv_header_location_decl + | csv_headers_decl + | max_items_decl + | max_items_path_decl +; + +input_type_decl: INPUTTYPE COLON keyword_or_string; + +csv_header_location_decl: CSVHEADERLOCATION COLON keyword_or_string; + +csv_headers_decl: // TODO: are empty "CSVHeaders" list values supported? + CSVHEADERS COLON LBRACK keyword_or_string (COMMA keyword_or_string)* RBRACK +; + +max_items_decl: MAXITEMS COLON INT; + +max_items_path_decl: MAXITEMSPATH COLON STRINGPATH; + +retry_decl: RETRY COLON LBRACK (retrier_decl (COMMA retrier_decl)*)? RBRACK; + +retrier_decl: LBRACE retrier_stmt (COMMA retrier_stmt)* RBRACE; + +retrier_stmt: + error_equals_decl + | interval_seconds_decl + | max_attempts_decl + | backoff_rate_decl + | max_delay_seconds_decl + | jitter_strategy_decl + | comment_decl +; + +error_equals_decl: ERROREQUALS COLON LBRACK error_name (COMMA error_name)* RBRACK; + +interval_seconds_decl: INTERVALSECONDS COLON INT; + +max_attempts_decl: MAXATTEMPTS COLON INT; + +backoff_rate_decl: BACKOFFRATE COLON (INT | NUMBER); + +max_delay_seconds_decl: MAXDELAYSECONDS COLON INT; + +jitter_strategy_decl: JITTERSTRATEGY COLON (FULL | NONE); + +catch_decl: CATCH COLON LBRACK (catcher_decl (COMMA catcher_decl)*)? RBRACK; + +catcher_decl: LBRACE catcher_stmt (COMMA catcher_stmt)* RBRACE; + +catcher_stmt: error_equals_decl | result_path_decl | next_decl | comment_decl; + +comparison_op: + BOOLEANEQUALS + | BOOLEANQUALSPATH + | ISBOOLEAN + | ISNULL + | ISNUMERIC + | ISPRESENT + | ISSTRING + | ISTIMESTAMP + | NUMERICEQUALS + | NUMERICEQUALSPATH + | NUMERICGREATERTHAN + | NUMERICGREATERTHANPATH + | NUMERICGREATERTHANEQUALS + | NUMERICGREATERTHANEQUALSPATH + | NUMERICLESSTHAN + | NUMERICLESSTHANPATH + | NUMERICLESSTHANEQUALS + | NUMERICLESSTHANEQUALSPATH + | STRINGEQUALS + | STRINGEQUALSPATH + | STRINGGREATERTHAN + | STRINGGREATERTHANPATH + | STRINGGREATERTHANEQUALS + | STRINGGREATERTHANEQUALSPATH + | STRINGLESSTHAN + | STRINGLESSTHANPATH + | STRINGLESSTHANEQUALS + | STRINGLESSTHANEQUALSPATH + | STRINGMATCHES + | TIMESTAMPEQUALS + | TIMESTAMPEQUALSPATH + | TIMESTAMPGREATERTHAN + | TIMESTAMPGREATERTHANPATH + | TIMESTAMPGREATERTHANEQUALS + | TIMESTAMPGREATERTHANEQUALSPATH + | TIMESTAMPLESSTHAN + | TIMESTAMPLESSTHANPATH + | TIMESTAMPLESSTHANEQUALS + | TIMESTAMPLESSTHANEQUALSPATH +; + +choice_operator: NOT | AND | OR; + +states_error_name: + ERRORNAMEStatesALL + | ERRORNAMEStatesHeartbeatTimeout + | ERRORNAMEStatesTimeout + | ERRORNAMEStatesTaskFailed + | ERRORNAMEStatesPermissions + | ERRORNAMEStatesResultPathMatchFailure + | ERRORNAMEStatesParameterPathFailure + | ERRORNAMEStatesBranchFailed + | ERRORNAMEStatesNoChoiceMatched + | ERRORNAMEStatesIntrinsicFailure + | ERRORNAMEStatesExceedToleratedFailureThreshold + | ERRORNAMEStatesItemReaderFailed + | ERRORNAMEStatesResultWriterFailed + | ERRORNAMEStatesRuntime +; + +error_name: states_error_name | keyword_or_string; + +json_obj_decl: LBRACE json_binding (COMMA json_binding)* RBRACE | LBRACE RBRACE; + +json_binding: keyword_or_string COLON json_value_decl; + +json_arr_decl: LBRACK json_value_decl (COMMA json_value_decl)* RBRACK | LBRACK RBRACK; + +json_value_decl: + NUMBER + | INT + | TRUE + | FALSE + | NULL + | json_binding + | json_arr_decl + | json_obj_decl + | keyword_or_string +; + +keyword_or_string: + STRINGDOLLAR + | STRINGPATHCONTEXTOBJ + | STRINGPATH + | STRING + // + | COMMENT + | STATES + | STARTAT + | TYPE + | TASK + | CHOICE + | FAIL + | SUCCEED + | PASS + | WAIT + | PARALLEL + | MAP + | CHOICES + | VARIABLE + | DEFAULT + | BRANCHES + | AND + | BOOLEANEQUALS + | BOOLEANQUALSPATH + | ISBOOLEAN + | ISNULL + | ISNUMERIC + | ISPRESENT + | ISSTRING + | ISTIMESTAMP + | NOT + | NUMERICEQUALS + | NUMERICEQUALSPATH + | NUMERICGREATERTHAN + | NUMERICGREATERTHANPATH + | NUMERICGREATERTHANEQUALS + | NUMERICGREATERTHANEQUALSPATH + | NUMERICLESSTHAN + | NUMERICLESSTHANPATH + | NUMERICLESSTHANEQUALS + | NUMERICLESSTHANEQUALSPATH + | OR + | STRINGEQUALS + | STRINGEQUALSPATH + | STRINGGREATERTHAN + | STRINGGREATERTHANPATH + | STRINGGREATERTHANEQUALS + | STRINGGREATERTHANEQUALSPATH + | STRINGLESSTHAN + | STRINGLESSTHANPATH + | STRINGLESSTHANEQUALS + | STRINGLESSTHANEQUALSPATH + | STRINGMATCHES + | TIMESTAMPEQUALS + | TIMESTAMPEQUALSPATH + | TIMESTAMPGREATERTHAN + | TIMESTAMPGREATERTHANPATH + | TIMESTAMPGREATERTHANEQUALS + | TIMESTAMPGREATERTHANEQUALSPATH + | TIMESTAMPLESSTHAN + | TIMESTAMPLESSTHANPATH + | TIMESTAMPLESSTHANEQUALS + | TIMESTAMPLESSTHANEQUALSPATH + | SECONDSPATH + | SECONDS + | TIMESTAMPPATH + | TIMESTAMP + | TIMEOUTSECONDS + | TIMEOUTSECONDSPATH + | HEARTBEATSECONDS + | HEARTBEATSECONDSPATH + | PROCESSORCONFIG + | MODE + | INLINE + | DISTRIBUTED + | EXECUTIONTYPE + | STANDARD + | ITEMPROCESSOR + | ITERATOR + | ITEMSELECTOR + | MAXCONCURRENCY + | RESOURCE + | INPUTPATH + | OUTPUTPATH + | ITEMSPATH + | RESULTPATH + | RESULT + | PARAMETERS + | RESULTSELECTOR + | ITEMREADER + | READERCONFIG + | INPUTTYPE + | CSVHEADERLOCATION + | CSVHEADERS + | MAXITEMS + | MAXITEMSPATH + | NEXT + | END + | CAUSE + | ERROR + | RETRY + | ERROREQUALS + | INTERVALSECONDS + | MAXATTEMPTS + | BACKOFFRATE + | MAXDELAYSECONDS + | JITTERSTRATEGY + | FULL + | NONE + | CATCH + | ERRORNAMEStatesALL + | ERRORNAMEStatesHeartbeatTimeout + | ERRORNAMEStatesTimeout + | ERRORNAMEStatesTaskFailed + | ERRORNAMEStatesPermissions + | ERRORNAMEStatesResultPathMatchFailure + | ERRORNAMEStatesParameterPathFailure + | ERRORNAMEStatesBranchFailed + | ERRORNAMEStatesNoChoiceMatched + | ERRORNAMEStatesIntrinsicFailure + | ERRORNAMEStatesExceedToleratedFailureThreshold + | ERRORNAMEStatesItemReaderFailed + | ERRORNAMEStatesResultWriterFailed + | ERRORNAMEStatesRuntime +; \ No newline at end of file diff --git a/amazon-states-language/README.md b/amazon-states-language/README.md new file mode 100644 index 0000000000..e24330f7d7 --- /dev/null +++ b/amazon-states-language/README.md @@ -0,0 +1,40 @@ +# Amazon States Language (ASL) ANTLR4 Grammar + +The ANTLR4 grammar for the Amazon States Language (ASL), initially developed by +[LocalStack](github.com/localstack/localstack). + +The module contains lexer and parser grammars (`ASLLexer.g4` and `ASLParser.g4`) for +the Amazon States Language (ASL) language. + +## License +```txt +Copyright (c) 2017+ LocalStack contributors +Copyright (c) 2016 Atlassian Pty Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` + +## Links + +* [LocalStack](https://github.com/localstack/localstack) - LocalStack, the project +that developed the grammar and an Amazon States Language interpreter. +* [Amazon Language Specification](https://states-language.net/spec.html) - The original +language specification for Amazon States Language provided by Amazon. + + +## Examples +The `examples/` directory contains baseline examples demonstrating various types +of State Machine definitions in JSON. + +## Original source + diff --git a/amazon-states-language/desc.xml b/amazon-states-language/desc.xml new file mode 100644 index 0000000000..26bde4cec2 --- /dev/null +++ b/amazon-states-language/desc.xml @@ -0,0 +1,4 @@ + + + CSharp;Cpp;Dart;Go;Java;JavaScript;PHP;Python3;TypeScript + diff --git a/amazon-states-language/examples/choice_state.json b/amazon-states-language/examples/choice_state.json new file mode 100644 index 0000000000..75b4a88cd4 --- /dev/null +++ b/amazon-states-language/examples/choice_state.json @@ -0,0 +1,52 @@ +{ + "StartAt": "ChoiceStateX", + "States": { + "ChoiceStateX": { + "Type": "Choice", + "Choices": [ + { + "Not": { + "Variable": "$.type", + "StringEquals": "Private" + }, + "Next": "Public" + }, + { + "Variable": "$.value", + "NumericEquals": 0, + "Next": "ValueIsZero" + }, + { + "And": [ + { + "Variable": "$.value", + "NumericGreaterThanEquals": 20 + }, + { + "Variable": "$.value", + "NumericLessThan": 30 + } + ], + "Next": "ValueInTwenties" + } + ], + "Default": "DefaultState" + }, + "Public": { + "Type": "Pass", + "End": true + }, + "ValueIsZero": { + "Type": "Pass", + "End": true + }, + "ValueInTwenties": { + "Type": "Pass", + "End": true + }, + "DefaultState": { + "Type": "Fail", + "Cause": "No Matches!" + } + } +} \ No newline at end of file diff --git a/amazon-states-language/examples/dynamodb_put_update_get_item.json b/amazon-states-language/examples/dynamodb_put_update_get_item.json new file mode 100644 index 0000000000..c31b206d92 --- /dev/null +++ b/amazon-states-language/examples/dynamodb_put_update_get_item.json @@ -0,0 +1,39 @@ +{ + "Comment": "DYNAMODB_PUT_UPDATE_GET_ITEM", + "StartAt": "PutItem", + "States": { + "PutItem": { + "Type": "Task", + "Resource": "arn:aws:states:::dynamodb:putItem", + "Parameters": { + "TableName.$": "$.TableName", + "Item.$": "$.Item" + }, + "ResultPath": "$.putItemOutput", + "Next": "UpdateItem" + }, + "UpdateItem": { + "Type": "Task", + "Resource": "arn:aws:states:::dynamodb:updateItem", + "ResultPath": "$.updateItemOutput", + "Parameters": { + "TableName.$": "$.TableName", + "Key.$": "$.Key", + "UpdateExpression.$": "$.UpdateExpression", + "ExpressionAttributeValues.$": "$.ExpressionAttributeValues", + "ReturnValues": "UPDATED_NEW" + }, + "Next": "GetItem" + }, + "GetItem": { + "Type": "Task", + "Resource": "arn:aws:states:::dynamodb:getItem", + "ResultPath": "$.getItemOutput", + "Parameters": { + "TableName.$": "$.TableName", + "Key.$": "$.Key" + }, + "End": true + } + } +} diff --git a/amazon-states-language/examples/fail_state.json b/amazon-states-language/examples/fail_state.json new file mode 100644 index 0000000000..482a153ac9 --- /dev/null +++ b/amazon-states-language/examples/fail_state.json @@ -0,0 +1,10 @@ +{ + "StartAt": "FailState", + "States": { + "FailState": { + "Type": "Fail", + "ErrorPath": "States.Format('{}', $.Error)", + "CausePath": "States.Format('This is a custom error message for {}, caused by {}.', $.Error, $.Cause)" + } + } +} diff --git a/amazon-states-language/examples/lambda_catch.json b/amazon-states-language/examples/lambda_catch.json new file mode 100644 index 0000000000..d2a0de8e14 --- /dev/null +++ b/amazon-states-language/examples/lambda_catch.json @@ -0,0 +1,54 @@ +{ + "StartAt": "Start", + "States": { + "Start": { + "Type": "Task", + "Resource": "__tbd__", + "Parameters": { + "FunctionName.$": "$.FunctionName", + "Payload.$": "$.Payload" + }, + "Catch": [ + { + "ErrorEquals": [ + "Lambda.Unknown" + ], + "Next": "EndWithLambdaUnknownHandler" + }, + { + "ErrorEquals": [ + "States.TaskFailed" + ], + "Next": "EndWithStateTaskFailedHandler" + }, + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "EndWithAllHandler" + } + ], + "Next": "EndWithFinal" + }, + "EndWithLambdaUnknownHandler": { + "Type": "Pass", + "ResultPath": "$.lambda_unknown", + "End": true + }, + "EndWithStateTaskFailedHandler": { + "Type": "Pass", + "ResultPath": "$.task_failed_error", + "End": true + }, + "EndWithAllHandler": { + "Type": "Pass", + "ResultPath": "$.all_error", + "End": true + }, + "EndWithFinal": { + "Type": "Pass", + "ResultPath": "$.final", + "End": true + } + } +} diff --git a/amazon-states-language/examples/lambda_retry.json b/amazon-states-language/examples/lambda_retry.json new file mode 100644 index 0000000000..028144c81c --- /dev/null +++ b/amazon-states-language/examples/lambda_retry.json @@ -0,0 +1,23 @@ +{ + "StartAt": "LambdaTask", + "States": { + "LambdaTask": { + "Type": "Task", + "Resource": "_tbd_", + "End": true, + "Retry": [ + { + "Comment": "Includes all retry langauge features with JitterStrategy NONE.", + "ErrorEquals": [ + "States.ALL" + ], + "IntervalSeconds": 1, + "MaxAttempts": 2, + "BackoffRate": 1, + "MaxDelaySeconds": 3, + "JitterStrategy": "NONE" + } + ] + } + } +} diff --git a/amazon-states-language/examples/map_state.json b/amazon-states-language/examples/map_state.json new file mode 100644 index 0000000000..ac1a1186ac --- /dev/null +++ b/amazon-states-language/examples/map_state.json @@ -0,0 +1,39 @@ +{ + "StartAt": "MapState", + "States": { + "MapState": { + "Type": "Map", + "MaxConcurrency": 1, + "ItemReader": { + "ReaderConfig": { + "InputType": "CSV", + "CSVHeaderLocation": "GIVEN", + "CSVHeaders": [ + "H1", + "H2", + "H3" + ] + }, + "Resource": "arn:aws:states:::s3:getObject", + "Parameters": { + "Bucket.$": "$.Bucket", + "Key.$": "$.Key" + } + }, + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "DISTRIBUTED", + "ExecutionType": "STANDARD" + }, + "StartAt": "PassItem", + "States": { + "PassItem": { + "Type": "Pass", + "End": true + } + } + }, + "End": true + } + } +} diff --git a/amazon-states-language/examples/map_state_legacy.json b/amazon-states-language/examples/map_state_legacy.json new file mode 100644 index 0000000000..3fe9899b75 --- /dev/null +++ b/amazon-states-language/examples/map_state_legacy.json @@ -0,0 +1,40 @@ +{ + "StartAt": "StartState", + "States": { + "StartState": { + "Type": "Pass", + "Result": [ + 1, + "Hello", + {}, + null, + 3.3, + 3, + 4, + 5 + ], + "ResultPath": "$.arr", + "Next": "MapState" + }, + "MapState": { + "Type": "Map", + "ResultPath": null, + "InputPath": "$.arr", + "MaxConcurrency": 1, + "Iterator": { + "StartAt": "HandleItem", + "States": { + "HandleItem": { + "Type": "Pass", + "End": true + } + } + }, + "Next": "Final" + }, + "Final": { + "Type": "Pass", + "End": true + } + } +} diff --git a/amazon-states-language/examples/parallel_state.json b/amazon-states-language/examples/parallel_state.json new file mode 100644 index 0000000000..725d0469fa --- /dev/null +++ b/amazon-states-language/examples/parallel_state.json @@ -0,0 +1,60 @@ +{ + "StartAt": "LoadInput", + "States": { + "LoadInput": { + "Type": "Pass", + "Result": [ + 1, + 2, + 3, + 4 + ], + "Next": "ParallelState" + }, + "ParallelState": { + "Type": "Parallel", + "End": true, + "Branches": [ + { + "StartAt": "Branch1", + "States": { + "Branch1": { + "Type": "Pass", + "End": true + } + } + }, + { + "StartAt": "Branch21", + "States": { + "Branch21": { + "Type": "Pass", + "Next": "Branch22" + }, + "Branch22": { + "Type": "Pass", + "End": true + } + } + }, + { + "StartAt": "Branch31", + "States": { + "Branch31": { + "Type": "Pass", + "Next": "Branch32" + }, + "Branch32": { + "Type": "Pass", + "Next": "Branch33" + }, + "Branch33": { + "Type": "Pass", + "End": true + } + } + } + ] + } + } +} diff --git a/amazon-states-language/examples/pass_state.json b/amazon-states-language/examples/pass_state.json new file mode 100644 index 0000000000..eb60a98004 --- /dev/null +++ b/amazon-states-language/examples/pass_state.json @@ -0,0 +1,35 @@ +{ + "StartAt": "State0", + "States": { + "State0": { + "Type": "Pass", + "Parameters": { + "FromInput.$": "$.users[?(@.status == 0)]" + }, + "OutputPath": "$.FromInput", + "Next": "State1" + }, + "State1": { + "Type": "Pass", + "Parameters": { + "FromInput.$": "$[?(@.year <= 1999)]" + }, + "OutputPath": "$.FromInput", + "Next": "State2" + }, + "State2": { + "Type": "Pass", + "Parameters": { + "InputValue.$": "$", + "FromInput.$": "States.JsonToString($.[?(@.year <= 1998)])" + }, + "Next": "State3" + }, + "State3": { + "Type": "Pass", + "InputPath": "$.InputValue", + "OutputPath": "$.[?(@.year < 1999)].name", + "End": true + } + } +} diff --git a/amazon-states-language/pom.xml b/amazon-states-language/pom.xml new file mode 100644 index 0000000000..6214ba666e --- /dev/null +++ b/amazon-states-language/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + amazon-states-language + jar + localstack.cloud amazon-states-language + + org.antlr.grammars + grammarsv4 + 1.0-SNAPSHOT + + + + + org.antlr + antlr4-maven-plugin + ${antlr.version} + + ${basedir} + + ASLLexer.g4 + ASLParser.g4 + + true + true + + + + + antlr4 + + + + + + com.khubla.antlr + antlr4test-maven-plugin + ${antlr4test-maven-plugin.version} + + false + false + state_machine + ASL + + examples/ + + + + + test + + + + + + + diff --git a/pom.xml b/pom.xml index 57042ee9a8..e81fba35ac 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,8 @@ algol60 alloy alpaca + amazon-states-language + amazon-states-language-intrinsic-functions angelscript antlr apex