From 3d238fe475fba284975fda4d78c154d60de83269 Mon Sep 17 00:00:00 2001 From: InversionSpaces Date: Wed, 21 Jun 2023 12:25:09 +0000 Subject: [PATCH 1/2] Initial --- .gitignore | 2 ++ fuzzing-tests/Aqua.g4 | 51 ++++++++++++++++++++++++++++++++++ fuzzing-tests/README.md | 21 ++++++++++++++ fuzzing-tests/requirements.txt | 1 + 4 files changed, 75 insertions(+) create mode 100644 fuzzing-tests/Aqua.g4 create mode 100644 fuzzing-tests/README.md create mode 100644 fuzzing-tests/requirements.txt diff --git a/.gitignore b/.gitignore index b01daccb1..a558afced 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ project/target npm/aqua.js **/node_modules + +**/.antlr diff --git a/fuzzing-tests/Aqua.g4 b/fuzzing-tests/Aqua.g4 new file mode 100644 index 000000000..7af550315 --- /dev/null +++ b/fuzzing-tests/Aqua.g4 @@ -0,0 +1,51 @@ +grammar Aqua; + +tokens { + INDENT, + DEDENT, + NL +} + +@lexer::members { +# A hack to support indentation +def create_node(self, node, *args, **kwargs): + result = super().create_node(node, *args, **kwargs) + + if not hasattr(self, "indent_level"): + self.indent_level = 0 + + if node.name == "INDENT": + self.indent_level += 1 + result.src = "\n" + " " * self.indent_level + elif node.name == "DEDENT": + self.indent_level -= 1 + result.src = "\n" + " " * self.indent_level + elif node.name == "NL": + result.src = "\n" + " " * self.indent_level + + return result +} + +prog: function+; + +function: FUNC SP+ closure; + +closure: + ID LPAREN ((typedId COMMA SP*)* typedId)? RPAREN COLON block; + +block: INDENT ('expr' NL | ifStat)+ DEDENT; + +ifStat: IF SP+ ID COLON block; + +typedId: ID SP* COLON SP* type; + +type: 'u16'; + +LPAREN: '('; +RPAREN: ')'; +COLON: ':'; +COMMA: ','; +SP: ' '; +IF: 'if'; +FUNC: 'func'; +ID: [a-zA-Z][a-zA-Z_]+; diff --git a/fuzzing-tests/README.md b/fuzzing-tests/README.md new file mode 100644 index 000000000..2208b6078 --- /dev/null +++ b/fuzzing-tests/README.md @@ -0,0 +1,21 @@ +# Fuzzing tests for Aqua Compiler + +## Installation + +```sh +python3 -m pip install -r requirements.txt +``` + +## Usage + +File `Aqua.g4` contains ANTLRv4 grammar of Aqua Language. + +The following command will generate python fuzzing input generators for Aqua in `generated` dir: +```sh +grammarinator-process Aqua.g4 -o generated +``` + +The following command will generate `N` tests in `tests` dir with maximum grammar depth `D`: +```sh +grammarinator-generate -p generated/AquaUnparser.py -l generated/AquaUnlexer -r prog -n N -d D +``` \ No newline at end of file diff --git a/fuzzing-tests/requirements.txt b/fuzzing-tests/requirements.txt new file mode 100644 index 000000000..5979d3b17 --- /dev/null +++ b/fuzzing-tests/requirements.txt @@ -0,0 +1 @@ +grammarinator==19.3 \ No newline at end of file From aefc52725ddedd3b4fdef5914448be3c1bebbb7d Mon Sep 17 00:00:00 2001 From: InversionSpaces Date: Tue, 19 Sep 2023 15:59:07 +0000 Subject: [PATCH 2/2] Add types --- fuzzing-tests/Aqua.g4 | 55 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/fuzzing-tests/Aqua.g4 b/fuzzing-tests/Aqua.g4 index 7af550315..d1f70c752 100644 --- a/fuzzing-tests/Aqua.g4 +++ b/fuzzing-tests/Aqua.g4 @@ -39,13 +39,62 @@ ifStat: IF SP+ ID COLON block; typedId: ID SP* COLON SP* type; -type: 'u16'; +basicType: + '⊥' + | '⊤' + | 'u8' + | 'u16' + | 'u32' + | 'u64' + | 'i8' + | 'i16' + | 'i32' + | 'i64' + | 'f32' + | 'f64' + | 'bool' + | 'string'; +namedType: ID; + +dataType: + basicType + | namedType + | ARRAY SP* dataType + | OPTION SP* dataType + | STREAM SP* dataType; + +arrowTypeAbilities_aux: + LBRACE SP* namedType SP* (COMMA SP* namedType)* SP* RBRACE; + +// Only data types are allowed as arguments for arrow type +arrowTypeArgs_aux: (dataType SP* (COMMA SP* dataType)*)?; + +arrowTypeRet_aux: + typeParen_aux SP* (COMMA SP* typeParen_aux)* + | LPAREN RPAREN; // for no return + +arrowType: + arrowTypeAbilities_aux SP* arrowTypeArgs_aux SP* RARROW SP* arrowTypeRet_aux; + +type: dataType | arrowType; + +typeParen_aux: LPAREN SP* type SP* RPAREN | type; + +ARRAY: '[]'; +OPTION: '?'; +STREAM: '*'; + +IF: 'if'; +FUNC: 'func'; + +RARROW: '->'; LPAREN: '('; RPAREN: ')'; +LBRACE: '{'; +RBRACE: '}'; COLON: ':'; COMMA: ','; SP: ' '; -IF: 'if'; -FUNC: 'func'; + ID: [a-zA-Z][a-zA-Z_]+;