forked from antlr/grammars-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LocalStack's Amazon States Language (ASL) Grammar (antlr#3981)
* Add LocalStack AmazonStatesLanguage grammars and examples. * build configuration * devide modules into asl and intrinsic functions * start productions with eof
- Loading branch information
Showing
39 changed files
with
1,430 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
amazon-states-language-intrinsic-functions/ASLIntrinsicLexer.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
72 changes: 72 additions & 0 deletions
72
amazon-states-language-intrinsic-functions/ASLIntrinsicParser.g4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<https://github.com/localstack/localstack> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd"> | ||
<targets>CSharp;Cpp;Dart;Go;Java;JavaScript;PHP;Python3;TypeScript</targets> | ||
</desc> |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.Array($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_contains.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayContains($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_get_item.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayGetItem($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_length.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayLength($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_partition.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayPartition($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_range.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayRange($.FunctionInput.fst, $.FunctionInput.snd, $.FunctionInput.trd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_array_unique.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayUnique($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_decode.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.Base64Decode($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_base_64_encode.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.Base64Encode($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_format.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.Format('Formatting arguments fst={} and snd={}.', $.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_hash.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.Hash($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_merge.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.JsonMerge($.FunctionInput.fst, $.FunctionInput.snd, false) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_json_to_string.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.JsonToString($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_add.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.MathAdd($.FunctionInput.fst, $.FunctionInput.snd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_math_random.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.MathRandom($.FunctionInput.fst, $.FunctionInput.snd, $.FunctionInput.trd) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_nested_calls.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.ArrayGetItem(States.StringSplit($$.StateMachine.Name, '-'), States.MathAdd(States.ArrayLength(States.StringSplit($$.StateMachine.Name, '-')), -1)) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_split.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.StringSplit('Hello\nWorld', '\n') |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_string_to_json.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.StringToJson($.FunctionInput) |
1 change: 1 addition & 0 deletions
1
amazon-states-language-intrinsic-functions/examples/intrinsic_states_uuid.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
States.UUID() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>amazon-states-language-intrinsic-functions</artifactId> | ||
<packaging>jar</packaging> | ||
<name>localstack.cloud amazon-states-language intrinsic-functions</name> | ||
<parent> | ||
<groupId>org.antlr.grammars</groupId> | ||
<artifactId>grammarsv4</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-maven-plugin</artifactId> | ||
<version>${antlr.version}</version> | ||
<configuration> | ||
<sourceDirectory>${basedir}</sourceDirectory> | ||
<includes> | ||
<include>ASLIntrinsicLexer.g4</include> | ||
<include>ASLIntrinsicParser.g4</include> | ||
</includes> | ||
<visitor>true</visitor> | ||
<listener>true</listener> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>antlr4</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.khubla.antlr</groupId> | ||
<artifactId>antlr4test-maven-plugin</artifactId> | ||
<version>${antlr4test-maven-plugin.version}</version> | ||
<configuration> | ||
<verbose>false</verbose> | ||
<showTree>false</showTree> | ||
<entryPoint>intrinsic_function</entryPoint> | ||
<grammarName>ASLIntrinsic</grammarName> | ||
<packageName></packageName> | ||
<exampleFiles>examples/</exampleFiles> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.