diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8306dd2..ec7bb84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,9 @@ jobs: python-version: "3.11" - name: Install test dependency run: pip install pytest + - name: Validate JSON schemas + run: | + #pip install jsonschema + #python test/validate_schemas.py - name: Run harness self-tests run: python -m pytest test/.self-test -v diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1db21c2..abc5c59 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,11 @@ jobs: with: python-version: "3.11" + - name: Validate JSON schemas + run: | + #pip install jsonschema + #python test/validate_schemas.py + - name: Install test harness dependency run: pip install pytest @@ -33,4 +38,4 @@ jobs: exit 1 - name: Run tests for grammar ${{ matrix.grammar }} - run: python3 test/run_tests.py test --grammar ${{ matrix.grammar }} --no-build \ No newline at end of file + run: python3 test/run_tests.py test --grammar ${{ matrix.grammar }} --no-build diff --git a/doc/grammar1.md b/doc/grammar1.md index 266c22e..7525e24 100644 --- a/doc/grammar1.md +++ b/doc/grammar1.md @@ -95,3 +95,138 @@ SysProLang uses C-style comments: - **Comments and whitespace** are ignored by the parser (handled by the lexer). - **Error recovery**: see [`doc/error-handling.md`](error-handling.md) for the recommended error recovery strategy. + +## Token kinds + +These are the `"kind"` values that appear in `tokens.json` golden files: + +| Token kind | Grammar source | Notes | +|---|---|---| +| `IDENT` | `IDENT` (any identifier) | | +| `INT` | `INTEGER_LITERAL` | | +| `RETURN` | `return` | Keyword | +| `VAL` | `val` | Keyword | +| `VAR` | `var` | Keyword | +| `PLUS` | `+` | | +| `MINUS` | `-` | | +| `MULT` | `*` | | +| `DIV` | `/` | | +| `ASSIGN` | `=` | Assignment | +| `LPAREN` | `(` | | +| `RPAREN` | `)` | | +| `SEMI` | `;` | | +| `EOF` | (end of file) | Always the last token | + +> Comments are filtered out by the lexer before the parser sees them, +> so comment token kinds never appear in golden token files. + +### Example + +Source: + +``` +var x = 10; +return x / 2; +``` + +```json +[ +{"kind": "VAR", "value": "var", "line": 1, "column": 1}, +{"kind": "IDENT", "value": "x", "line": 1, "column": 5}, +{"kind": "ASSIGN", "value": "=", "line": 1, "column": 7}, +{"kind": "INT", "value": "10", "line": 1, "column": 9}, +{"kind": "SEMI", "value": ";", "line": 1, "column": 11}, +{"kind": "RETURN", "value": "return", "line": 2, "column": 1}, +{"kind": "IDENT", "value": "x", "line": 2, "column": 8}, +{"kind": "DIV", "value": "/", "line": 2, "column": 10}, +{"kind": "INT", "value": "2", "line": 2, "column": 12}, +{"kind": "SEMI", "value": ";", "line": 2, "column": 13}, +{"kind": "EOF", "value": "", "line": 2, "column": 14} +] +``` + +## AST node kinds + +These are the `"kind"` values that appear in `ast.json` golden files: + +| AST kind | `elems[]` children | Notes | +|---|---|---| +| `Program` | `[statements...]` | Wraps all top-level statements (implicit `main()`) | +| `Return` | `[expr]` | Return value is the single child | +| `Declare` | `[name, expr]` | `var`/`val` declaration with name as `Ident` node | +| `Assign` | `[name, expr]` | Name is an `Ident` node | +| `IntLiteral` | `[]` | Literal integer value | +| `Ident` | `[]` | Identifier name reference | +| `BinOp` | `[left, right]` | Binary arithmetic operator | +| `Unary` | `[operand]` | Unary minus | +| `Error` | `[]` | Produced during error recovery | + +### Example + +Source: + +```scala +var x = 10; +return x / 2; +``` + +```json +{ + "line": 1, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "Declare", + "mut": "var", + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "value": "x", + "elems": [], + }, + { + "line": 1, + "column": 9, + "kind": "IntLiteral", + "value": 10, + "elems": [] + } + ], + }, + { + "line": 2, + "column": 1, + "kind": "Return", + "elems": [ + { + "line": 2, + "column": 10, + "kind": "BinOp", + "value": "/", + "elems": [ + { + "line": 2, + "column": 8, + "kind": "Ident", + "value": "x", + "elems": [], + }, + { + "line": 2, + "column": 12, + "kind": "IntLiteral", + "value": 2, + "elems": [] + } + ], + } + ] + } + ], +} +``` diff --git a/doc/grammar2.md b/doc/grammar2.md index febb286..a28fa84 100644 --- a/doc/grammar2.md +++ b/doc/grammar2.md @@ -137,6 +137,69 @@ All semantic rules from grammar 1 apply, plus: - **Logical operators** `&&` and `||` are short-circuit: `&&` evaluates the right operand only if the left is non-zero; `||` evaluates the right operand only if the left is zero. `!` negates (non-zero becomes `0`, zero becomes `1`). -- **All values remain `Int64`** — no type system yet. +- **All values remain `Int64`** --- no type system yet. - **Error recovery**: see [`doc/error-handling.md`](error-handling.md) for the - recommended error recovery strategy. \ No newline at end of file + recommended error recovery strategy. + +## Token kinds (new in grammar 2) + +These `"kind"` values appear in `tokens.json` golden files, in addition to those from grammar 1: + +| Token kind | Grammar source | Notes | +|---|---|---| +| `IF` | `if` | Keyword | +| `ELSE` | `else` | Keyword | +| `WHILE` | `while` | Keyword | +| `BREAK` | `break` | Keyword | +| `CONTINUE` | `continue` | Keyword | +| `TRUE` | `true` | Boolean literal | +| `FALSE` | `false` | Boolean literal | +| `LBRACE` | `{` | Block opening | +| `RBRACE` | `}` | Block closing | +| `EQ` | `==` | Equality | +| `NE` | `!=` | Inequality | +| `LT` | `<` | Less-than | +| `GT` | `>` | Greater-than | +| `LE` | `<=` | Less-or-equal | +| `GE` | `>=` | Greater-or-equal | +| `AND` | `&&` | Logical AND (short-circuit) | +| `OR` | `\|\|` | Logical OR (short-circuit) | +| `NOT` | `!` | Logical NOT | + +All tokens from grammar 1 also apply. + +### Example + +> TODO + +## AST node kinds (new in grammar 2) + +These `"kind"` values appear in `ast.json` golden files, in addition to those from grammar 1: + +| AST kind | `elems[]` children | Notes | +|---|---|---| +| `If` | `[cond, thenBody, elseBody?]` | `elseBody` is omitted if absent (2 or 3 children) | +| `While` | `[cond, body]` | | +| `Break` | `[]` | | +| `Continue` | `[]` | | +| `Block` | `[statements..]` | Wraps a `{ ... }` block | +| `BoolLiteral` | `[]` | Boolean literal | +| `BinOp` | `[left, right]` | New operators: `"=="`, `"!="`, `"<"`, `">"`, `"<="`, `">="`, `"&&"`, `"\|\|"` | +| `Unary` | `[operand]` | New operator: `"!"` | + +All AST kinds from grammar 1 also apply. + +### Notes on expression AST + +- `==`, `!=`, `<`, `>`, `<=`, `>=` comparisons are represented as `BinOp` nodes. +- `&&`, `||` are also `BinOp` nodes. +- `!` (logical NOT) is a `Unary` node. +- `true` and `false` literals are `BoolLiteral` nodes. In grammar 2 (no type system) + semantically they are treated as `Int64` 1 or 0. +- `If` nodes have `elems[0]` = condition, `elems[1]` = then-body, and optionally + `elems[2]` = else-body. The presence of exactly 2 or 3 children distinguishes + `if (cond) stmt` from `if (cond) stmt else stmt`. + +### Example + +> TODO diff --git a/doc/grammar3.g4 b/doc/grammar3.g4 index 4ec5d4b..395da37 100644 --- a/doc/grammar3.g4 +++ b/doc/grammar3.g4 @@ -13,7 +13,21 @@ grammar grammar3; // lexer runs a single-line comment to end-of-line, a generated line comment // must always end with a newline (whitespace.py guarantees this). -program : externDeclaration* funcDeclaration* EOF; +program : topDeclaration* EOF; + +topDeclaration + : externDeclaration + | funcDeclaration + +// extern declaration for C interop. +// Example: extern def foo(a, b); +externDeclaration : 'extern' 'def' IDENT '(' paramList? ')' ';'; + +// Function declaration with optional parameters. +// Example: def add(a, b) { return a + b; } +funcDeclaration : 'def' IDENT '(' paramList? ')' block; + +paramList : IDENT (',' IDENT)*; statement : returnStatement @@ -50,16 +64,6 @@ breakStatement : 'break' ';'; continueStatement : 'continue' ';'; -// extern declaration for C interop. -// Example: extern def foo(a, b); -externDeclaration : 'extern' 'def' IDENT '(' paramList? ')' ';'; - -// Function declaration with optional parameters. -// Example: def add(a, b) { return a + b; } -funcDeclaration : 'def' IDENT '(' paramList? ')' block; - -paramList : IDENT (',' IDENT)*; - // Expression definitions go from lowest operator precedence // to the highest, allowing for straightforward expression parsing. // Comparison operators produce integer values (0 or 1). @@ -126,4 +130,4 @@ IDENT : [a-zA-Z_] [a-zA-Z0-9_]*; // parser rule references them. WS : [ \t\n\r]+; LINE_COMMENT : '//' ~[\r\n]*; -BLOCK_COMMENT : '/*' .*? '*/'; \ No newline at end of file +BLOCK_COMMENT : '/*' .*? '*/'; diff --git a/doc/grammar3.md b/doc/grammar3.md index 7ffaa32..edb2120 100644 --- a/doc/grammar3.md +++ b/doc/grammar3.md @@ -5,7 +5,16 @@ Version: 3 ## Grammar ```bnf -program ::= { externDeclaration } { funcDeclaration } { statement } EOF +program ::= { topDeclaration } EOF + +topDeclaration ::= externDeclaration + | funcDeclaration + +externDeclaration ::= "extern" "def" IDENT "(" [ paramList ] ")" ";" + +funcDeclaration ::= "def" IDENT "(" [ paramList ] ")" block + +paramList ::= IDENT { "," IDENT } statement ::= returnStatement @@ -39,12 +48,6 @@ breakStatement ::= "break" ";" continueStatement ::= "continue" ";" -externDeclaration ::= "extern" "def" IDENT "(" [ paramList ] ")" ";" - -funcDeclaration ::= "def" IDENT "(" [ paramList ] ")" block - -paramList ::= IDENT { "," IDENT } - ; Expression definitions go from lowest operator precedence ; to the highest, allowing for straightforward expression parsing. @@ -141,17 +144,48 @@ All semantic rules from grammar 2 apply, plus: - **Function definitions** use `def name(params) { body }`. Parameters are passed by value. A function must have a `return` statement if it returns a value. - **Functions are visible anywhere** in the program after they are defined (forward - references are allowed — the compiler can collect all function definitions before + references are allowed --- the compiler can collect all function definitions before codegen). - **`extern` declarations** declare a C function with no body. These are linked with the compiled program at the end. The calling convention is the C ABI. - **Function calls** are expressions. A call evaluates all arguments, then transfers control to the function. The function's return value is the result of the call expression. -- **Top-level statements** (outside any function) form the body of the implicit - `main()` function. Top-level statements are executed in order when the program - starts. A `return` at the top level returns from `main()`. -- **All values remain `Int64`** — no type system yet. Functions take `Int64` +- **All values remain `Int64`** --- no type system yet. Functions take `Int64` parameters and return `Int64`. +- **A `main` function must be explicitly defined** Top-level statements are not allowed. - **Error recovery**: see [`doc/error-handling.md`](error-handling.md) for the - recommended error recovery strategy. \ No newline at end of file + recommended error recovery strategy. + +## Token kinds (new in grammar 3) + +These `"kind"` values appear in `tokens.json` golden files, in addition to those from grammar 1–2: + +| Token kind | Grammar source | Notes | +|---|---|---| +| `DEF` | `def` | Keyword | +| `EXTERN` | `extern` | Keyword | +| `COMMA` | `,` | Parameter/argument separator | + +All tokens from grammar 1–2 also apply. + +### Example + +> TODO + +## AST node kinds (new in grammar 3) + +These `"kind"` values appear in `ast.json` golden files, in addition to those from grammar 1–2: + +| AST kind | `elems[]` children | Notes | +|---|---|---| +| `ExternDecl` | `[name, params...]` | `external def` function declaration | +| `FuncDecl` | `[name, params..., body]` | `def` function declaration with body as `Block` node | +| `Param` | `[name]` | Name is an `Ident` node | +| `Call` | `[callee, args...]` | Callee is an `Ident` node followed by argument expressions | + +All AST kinds from grammar 1–2 also apply. + +### Example + +> TODO diff --git a/doc/grammar4.g4 b/doc/grammar4.g4 index e1671a5..a45a51c 100644 --- a/doc/grammar4.g4 +++ b/doc/grammar4.g4 @@ -14,7 +14,23 @@ grammar grammar4; // lexer runs a single-line comment to end-of-line, a generated line comment // must always end with a newline (whitespace.py guarantees this). -program : externDeclaration* funcDeclaration* EOF; +program : topDeclaration* EOF; + +topDeclaration + : externDeclaration + | funcDeclaration + +// extern declaration for C interop with typed parameters and return type. +externDeclaration : 'extern' 'def' IDENT '(' typedParamList? ')' ':' type ';'; + +// Function declaration with typed parameters and return type. +funcDeclaration : 'def' IDENT '(' typedParamList? ')' ':' type block; + +// Type annotation on each parameter. +typedParamList : IDENT ':' type (',' IDENT ':' type)*; + +// Primitive and built-in types. +type : INT8 | INT16 | INT32 | INT64 | BOOL | STRING; statement : returnStatement @@ -52,18 +68,6 @@ breakStatement : 'break' ';'; continueStatement : 'continue' ';'; -// extern declaration for C interop with typed parameters and return type. -externDeclaration : 'extern' 'def' IDENT '(' typedParamList? ')' ':' type ';'; - -// Function declaration with typed parameters and return type. -funcDeclaration : 'def' IDENT '(' typedParamList? ')' ':' type block; - -// Type annotation on each parameter. -typedParamList : IDENT ':' type (',' IDENT ':' type)*; - -// Primitive and built-in types. -type : INT8 | INT16 | INT32 | INT64 | BOOL | STRING; - // Expression definitions go from lowest operator precedence // to the highest, allowing for straightforward expression parsing. expression : logicalOrExpression; @@ -140,4 +144,4 @@ IDENT : [a-zA-Z_] [a-zA-Z0-9_]*; // parser rule references them. WS : [ \t\n\r]+; LINE_COMMENT : '//' ~[\r\n]*; -BLOCK_COMMENT : '/*' .*? '*/'; \ No newline at end of file +BLOCK_COMMENT : '/*' .*? '*/'; diff --git a/doc/grammar4.md b/doc/grammar4.md index 3faf4d1..00c35b1 100644 --- a/doc/grammar4.md +++ b/doc/grammar4.md @@ -5,7 +5,26 @@ Version: 4 ## Grammar ```bnf -program ::= { externDeclaration } { funcDeclaration } { statement } EOF +program ::= { topDeclaration } EOF + +topDeclaration ::= externDeclaration + | funcDeclaration + +externDeclaration ::= + "extern" "def" IDENT "(" [ typedParamList ] ")" ":" type ";" + +funcDeclaration ::= + "def" IDENT "(" [ typedParamList ] ")" ":" type block + +typedParamList ::= IDENT ":" type { "," IDENT ":" type } + + +; Type definitions + +type ::= "Int8" | "Int16" | "Int32" | "Int64" + | "Bool" + | "String" + statement ::= returnStatement @@ -40,22 +59,6 @@ breakStatement ::= "break" ";" continueStatement ::= "continue" ";" -externDeclaration ::= - "extern" "def" IDENT "(" [ typedParamList ] ")" ":" type ";" - -funcDeclaration ::= - "def" IDENT "(" [ typedParamList ] ")" ":" type block - -typedParamList ::= IDENT ":" type { "," IDENT ":" type } - - -; Type definitions - -type ::= "Int8" | "Int16" | "Int32" | "Int64" - | "Bool" - | "String" - - ; Expression definitions go from lowest operator precedence ; to the highest, allowing for straightforward expression parsing. ; Comparison operators produce Bool values. @@ -173,7 +176,7 @@ All semantic rules from grammar 3 apply, plus: - **`cast(expr)** supports: - Integer widening: `Int8` → `Int16` → `Int32` → `Int64` (LLVM: `sext`) - Integer narrowing: `Int64` → `Int32` → `Int16` → `Int8` (LLVM: `trunc`) - - `Bool` to integer: `Bool` → `Int8`/`Int16`/`Int32`/`Int64` (LLVM: `zext` — zero extension, not `sext`) + - `Bool` to integer: `Bool` → `Int8`/`Int16`/`Int32`/`Int64` (LLVM: `zext` --- zero extension, not `sext`) - Integer to `Bool`: `Int8`/`Int16`/`Int32`/`Int64` → `Bool` (LLVM: `icmp ne %val, 0` or `trunc` to `i1`) - **String literals** are of type `String`. A string literal is a null-terminated byte array compiled as a global constant. `String` maps to `ptr` in LLVM IR. @@ -198,3 +201,42 @@ All semantic rules from grammar 3 apply, plus: - **Extern functions** must specify parameter and return types: `extern def foo(x: Int64): Int64;` - **Error recovery**: see [`doc/error-handling.md`](error-handling.md) for the recommended error recovery strategy. + +## Token kinds (new in grammar 4) + +These `"kind"` values appear in `tokens.json` golden files, in addition to those from grammar 1–3: + +| Token kind | Grammar source | Notes | +|---|---|---| +| `INT8` | `Int8` | Type keyword | +| `INT16` | `Int16` | Type keyword | +| `INT32` | `Int32` | Type keyword | +| `INT64` | `Int64` | Type keyword | +| `BOOL` | `Bool` | Type keyword | +| `STRING` | `String` | Type keyword | +| `CAST` | `cast` | Type conversion keyword | +| `COLON` | `:` | Type annotation separator | +| `STR` | `STRING_LITERAL` | String literal content | + +All tokens from grammar 1–3 also apply. + +### Example + +> TODO + +## AST node kinds (new in grammar 4) + +These `"kind"` values appear in `ast.json` golden files, in addition to those from grammar 1–3: + +| AST kind | `elems[]` children | Notes | +|---|---|---| +| `StringLiteral` | `[]` | | +| `Cast` | `[value]` | Has additional `type` property with the target type name | + +### Type annotations + +> TODO + +### Example + +> TODO diff --git a/doc/grammar5.g4 b/doc/grammar5.g4 index 700e5ea..a3c7fbe 100644 --- a/doc/grammar5.g4 +++ b/doc/grammar5.g4 @@ -13,7 +13,27 @@ grammar grammar5; // lexer runs a single-line comment to end-of-line, a generated line comment // must always end with a newline (whitespace.py guarantees this). -program : structDeclaration* externDeclaration* funcDeclaration* EOF; +program : topDeclaration* EOF; + +topDeclaration + : externDeclaration + | funcDeclaration + | structDeclaration + +// extern declaration for C interop with typed parameters and return type. +externDeclaration : 'extern' 'def' IDENT '(' typedParamList? ')' ':' type ';'; + +// Function declaration with typed parameters and return type. +funcDeclaration : 'def' IDENT '(' typedParamList? ')' ':' type block; + +// Type annotation on each parameter. +typedParamList : IDENT ':' type (',' IDENT ':' type)*; + +// Types: primitive types, struct type (identifier), array type. +type : INT8 | INT16 | INT32 | INT64 | BOOL | STRING + | IDENT + | type '[' INTEGER_LITERAL ']' + ; statement : returnStatement @@ -59,21 +79,6 @@ breakStatement : 'break' ';'; continueStatement : 'continue' ';'; -// extern declaration for C interop with typed parameters and return type. -externDeclaration : 'extern' 'def' IDENT '(' typedParamList? ')' ':' type ';'; - -// Function declaration with typed parameters and return type. -funcDeclaration : 'def' IDENT '(' typedParamList? ')' ':' type block; - -// Type annotation on each parameter. -typedParamList : IDENT ':' type (',' IDENT ':' type)*; - -// Types: primitive types, struct type (identifier), array type. -type : INT8 | INT16 | INT32 | INT64 | BOOL | STRING - | IDENT - | type '[' INTEGER_LITERAL ']' - ; - // Expression definitions go from lowest operator precedence // to the highest, allowing for straightforward expression parsing. expression : logicalOrExpression; @@ -156,4 +161,4 @@ IDENT : [a-zA-Z_] [a-zA-Z0-9_]*; // parser rule references them. WS : [ \t\n\r]+; LINE_COMMENT : '//' ~[\r\n]*; -BLOCK_COMMENT : '/*' .*? '*/'; \ No newline at end of file +BLOCK_COMMENT : '/*' .*? '*/'; diff --git a/doc/grammar5.md b/doc/grammar5.md index 9df558a..d0bf02c 100644 --- a/doc/grammar5.md +++ b/doc/grammar5.md @@ -5,7 +5,29 @@ Version: 5 ## Grammar ```bnf -program ::= { structDeclaration } { externDeclaration } { funcDeclaration } { statement } EOF +program ::= { topDeclaration } EOF + +topDeclaration ::= externDeclaration + | funcDeclaration + | structDeclaration + +externDeclaration ::= + "extern" "def" IDENT "(" [ typedParamList ] ")" ":" type ";" + +funcDeclaration ::= + "def" IDENT "(" [ typedParamList ] ")" ":" type block + +typedParamList ::= IDENT ":" type { "," IDENT ":" type } + + +; Type definitions + +type ::= "Int8" | "Int16" | "Int32" | "Int64" + | "Bool" + | "String" + | IDENT ; struct type (name) + | type "[" INTEGER_LITERAL "]" ; array type + statement ::= returnStatement @@ -48,24 +70,6 @@ breakStatement ::= "break" ";" continueStatement ::= "continue" ";" -externDeclaration ::= - "extern" "def" IDENT "(" [ typedParamList ] ")" ":" type ";" - -funcDeclaration ::= - "def" IDENT "(" [ typedParamList ] ")" ":" type block - -typedParamList ::= IDENT ":" type { "," IDENT ":" type } - - -; Type definitions - -type ::= "Int8" | "Int16" | "Int32" | "Int64" - | "Bool" - | "String" - | IDENT ; struct type (name) - | type "[" INTEGER_LITERAL "]" ; array type - - ; Expression definitions go from lowest operator precedence ; to the highest, allowing for straightforward expression parsing. ; Comparison operators produce Bool values. @@ -201,5 +205,64 @@ All semantic rules from grammar 4 apply, plus: - **Arrays are value types**: an array assignment (`a = b`) copies all elements by value (LLVM `memcpy`). Arrays are stack-allocated in their declaring scope and cannot be passed to or returned from functions. +- **Variables can be declared without an initializer**: `var x: Int64;` means the variable + is zero-initialized. +- **Assignment targets** can be complex lvalues (field access, array subscript, or + chains thereof), not just simple identifiers. - **Error recovery**: see [`doc/error-handling.md`](error-handling.md) for the recommended error recovery strategy. + +## Token kinds (new in grammar 5) + +These `"kind"` values appear in `tokens.json` golden files, in addition to those from grammar 1–4: + +| Token kind | Grammar source | Notes | +|---|---|---| +| `STRUCT` | `struct` | Keyword | +| `LBRACKET` | `[` | Array subscript / type opening bracket | +| `RBRACKET` | `]` | Array subscript / type closing bracket | +| `DOT` | `.` | Field access operator | + +All tokens from grammar 1–4 also apply. + +### Example + +> TODO + +## AST node kinds (new in grammar 5) + +These `"kind"` values appear in `ast.json` golden files, in addition to those from grammar 1–4: + +| AST kind | `elems[]` children | Notes | +|---|---|---| +| `StructDecl` | `[name, fields...]` | Name is an `Ident` node and each field is a `Declare` node | +| `FieldAccess` | `[base, name]` | Dot-access to a struct field, name is an `Ident` | +| `Subscript` | `[base, index]` | Array index access | + +### Type annotations + +> TODO + +### Declaration without initializer (grammar 5) + +Grammar 5 allows variable declarations without an initializer: +``` +var x: Int64; +``` +In the AST, `Declare.elems` will be `[]` (empty) when there is no initializer. + +### Assignment target in grammar 5 + +The assignment target changes from a simple `Ident` to a `postfixExpression`, +which can be: +- An `Ident` (simple variable) +- A `FieldAccess` (e.g., `point.x = 10`) +- A `Subscript` (e.g., `arr[0] = 5`) +- A chain of field accesses and subscripts (e.g., `arr[0].x = 1`) + +The AST `Assign` node always has `elems[0]` = target and `elems[1]` = value, +regardless of the target's complexity. + +### Example + +> TODO diff --git a/doc/json-formats.md b/doc/json-formats.md new file mode 100644 index 0000000..9b1c94e --- /dev/null +++ b/doc/json-formats.md @@ -0,0 +1,335 @@ +# JSON Formats and Schemas + +## Overview + +The SysProLang test suite uses JSON files to store golden test data for the lexer +and parser stages. These files are validated against JSON Schema definitions to +ensure consistency across test cases and compiler implementations. + +## Schema files location + +All schema files live in `test/schemas/`: + +| Schema file | Validates | Description | +|---|---|---| +| `test/schemas/tokens.schema.json` | `tokens.json` | Token streams produced by the lexer | +| `test/schemas/ast.schema.json` | `ast.json` | AST trees produced by the parser | +| `test/schemas/meta.schema.json` | `meta.json` | Test case metadata | +| `test/schemas/config.schema.json` | `test/config.json` | Test runner configuration | + +## Schema enforcement + +### Validation script + +Run `test/validate_schemas.py` to validate all JSON files against their schemas: + +```bash +python3 test/validate_schemas.py +``` + +This script: +1. Loads all schema definitions from `test/schemas/`. +2. Scans recursively for `config.json`, `meta.json`, `tokens.json`, and `ast.json` + files under the `test/` directory. +3. Validates each file against its respective schema using the `jsonschema` Python + package. +4. Prints a checkmark (✓) for each valid file, or a cross (✗) with error details. +5. Exits with code 0 if all files are valid, 1 otherwise. + +### Dependency + +Install the `jsonschema` package: + +```bash +pip install jsonschema +``` + +### CI enforcement + +The CI workflow validates all schema files on every push. A PR with invalid JSON +files will be blocked. + +--- + +## Token JSON format (`tokens.json`) + +### Schema rules + +- The file is a **JSON array** (top-level type: `array`). +- Every element is a **token object** with **required** properties: + - `kind` (string): token kind identifier (e.g., `"IDENT"`, `"INT"`, `"PLUS"`, + `"SEMI"`, `"EOF"`, etc.) + - `line` (integer >= 1): source line where the token starts (1-based). + - `column` (integer >= 1): source column where the token starts (1-based). +- No other properties are kept during golden comparison (the test runner's lexer + stage preprocessor applies `{"keep": ["kind", "line", "column"]}`). +- The array must have at least 1 element (the `EOF` token is always present). +- The `kind` values are uppercase names like `IDENT`, `INT`, `PLUS`, `SEMI`, `EOF`, + `IF`, `WHILE`, `RETURN`, `DEF`, `COLON`, `INT64`, `STRUCT`, `DOT`, etc. +- See each grammar `.md` file for the full list of token kinds introduced at each + grammar version. + +### Token comparison + +During testing, both the golden `tokens.json` and the compiler's output are passed +through a JSON filter that drops all fields except `kind`, `line`, `column`. This +means the `value` field (which contains the raw token text in compiler output) is +**not compared**, allowing different compilers to use different string representations. + +### Example + +Source: + +```scala +var x = 10; +return x / 2; +``` + +```json +[ +{"kind": "VAR", "value": "var", "line": 1, "column": 1}, +{"kind": "IDENT", "value": "x", "line": 1, "column": 5}, +{"kind": "ASSIGN", "value": "=", "line": 1, "column": 7}, +{"kind": "INT", "value": "10", "line": 1, "column": 9}, +{"kind": "SEMI", "value": ";", "line": 1, "column": 11}, +{"kind": "RETURN", "value": "return", "line": 2, "column": 1}, +{"kind": "IDENT", "value": "x", "line": 2, "column": 8}, +{"kind": "DIV", "value": "/", "line": 2, "column": 10}, +{"kind": "INT", "value": "2", "line": 2, "column": 12}, +{"kind": "SEMI", "value": ";", "line": 2, "column": 13}, +{"kind": "EOF", "value": "", "line": 2, "column": 14} +] +``` + +### Token kind reference + +See each grammar `.md` file for the complete list of token kinds (`"kind"` values) +introduced at each grammar version: + +- [`doc/grammar1.md`](grammar1.md#token-kinds) — base tokens +- [`doc/grammar2.md`](grammar2.md#token-kinds-new-in-grammar-2) — control flow, boolean, comparison, logical +- [`doc/grammar3.md`](grammar3.md#token-kinds-new-in-grammar-3) — function definitions, extern +- [`doc/grammar4.md`](grammar4.md#token-kinds-new-in-grammar-4) — type keywords, cast, string +- [`doc/grammar5.md`](grammar5.md#token-kinds-new-in-grammar-5) — struct, array subscript, field access + +--- + +## AST JSON format (`ast.json`) + +### Schema rules + +The schema defines a recursive `astNode` object with: + +**Required properties** (every node must have these): + +| Property | Type | Description | +|---|---|---| +| `line` | integer (>= 1) | Source line number where the node starts (1-based) | +| `column` | integer (>= 1) | Source column where the node starts (1-based) | +| `kind` | string | AST node kind (e.g., `"Program"`, `"Declare"`, `"IntLiteral"`, `"BinOp"`, etc.) | +| `elems` | array of `astNode` | Ordered list of child nodes (may be `[]`) | + +**Additional properties** are allowed (not required, not restricted). These include +named attributes like `value`, `mut`, `type`, etc. + +### AST comparison + +During testing, both the golden `ast.json` and the compiler's output are passed +through a JSON filter that keeps only `kind`, `line`, `column`, `elems`. +All extra named fields (like `value`, `mut`, `type`, `name`, `op`, `message`, +`field`) are **dropped during comparison**. This means: + +- The structure of the tree (what `elems` contains) is compared. +- Named extra properties serve as human-readable annotations but are not + enforced in golden comparisons. + +### The `elems[]` array convention + +The `elems[]` array contains all child nodes in a fixed order. Named relationships +(left vs right, condition vs body, etc.) are **positional**: + +| Node kind | `elems[]` order | Number of children | +|---|---|---| +| `Program` | top-level statements | N | +| `Block` | statements | N | +| `Return` | `[value]` | 1 (or 0 if missing) | +| `Declare` | `[name, expr?]` | 1 or 2 | +| `Assign` | `[name, expr]` | 2 | +| `If` | `[cond, thenBody, elseBody?]` | 2 or 3 | +| `While` | `[cond, body]` | 2 | +| `Break` | `[]` | 0 | +| `Continue` | `[]` | 0 | +| `IntLiteral` | `[]` | 0 | +| `BoolLiteral` | `[]` | 0 | +| `StringLiteral` | `[]` | 0 | +| `Ident` | `[]` | 0 | +| `BinOp` | `[left, right]` | 2 | +| `Unary` | `[operand]` | 1 | +| `Call` | `[callee, args...]` | 1 + N | +| `FuncDecl` | `[name, params..., body]` | N_params + 2 | +| `ExternDecl` | `[name, params...]` | N_params + 1 | +| `Param` | `[name]` | 1 | +| `Cast` | `[value]` | 1 | +| `StructDecl` | `[name, fields...]` | N_fields + 1 | +| `FieldAccess` | `[base, name]` | 2 | +| `Subscript` | `[base, index]` | 2 | +| `Error` | `[]` | 0 | + +### Example + +Source: + +```scala +var x = 10; +return x / 2; +``` + +```json +{ + "line": 1, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "Declare", + "mut": "var", + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "value": "x" + "elems": [], + }, + { + "line": 1, + "column": 9, + "kind": "IntLiteral", + "value": 10, + "elems": [] + } + ], + }, + { + "line": 2, + "column": 1, + "kind": "Return", + "elems": [ + { + "line": 2, + "column": 10, + "kind": "BinOp", + "value": "/" + "elems": [ + { + "line": 2, + "column": 8, + "kind": "Ident", + "value": "x" + "elems": [], + }, + { + "line": 2, + "column": 12, + "kind": "IntLiteral", + "value": 2, + "elems": [] + } + ], + } + ] + } + ], +} +``` + +--- + +## Meta JSON format (`meta.json`) + +The `meta.json` file describes a test case's metadata. See +[`test/schemas/meta.schema.json`](../test/schemas/meta.schema.json) for the full +schema. + +### Required properties + +- `grammar`: grammar version constraint (string, list, or per-stage dict). +- `stages`: list of stage names to run (e.g., `["lexer", "parser"]`). +- `exit`: expected exit code (integer, `"nonzero"`, or per-stage dict). + +### Example + +```json +{ + "$schema": "../../schemas/meta.schema.json", + "grammar": ">=2", + "stages": ["lexer", "parser"], + "exit": 0 +} +``` + +The `$schema` key is optional but recommended for editor LSP support. + +--- + +## Config JSON format (`config.json`) + +The `test/config.json` file configures the test runner. It defines: + +- Build command +- Default grammar version +- Available grammar versions +- Per-stage commands and output paths +- Preprocessing pipelines +- Fuzz testing parameters + +See [`test/config.json`](../test/config.json) and +[`test/schemas/config.schema.json`](../test/schemas/config.schema.json) for details. + +--- + +## Preprocessing and golden comparison + +Both `tokens.json` and `ast.json` go through a preprocessing step before +diffing against golden files, defined in `test/config.json`: + +```json +{ + "lexer": { + "preprocess": [{"type": "json", "keep": ["kind", "line", "column"]}] + }, + "parser": { + "preprocess": [{"type": "json", "keep": ["kind", "line", "column", "elems"]}] + } +} +``` + +The `json` preprocessor recursively filters each object tree, keeping only the +listed scalar fields while preserving all nested objects and arrays. This makes +golden comparison robust to differences in extra fields that different compilers +may or may not emit. + +### What gets compared + +| Stage | Golden file | Compared fields | +|---|---|---| +| lexer | `tokens.json` | `kind`, `line`, `column` | +| parser | `ast.json` | `kind`, `line`, `column`, `elems` | +| llvm | `out.ll` | Full text (after LLVM name normalization) | +| run | `stdout` | Full text (optional tolerance) | + +> LLVM IR golden comparison (`out.ll`) is opt-in with `--check-ir`. +> By default, only lexer, parser, and run stages are checked. + +## Grammar-by-grammar AST and token reference + +For a detailed, grammar-by-grammar breakdown of which token kinds and AST node +kinds are introduced, see: + +- [`doc/grammar1.md`](grammar1.md) — Token kinds and AST nodes for grammar 1 +- [`doc/grammar2.md`](grammar2.md) — Token kinds and AST nodes new in grammar 2 +- [`doc/grammar3.md`](grammar3.md) — Token kinds and AST nodes new in grammar 3 +- [`doc/grammar4.md`](grammar4.md) — Token kinds and AST nodes new in grammar 4 +- [`doc/grammar5.md`](grammar5.md) — Token kinds and AST nodes new in grammar 5 diff --git a/test/.self-test/test_harness.py b/test/.self-test/test_harness.py index 03aab72..00d4ec3 100644 --- a/test/.self-test/test_harness.py +++ b/test/.self-test/test_harness.py @@ -128,8 +128,8 @@ def test_list_lists_tests(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind", "line", "column"])) rc, out = run(["list", "--config", cfg]) assert rc == 0 - assert "lexer/a" in out - assert "lexer/b" in out + assert " a" in out + assert " b" in out def test_stage_and_name_filters(harness, run): @@ -142,10 +142,10 @@ def test_stage_and_name_filters(harness, run): }) rc, out = run(["list", "--config", cfg, "--stage", "lexer"]) assert rc == 0 - assert "lexer/alpha" in out and "parser/gamma" not in out + assert " alpha" in out and "=== PARSER ===" not in out rc, out = run(["list", "--config", cfg, "--test", "beta"]) assert rc == 0 - assert "lexer/beta" in out and "lexer/alpha" not in out + assert " beta" in out and " alpha" not in out def test_grammar_version_filter(harness, run): @@ -154,12 +154,12 @@ def test_grammar_version_filter(harness, run): add_lexer(harness, "any") cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["list", "--config", cfg, "--grammar", "1"]) - assert "lexer/v1" in out and "lexer/v2" not in out and "lexer/any" in out + assert " v1" in out and " v2" not in out and " any" in out rc, out = run(["list", "--config", cfg, "--grammar", "2"]) - assert "lexer/v2" in out and "lexer/v1" not in out + assert " v2" in out and " v1" not in out add_lexer(harness, "v2plus", meta={"grammar": ">=2"}) rc, out = run(["list", "--config", cfg, "--grammar", "2"]) - assert "lexer/v2plus" in out + assert " v2plus" in out def test_nested_test_paths(harness, run): @@ -169,8 +169,8 @@ def test_nested_test_paths(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["list", "--config", cfg]) assert rc == 0 - assert "lexer/grammar2/booleans/if-else" in out - assert "lexer/grammar3/functions/calls/nested" in out + assert " grammar2/booleans/if-else" in out + assert " grammar3/functions/calls/nested" in out def test_exclude_boolean_skips_test(harness, run): @@ -180,8 +180,8 @@ def test_exclude_boolean_skips_test(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind", "line", "column"])) rc, out = run(["list", "--config", cfg]) assert rc == 0 - assert "lexer/should-run" in out - assert "lexer/should-skip" not in out + assert " should-run" in out + assert " should-skip" not in out def test_exclude_false_runs_test(harness, run): @@ -190,7 +190,7 @@ def test_exclude_false_runs_test(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind", "line", "column"])) rc, out = run(["list", "--config", cfg]) assert rc == 0 - assert "lexer/runs" in out + assert " runs" in out def test_exclude_shown_in_summary(harness, run): @@ -202,7 +202,7 @@ def test_exclude_shown_in_summary(harness, run): assert rc == 0 assert "EXCLUDED hidden" in out assert "1 EXCLUDED" in out - assert "PASS lexer/active" in out + assert "PASS active" in out def test_grammar_list_constraint(harness, run): @@ -210,11 +210,11 @@ def test_grammar_list_constraint(harness, run): add_lexer(harness, "v12", meta={"grammar": ["1", "2"]}) cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["list", "--config", cfg, "--grammar", "1"]) - assert "lexer/v12" in out + assert " v12" in out rc, out = run(["list", "--config", cfg, "--grammar", "2"]) - assert "lexer/v12" in out + assert " v12" in out rc, out = run(["list", "--config", cfg, "--grammar", "3"]) - assert "lexer/v12" not in out + assert " v12" not in out def test_compare_tolerance_edges(harness, run): @@ -259,7 +259,7 @@ def test_golden_pass(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind", "line", "column"])) rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "PASS lexer/ok" in out + assert "PASS ok" in out def test_golden_fail_prints_diff(harness, run): @@ -267,7 +267,7 @@ def test_golden_fail_prints_diff(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 1 - assert "FAIL lexer/bad" in out + assert "FAIL bad" in out assert "diff" in out @@ -286,7 +286,7 @@ def test_exit_only_nonzero_no_golden(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "PASS lexer/neg" in out + assert "PASS neg" in out def test_exit_only_exact_code_auto_discover(harness, run): @@ -296,7 +296,7 @@ def test_exit_only_exact_code_auto_discover(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "PASS lexer/exit5" in out + assert "PASS exit5" in out def test_exit_only_stages_list_skips(harness, run): @@ -306,15 +306,7 @@ def test_exit_only_stages_list_skips(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "SKIP lexer/skipme" in out - - -def test_nonzero_exit_negative_pass(harness, run): - add_lexer(harness, "neg", src="// exit: 3\n", meta={"exit": "nonzero"}) - cfg = harness.write_config(stages=lexer_stage(["kind"])) - rc, out = run(["test", "--config", cfg]) - assert rc == 0 - assert "PASS lexer/neg" in out + assert "SKIP skipme" in out def test_crash_fails(harness, run): @@ -322,7 +314,7 @@ def test_crash_fails(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 1 - assert "FAIL lexer/crash" in out + assert "FAIL crash" in out def test_timeout_fails(harness, run): @@ -340,7 +332,7 @@ def test_missing_stage_skips(harness, run): cfg = harness.write_config(stages={}) # no stages configured rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "SKIP lexer/x" in out + assert "SKIP x" in out assert "not configured" in out @@ -358,7 +350,7 @@ def test_update_regenerates_golden(harness, run): assert golden.exists() # Re-running now passes against the regenerated golden. rc, out = run(["test", "--config", cfg]) - assert rc == 0 and "PASS lexer/u" in out + assert rc == 0 and "PASS u" in out def test_update_no_output_fails(harness, run): @@ -404,12 +396,12 @@ def test_fuzz_creates_tests_and_orders_after_committed(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind", "line", "column"]), fuzz=make_fuzz_config()) rc, out = run(["test", "--fuzz", "--fuzz-count", "3", "--fuzz-seed", "7", "--config", cfg]) assert rc == 0 - committed_pos = out.index("lexer/committed") + committed_pos = out.index("PASS committed") fuzz_pos = out.index("---- fuzz tests ----") assert committed_pos < fuzz_pos assert "fuzz: grammar version(s) 1" in out assert "generated in" in out and "seed 7" in out - assert "PASS lexer/fuzz_0000" in out + assert "PASS fuzz_0000" in out def test_stop_on_fail_skips_fuzz(harness, run): @@ -428,8 +420,8 @@ def test_parallel_keeps_order(harness, run): rc, out = run(["test", "-j", "8", "--config", cfg]) assert rc == 0 for i in range(20): - assert out.index(f"lexer/t{i:02d}") - names = [line.split()[1] for line in out.splitlines() if "lexer/t" in line] + assert f"PASS t{i:02d}" in out + names = [line.split()[1] for line in out.splitlines() if line.startswith("PASS") or line.startswith("FAIL")] assert names == sorted(names) # deterministic ordering @@ -459,7 +451,7 @@ def test_malformed_meta_fails(harness, run): cfg = harness.write_config(stages=lexer_stage(["kind"])) rc, out = run(["test", "--config", cfg]) assert rc == 1 - assert "FAIL lexer/bad" in out + assert "FAIL bad" in out # --------------------------------------------------------------------------- @@ -476,7 +468,7 @@ def compiler_config(compile_cmd, run_cmd, run_preprocess=None): run = {"cmd": run_cmd} if run_preprocess: run["preprocess"] = run_preprocess - return {"compile": {"cmd": compile_cmd}, "run": run} + return {"compiler": {"cmd": compile_cmd}, "run": run} def test_compiler_run_end_to_end_pass(harness, run): @@ -484,7 +476,7 @@ def test_compiler_run_end_to_end_pass(harness, run): cfg = harness.write_config( stages=compiler_config(compile_exe('print("hello")'), ["python3", "{exe}"])) rc, out = run(["test", "--config", cfg]) - assert rc == 0 and "PASS compiler/hw" in out + assert rc == 0 and "PASS hw" in out def test_compiler_stdin_and_run_preprocess(harness, run): @@ -497,17 +489,17 @@ def test_compiler_stdin_and_run_preprocess(harness, run): ) cfg = harness.write_config(stages=stages) rc, out = run(["test", "--config", cfg]) - assert rc == 0 and "PASS compiler/hw" in out + assert rc == 0 and "PASS hw" in out def test_compiler_compile_failure(harness, run): harness.add_test("cbad", src="// exit: 3\n", meta={"stages": ["compiler"]}) - stages = {"compile": {"cmd": ["{root}/mock_compiler.py", "{input}"]}, + stages = {"compiler": {"cmd": ["{root}/mock_compiler.py", "{input}"]}, "run": {"cmd": ["python3", "{exe}"]}} cfg = harness.write_config(stages=stages) rc, out = run(["test", "--config", cfg]) assert rc == 1 - assert "FAIL compiler/cbad" in out + assert "FAIL cbad" in out assert "compile failed (exit 3)" in out @@ -517,34 +509,38 @@ def test_compiler_tolerance_pass_and_diff_fail(harness, run): harness.add_test("hw", src="0;", stdout=golden) harness.add_test("hw", src="0;", stdout=golden, meta={"tolerance": 0.1}) rc, out = run(["test", "--config", harness.write_config(stages=stages)]) - assert rc == 0 and "PASS compiler/hw" in out + assert rc == 0 and "PASS hw" in out # Second run with same test but no tolerance in meta -> will fail because # the golden differs from actual output. But meta doesn't have tolerance, # so we create the test without tolerance meta. harness.add_test("hw2", src="0;", stdout=golden) rc, out = run(["test", "--config", harness.write_config(stages=stages)]) - assert rc == 1 and "FAIL compiler/hw2" in out + assert rc == 1 and "FAIL hw2" in out def test_compiler_exit_contract(harness, run): - stages = compiler_config(compile_exe("import sys;sys.exit(5)"), ["python3", "{exe}"]) - harness.add_test("hw", src="0;", meta={"exit": "nonzero", "stages": ["compiler"]}) + # Use mock_compiler which exits 5 for // exit: 5 source + harness.write("hw", "test.spl", "// exit: 5\n") + harness.write("hw", "meta.json", json.dumps({"exit": "nonzero", "stages": ["compiler"]})) + stages = {"compiler": {"cmd": ["{root}/mock_compiler.py", "{input}"]}} rc, out = run(["test", "--config", harness.write_config(stages=stages)]) - assert rc == 0 and "PASS compiler/hw" in out + assert rc == 0 and "PASS hw" in out # Exact 0 contract with a golden -> fails on exit mismatch harness.add_test("hw2", src="0;", stdout="unused\n", meta={"exit": 0}) - rc, out = run(["test", "--config", harness.write_config(stages=stages)]) + # For the run stage we need both compiler and run config + stages2 = compiler_config(compile_exe("import sys;sys.exit(5)"), ["python3", "{exe}"]) + rc, out = run(["test", "--config", harness.write_config(stages=stages2)]) assert rc == 1 and "exit: expected 0, got 5" in out def test_compiler_update_regenerates_and_exit_warning(harness, run): - stages = compiler_config(compile_exe("import sys;sys.exit(5)"), ["python3", "{exe}"]) + stages = compiler_config(compile_exe("import sys;print('hello');sys.exit(5)"), ["python3", "{exe}"]) harness.add_test("hw", src="0;", meta={"exit": 0, "stages": ["compiler"]}) cfg = harness.write_config(stages=stages) rc, out = run(["update", "--config", cfg]) assert rc == 0 - assert "UPD compiler/hw" in out + assert "UPD hw" in out assert "exit contract not met" in out golden = harness.root / "hw" / "stdout" assert golden.exists() @@ -562,7 +558,7 @@ def test_out_defaults_to_stdout_mode(harness, run): stage = {"cmd": ["python3", "-S", "-c", "print('STDX')"]} # no "out" key cfg = harness.write_config(stages={"lexer": stage}) rc, out = run(["test", "--config", cfg, "--keep", "all"]) - assert rc == 0 and "PASS lexer/a" in out + assert rc == 0 and "PASS a" in out raw = harness.out_dir / "lexer" / "a" / "lexer.raw" assert raw.exists() and raw.read_text() == "STDX\n" @@ -575,7 +571,7 @@ def test_stage_out_file_not_produced_fails(harness, run): cfg = harness.write_config(stages={"lexer": stage}) rc, out = run(["test", "--config", cfg]) assert rc == 1 - assert "FAIL lexer/a" in out + assert "FAIL a" in out assert "stage wrote no output to" in out @@ -642,7 +638,7 @@ def test_preprocess_regex_and_exec(harness, run): } cfg = harness.write_config(stages={"lexer": stage}) rc, out = run(["test", "--config", cfg]) - assert rc == 0 and "PASS lexer/a" in out + assert rc == 0 and "PASS a" in out def test_preprocess_regex_delete_lines(harness, run): @@ -659,7 +655,7 @@ def test_preprocess_regex_delete_lines(harness, run): } cfg = harness.write_config(stages={"lexer": stage}) rc, out = run(["test", "--config", cfg]) - assert rc == 0 and "PASS lexer/a" in out + assert rc == 0 and "PASS a" in out def test_malformed_preprocess_exec_fails(harness, run): @@ -690,7 +686,7 @@ def test_preprocess_json_drop(harness, run): cfg = harness.write_config(stages={"lexer": stage}) rc, out = run(["test", "--config", cfg]) assert rc == 0 - assert "PASS lexer/a" in out + assert "PASS a" in out def test_preprocess_llvm_step(harness, run): @@ -708,7 +704,7 @@ def test_preprocess_llvm_step(harness, run): cfg = harness.write_config(stages={"llvm": stage}) rc, out = run(["test", "--config", cfg, "--check-ir"]) assert rc == 0 - assert "PASS llvm/ll" in out + assert "PASS ll" in out def test_preprocess_json_no_keep_drop_rejected(harness, run): diff --git a/test/config.json b/test/config.json index f664750..53e0dc2 100644 --- a/test/config.json +++ b/test/config.json @@ -16,7 +16,7 @@ "cmd": ["{root}/build/splc", "-g", "{grammar}", "-a", "{ast_in}", "{input}"], "out": "{ast_out}", "preprocess": [ - {"type": "json", "keep": ["kind", "line", "column"]} + {"type": "json", "keep": ["kind", "line", "column", "elems"]} ] }, "llvm": { diff --git a/test/grammar1/assignment-and-division/ast.json b/test/grammar1/assignment-and-division/ast.json index 8182903..513c385 100644 --- a/test/grammar1/assignment-and-division/ast.json +++ b/test/grammar1/assignment-and-division/ast.json @@ -1,43 +1,53 @@ { - "line": 2, - "column": 13, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 11, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, { "line": 2, - "column": 13, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, - "column": 12, + "column": 10, "kind": "BinOp", - "op": "/", - "left": { + "elems": [ + { "line": 2, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { + { "line": 2, "column": 12, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/block-comments-no-return/ast.json b/test/grammar1/block-comments-no-return/ast.json index 8775842..51ee1a7 100644 --- a/test/grammar1/block-comments-no-return/ast.json +++ b/test/grammar1/block-comments-no-return/ast.json @@ -2,17 +2,12 @@ "line": 3, "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 3, "column": 1, - "kind": "ExprStmt", - "value": { - "line": 3, - "column": 1, - "kind": "IntLiteral", - "value": 42 - } + "kind": "IntLiteral", + "elems": [] } ] } diff --git a/test/grammar1/block-comments/ast.json b/test/grammar1/block-comments/ast.json index 5eb714c..577baaf 100644 --- a/test/grammar1/block-comments/ast.json +++ b/test/grammar1/block-comments/ast.json @@ -1,18 +1,20 @@ { "line": 3, - "column": 10, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 3, - "column": 10, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } ] } diff --git a/test/grammar1/chained-declarations/ast.json b/test/grammar1/chained-declarations/ast.json index 43cdc5f..f9bb5dd 100644 --- a/test/grammar1/chained-declarations/ast.json +++ b/test/grammar1/chained-declarations/ast.json @@ -1,44 +1,60 @@ { - "line": 3, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 10, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, { "line": 2, - "column": 10, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, "column": 9, "kind": "Ident", - "name": "x" + "elems": [] } + ] }, { "line": 3, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "Ident", - "name": "y" + "elems": [] } + ] } ] } diff --git a/test/grammar1/declarations-and-return/ast.json b/test/grammar1/declarations-and-return/ast.json index 9bcb95c..26eb545 100644 --- a/test/grammar1/declarations-and-return/ast.json +++ b/test/grammar1/declarations-and-return/ast.json @@ -1,56 +1,73 @@ { - "line": 3, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 11, + "column": 1, "kind": "Declare", "mut": "val", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, { "line": 2, - "column": 14, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, - "column": 13, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 2, "column": 9, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { + { "line": 2, "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] }, { "line": 3, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "Ident", - "name": "y" + "elems": [] } + ] } ] } diff --git a/test/grammar1/expression-statement/ast.json b/test/grammar1/expression-statement/ast.json index 8546fb5..1b1f140 100644 --- a/test/grammar1/expression-statement/ast.json +++ b/test/grammar1/expression-statement/ast.json @@ -1,18 +1,13 @@ { "line": 1, - "column": 3, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 3, - "kind": "ExprStmt", - "value": { - "line": 1, - "column": 1, - "kind": "IntLiteral", - "value": 42 - } + "column": 1, + "kind": "IntLiteral", + "elems": [] } ] } diff --git a/test/grammar1/identifiers-and-literals/ast.json b/test/grammar1/identifiers-and-literals/ast.json index 390c8e1..0e7cd62 100644 --- a/test/grammar1/identifiers-and-literals/ast.json +++ b/test/grammar1/identifiers-and-literals/ast.json @@ -1,42 +1,39 @@ { - "line": 4, - "column": 2, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { - "line": 4, - "column": 2, - "kind": "ExprStmt", - "value": { - "line": 4, - "column": 2, + "line": 2, + "column": 3, + "kind": "BinOp", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "IntLiteral", + "elems": [] + }, + { + "line": 3, + "column": 4, "kind": "BinOp", - "op": "+", - "left": { - "line": 1, + "elems": [ + { + "line": 3, "column": 1, "kind": "IntLiteral", - "value": 123 + "elems": [] }, - "right": { + { "line": 4, "column": 2, - "kind": "BinOp", - "op": "*", - "left": { - "line": 3, - "column": 1, - "kind": "IntLiteral", - "value": 42 - }, - "right": { - "line": 4, - "column": 2, - "kind": "Ident", - "name": "abc" - } + "kind": "Ident", + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/left-associativity/ast.json b/test/grammar1/left-associativity/ast.json index d55187c..2eed6bb 100644 --- a/test/grammar1/left-associativity/ast.json +++ b/test/grammar1/left-associativity/ast.json @@ -1,42 +1,46 @@ { "line": 1, - "column": 18, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 18, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 1, - "column": 17, + "column": 15, "kind": "BinOp", - "op": "-", - "left": { + "elems": [ + { "line": 1, - "column": 13, + "column": 11, "kind": "BinOp", - "op": "-", - "left": { + "elems": [ + { "line": 1, "column": 8, "kind": "IntLiteral", - "value": 10 + "elems": [] }, - "right": { + { "line": 1, "column": 13, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, - "right": { + { "line": 1, "column": 17, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/multiple-decls/ast.json b/test/grammar1/multiple-decls/ast.json index 6eaa176..d8a16d0 100644 --- a/test/grammar1/multiple-decls/ast.json +++ b/test/grammar1/multiple-decls/ast.json @@ -1,81 +1,106 @@ { - "line": 4, - "column": 17, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 10, + "column": 1, "kind": "Declare", "mut": "var", - "name": "a", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, { "line": 2, - "column": 10, + "column": 1, "kind": "Declare", "mut": "var", - "name": "b", - "init": { + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, "column": 9, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, { "line": 3, - "column": 10, + "column": 1, "kind": "Declare", "mut": "var", - "name": "c", - "init": { + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 3, "column": 9, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, { "line": 4, - "column": 17, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 4, - "column": 16, + "column": 14, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 4, - "column": 12, + "column": 10, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 4, "column": 8, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { + { "line": 4, "column": 12, "kind": "Ident", - "name": "b" + "elems": [] } + ] }, - "right": { + { "line": 4, "column": 16, "kind": "Ident", - "name": "c" + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/nested-parentheses/ast.json b/test/grammar1/nested-parentheses/ast.json index 8b304ea..7658b2d 100644 --- a/test/grammar1/nested-parentheses/ast.json +++ b/test/grammar1/nested-parentheses/ast.json @@ -1,18 +1,20 @@ { "line": 1, - "column": 18, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 18, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 1, "column": 12, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] } ] } diff --git a/test/grammar1/operator-precedence-2/ast.json b/test/grammar1/operator-precedence-2/ast.json index 5678204..40d5406 100644 --- a/test/grammar1/operator-precedence-2/ast.json +++ b/test/grammar1/operator-precedence-2/ast.json @@ -1,91 +1,105 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 30, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { "line": 1, - "column": 29, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 23, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 1, - "column": 21, + "column": 19, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 1, - "column": 17, + "column": 15, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, - "column": 13, + "column": 11, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "right": { + { "line": 1, "column": 13, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "right": { + { "line": 1, "column": 17, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, - "right": { + { "line": 1, "column": 21, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, - "right": { + { "line": 1, - "column": 29, + "column": 27, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, "column": 25, "kind": "IntLiteral", - "value": 5 + "elems": [] }, - "right": { + { "line": 1, "column": 29, "kind": "IntLiteral", - "value": 6 + "elems": [] } + ] } + ] } + ] }, { "line": 2, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar1/operator-precedence/ast.json b/test/grammar1/operator-precedence/ast.json index 3e2c930..8de366a 100644 --- a/test/grammar1/operator-precedence/ast.json +++ b/test/grammar1/operator-precedence/ast.json @@ -1,55 +1,66 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 18, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { "line": 1, - "column": 17, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 2 + "elems": [] }, - "right": { + { "line": 1, - "column": 17, + "column": 15, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, "column": 13, "kind": "IntLiteral", - "value": 3 + "elems": [] }, - "right": { + { "line": 1, "column": 17, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] } + ] } + ] }, { "line": 2, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar1/parentheses-and-unary-minus/ast.json b/test/grammar1/parentheses-and-unary-minus/ast.json index c6eaa17..c66a07c 100644 --- a/test/grammar1/parentheses-and-unary-minus/ast.json +++ b/test/grammar1/parentheses-and-unary-minus/ast.json @@ -1,97 +1,112 @@ { - "line": 2, - "column": 15, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 39, + "column": 1, "kind": "Declare", "mut": "var", - "name": "result", - "init": { + "elems": [ + { "line": 1, - "column": 38, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 36, "kind": "BinOp", - "op": "/", - "left": { + "elems": [ + { "line": 1, - "column": 34, + "column": 26, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, - "column": 24, + "column": 16, "kind": "BinOp", - "op": "*", - "left": { + "elems": [ + { "line": 1, "column": 14, "kind": "IntLiteral", - "value": 2 + "elems": [] }, - "right": { + { "line": 1, - "column": 23, + "column": 21, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 1, "column": 19, "kind": "IntLiteral", - "value": 2 + "elems": [] }, - "right": { + { "line": 1, "column": 23, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] } + ] }, - "right": { + { "line": 1, - "column": 33, + "column": 31, "kind": "BinOp", - "op": "-", - "left": { + "elems": [ + { "line": 1, "column": 29, "kind": "IntLiteral", - "value": 3 + "elems": [] }, - "right": { + { "line": 1, "column": 33, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] } + ] }, - "right": { + { "line": 1, "column": 38, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] } + ] }, { "line": 2, - "column": 15, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, - "column": 9, + "column": 8, "kind": "Unary", - "op": "-", - "operand": { + "elems": [ + { "line": 2, "column": 9, "kind": "Ident", - "name": "result" + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/return-without-expr/ast.json b/test/grammar1/return-without-expr/ast.json index b959d4e..c96ad64 100644 --- a/test/grammar1/return-without-expr/ast.json +++ b/test/grammar1/return-without-expr/ast.json @@ -1,18 +1,20 @@ { "line": 1, - "column": 7, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 7, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 1, - "column": 7, + "column": 8, "kind": "Error", - "message": "unexpected token 'SEMI'" + "elems": [] } + ] } ] } diff --git a/test/grammar1/unclosed-paren/ast.json b/test/grammar1/unclosed-paren/ast.json index e7ae233..63c008c 100644 --- a/test/grammar1/unclosed-paren/ast.json +++ b/test/grammar1/unclosed-paren/ast.json @@ -1,30 +1,33 @@ { "line": 1, - "column": 15, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 15, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 1, - "column": 14, + "column": 12, "kind": "BinOp", - "op": "+", - "left": { + "elems": [ + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 42 + "elems": [] }, - "right": { + { "line": 1, "column": 14, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] } + ] } ] } diff --git a/test/grammar1/undeclared-assignment/ast.json b/test/grammar1/undeclared-assignment/ast.json index 6a9bdb6..17bb1f4 100644 --- a/test/grammar1/undeclared-assignment/ast.json +++ b/test/grammar1/undeclared-assignment/ast.json @@ -1,35 +1,39 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 7, + "column": 1, "kind": "Assign", - "target": { + "elems": [ + { "line": 1, "column": 1, "kind": "Ident", - "name": "x" + "elems": [] }, - "value": { + { "line": 1, "column": 5, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, { "line": 2, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar1/val-assignment/ast.json b/test/grammar1/val-assignment/ast.json index 9a63f3e..920a44f 100644 --- a/test/grammar1/val-assignment/ast.json +++ b/test/grammar1/val-assignment/ast.json @@ -1,48 +1,59 @@ { - "line": 3, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 11, + "column": 1, "kind": "Declare", "mut": "val", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, { "line": 2, - "column": 7, + "column": 1, "kind": "Assign", - "target": { + "elems": [ + { "line": 2, "column": 1, "kind": "Ident", - "name": "x" + "elems": [] }, - "value": { + { "line": 2, "column": 5, "kind": "IntLiteral", - "value": 20 + "elems": [] } + ] }, { "line": 3, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar1/var-no-init/ast.json b/test/grammar1/var-no-init/ast.json index c7452b4..ac2d5d5 100644 --- a/test/grammar1/var-no-init/ast.json +++ b/test/grammar1/var-no-init/ast.json @@ -1,20 +1,27 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, - "column": 1, + "column": 8, "kind": "Error", - "message": "unexpected token 'RETURN'" + "elems": [] } + ] } ] } diff --git a/test/grammar1/var-redefinition/ast.json b/test/grammar1/var-redefinition/ast.json index 094847a..ae19a42 100644 --- a/test/grammar1/var-redefinition/ast.json +++ b/test/grammar1/var-redefinition/ast.json @@ -1,44 +1,60 @@ { - "line": 3, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 11, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, { "line": 2, - "column": 11, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, "column": 9, "kind": "IntLiteral", - "value": 37 + "elems": [] } + ] }, { "line": 3, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar1/var-val-redefinition/ast.json b/test/grammar1/var-val-redefinition/ast.json index 9fdd3ce..036dde8 100644 --- a/test/grammar1/var-val-redefinition/ast.json +++ b/test/grammar1/var-val-redefinition/ast.json @@ -1,44 +1,60 @@ { - "line": 3, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 11, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 1, "column": 9, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, { "line": 2, - "column": 11, + "column": 1, "kind": "Declare", "mut": "val", - "name": "x", - "init": { + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { "line": 2, "column": 9, "kind": "IntLiteral", - "value": 37 + "elems": [] } + ] }, { "line": 3, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 3, "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } ] } diff --git a/test/grammar2/boolean-logic/ast.json b/test/grammar2/boolean-logic/ast.json index e378d45..c0bcf4d 100644 --- a/test/grammar2/boolean-logic/ast.json +++ b/test/grammar2/boolean-logic/ast.json @@ -1,75 +1,100 @@ -{ - "line": 3, - "column": 21, - "kind": "Program", - "body": [ { "line": 1, - "column": 13, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "a", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] }, -{ - "line": 2, - "column": 14, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "b", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "BoolLiteral", - "value": false + "elems": [] } + ] }, -{ - "line": 3, - "column": 21, + { + "line": 3, + "column": 1, "kind": "Declare", "mut": "var", - "name": "c", - "init": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 16, "kind": "BinOp", - "op": "||", - "left": { - "line": 3, - "column": 14, + "elems": [ + { + "line": 3, + "column": 11, "kind": "BinOp", - "op": "&&", - "left": { - "line": 3, - "column": 9, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 3, - "column": 14, + { + "line": 3, + "column": 14, "kind": "Ident", - "name": "b" + "elems": [] } + ] }, - "right": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 19, "kind": "Unary", - "op": "!", - "operand": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 20, "kind": "Ident", - "name": "a" + "elems": [] } + ] } + ] } + ] } -]} + ] +} diff --git a/test/grammar2/break-outside-loop-codegen/ast.json b/test/grammar2/break-outside-loop-codegen/ast.json index 3a750bb..eeb9d9f 100644 --- a/test/grammar2/break-outside-loop-codegen/ast.json +++ b/test/grammar2/break-outside-loop-codegen/ast.json @@ -1,23 +1,26 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 6, - "kind": "Break" + "column": 1, + "kind": "Break", + "elems": [] }, { "line": 2, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 8, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } ] } diff --git a/test/grammar2/comparisons/ast.json b/test/grammar2/comparisons/ast.json index 6bcf74f..4eba5c2 100644 --- a/test/grammar2/comparisons/ast.json +++ b/test/grammar2/comparisons/ast.json @@ -1,156 +1,205 @@ -{ - "line": 6, - "column": 20, - "kind": "Program", - "body": [ { "line": 1, - "column": 17, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp", - "init": { - "line": 1, - "column": 16, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 13, "kind": "BinOp", - "op": "==", - "left": { - "line": 1, - "column": 11, + "elems": [ + { + "line": 1, + "column": 11, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "right": { - "line": 1, - "column": 16, + { + "line": 1, + "column": 16, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] }, -{ - "line": 2, - "column": 18, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp2", - "init": { - "line": 2, - "column": 17, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 14, "kind": "BinOp", - "op": "!=", - "left": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 3 + "elems": [] }, - "right": { - "line": 2, - "column": 17, + { + "line": 2, + "column": 17, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] } + ] }, -{ - "line": 3, - "column": 17, + { + "line": 3, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp3", - "init": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 14, "kind": "BinOp", - "op": "<", - "left": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 5 + "elems": [] }, - "right": { - "line": 3, - "column": 16, + { + "line": 3, + "column": 16, "kind": "IntLiteral", - "value": 6 + "elems": [] } + ] } + ] }, -{ - "line": 4, - "column": 17, + { + "line": 4, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp4", - "init": { - "line": 4, - "column": 16, + "elems": [ + { + "line": 4, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 14, "kind": "BinOp", - "op": ">", - "left": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 7 + "elems": [] }, - "right": { - "line": 4, - "column": 16, + { + "line": 4, + "column": 16, "kind": "IntLiteral", - "value": 8 + "elems": [] } + ] } + ] }, -{ - "line": 5, - "column": 19, + { + "line": 5, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp5", - "init": { - "line": 5, - "column": 17, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 14, "kind": "BinOp", - "op": "<=", - "left": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 9 + "elems": [] }, - "right": { - "line": 5, - "column": 17, + { + "line": 5, + "column": 17, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] } + ] }, -{ - "line": 6, - "column": 20, + { + "line": 6, + "column": 1, "kind": "Declare", "mut": "var", - "name": "cmp6", - "init": { - "line": 6, - "column": 18, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 15, "kind": "BinOp", - "op": ">=", - "left": { - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 12, "kind": "IntLiteral", - "value": 11 + "elems": [] }, - "right": { - "line": 6, - "column": 18, + { + "line": 6, + "column": 18, "kind": "IntLiteral", - "value": 12 + "elems": [] } + ] } + ] } -]} + ] +} diff --git a/test/grammar2/continue-outside-loop-codegen/ast.json b/test/grammar2/continue-outside-loop-codegen/ast.json index afea3d1..95c1fb6 100644 --- a/test/grammar2/continue-outside-loop-codegen/ast.json +++ b/test/grammar2/continue-outside-loop-codegen/ast.json @@ -1,23 +1,26 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ + "elems": [ { "line": 1, - "column": 9, - "kind": "Continue" + "column": 1, + "kind": "Continue", + "elems": [] }, { "line": 2, - "column": 9, + "column": 1, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 8, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } ] } diff --git a/test/grammar2/dangling-else/ast.json b/test/grammar2/dangling-else/ast.json index c1672ac..f39d34a 100644 --- a/test/grammar2/dangling-else/ast.json +++ b/test/grammar2/dangling-else/ast.json @@ -1,61 +1,72 @@ { - "line": 6, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -{ - "line": 5, - "column": 13, + "elems": [ + { + "line": 1, + "column": 1, "kind": "If", - "cond": { - "line": 1, - "column": 5, + "elems": [ + { + "line": 1, + "column": 5, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "then": { - "line": 5, - "column": 13, + { + "line": 2, + "column": 3, "kind": "If", - "cond": { - "line": 2, - "column": 7, + "elems": [ + { + "line": 2, + "column": 7, "kind": "IntLiteral", - "value": 0 + "elems": [] }, - "then": { - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Return", - "value": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "else": { - "line": 5, - "column": 13, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } + ] }, -{ - "line": 6, - "column": 9, + { + "line": 6, + "column": 1, "kind": "Return", - "value": { - "line": 6, - "column": 8, + "elems": [ + { + "line": 6, + "column": 8, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } -]} + ] +} diff --git a/test/grammar2/empty-block/ast.json b/test/grammar2/empty-block/ast.json index 7cfb6f8..83251a8 100644 --- a/test/grammar2/empty-block/ast.json +++ b/test/grammar2/empty-block/ast.json @@ -1,36 +1,47 @@ -{ - "line": 2, - "column": 12, - "kind": "Program", - "body": [ { "line": 1, - "column": 10, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 2, - "column": 12, + { + "line": 2, + "column": 1, "kind": "While", - "cond": { - "line": 2, - "column": 8, + "elems": [ + { + "line": 2, + "column": 8, "kind": "Ident", - "name": "x" + "elems": [] }, - "body": { - "line": 2, - "column": 12, + { + "line": 2, + "column": 11, "kind": "Block", - "body": [ - ]} + "elems": [ + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/if-else/ast.json b/test/grammar2/if-else/ast.json index 276cae5..79ddfee 100644 --- a/test/grammar2/if-else/ast.json +++ b/test/grammar2/if-else/ast.json @@ -1,101 +1,125 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 3, + "column": 1, "kind": "If", - "cond": { - "line": 3, - "column": 10, + "elems": [ + { + "line": 3, + "column": 7, "kind": "BinOp", - "op": "==", - "left": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 3, - "column": 10, + { + "line": 3, + "column": 10, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "then": { - "line": 5, - "column": 1, + { + "line": 3, + "column": 13, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 10, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Assign", - "target": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "y" + "elems": [] }, - "value": { - "line": 4, - "column": 9, + { + "line": 4, + "column": 9, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } - ]}, - "else": { - "line": 7, - "column": 1, + ] + }, + { + "line": 5, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Assign", - "target": { - "line": 6, - "column": 5, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Ident", - "name": "y" + "elems": [] }, - "value": { - "line": 6, - "column": 9, + { + "line": 6, + "column": 9, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/if-without-else/ast.json b/test/grammar2/if-without-else/ast.json index b2180b2..edcd0cc 100644 --- a/test/grammar2/if-without-else/ast.json +++ b/test/grammar2/if-without-else/ast.json @@ -1,34 +1,40 @@ { - "line": 3, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "If", - "cond": { - "line": 1, - "column": 5, + "elems": [ + { + "line": 1, + "column": 5, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "then": { - "line": 3, - "column": 1, + { + "line": 1, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/if-without-parens/ast.json b/test/grammar2/if-without-parens/ast.json index 4b4f460..09a3dc8 100644 --- a/test/grammar2/if-without-parens/ast.json +++ b/test/grammar2/if-without-parens/ast.json @@ -1,36 +1,40 @@ { - "line": 3, + "line": 1, "column": 1, "kind": "Program", - "body": [ + "elems": [ { - "line": 3, + "line": 1, "column": 1, "kind": "If", - "cond": { + "elems": [ + { "line": 1, - "column": 4, + "column": 9, "kind": "Error", - "message": "missing condition" + "elems": [] }, - "then": { - "line": 3, - "column": 1, + { + "line": 1, + "column": 9, "kind": "Block", - "body": [ + "elems": [ { "line": 2, - "column": 14, + "column": 5, "kind": "Return", - "value": { + "elems": [ + { "line": 2, "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } ] } + ] } ] } diff --git a/test/grammar2/nested-if-else-chain/ast.json b/test/grammar2/nested-if-else-chain/ast.json index f68f66f..372e36a 100644 --- a/test/grammar2/nested-if-else-chain/ast.json +++ b/test/grammar2/nested-if-else-chain/ast.json @@ -1,79 +1,93 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "If", - "cond": { - "line": 1, - "column": 5, + "elems": [ + { + "line": 1, + "column": 5, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "then": { - "line": 3, - "column": 1, + { + "line": 1, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 11, + "elems": [ + { + "line": 2, + "column": 3, "kind": "Return", - "value": { - "line": 2, - "column": 10, + "elems": [ + { + "line": 2, + "column": 10, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 7, - "column": 1, + ] + }, + { + "line": 3, + "column": 8, "kind": "If", - "cond": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] }, - "then": { - "line": 5, - "column": 1, + { + "line": 3, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 11, + "elems": [ + { + "line": 4, + "column": 3, "kind": "Return", - "value": { - "line": 4, - "column": 10, + "elems": [ + { + "line": 4, + "column": 10, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } - ]}, - "else": { - "line": 7, - "column": 1, + ] + }, + { + "line": 5, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 11, + "elems": [ + { + "line": 6, + "column": 3, "kind": "Return", - "value": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 10, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] } - ]} + ] + } + ] } + ] } -]} + ] +} diff --git a/test/grammar2/nested-if-else/ast.json b/test/grammar2/nested-if-else/ast.json index d255c8d..2a0f183 100644 --- a/test/grammar2/nested-if-else/ast.json +++ b/test/grammar2/nested-if-else/ast.json @@ -1,142 +1,178 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 3, - "column": 10, + { + "line": 3, + "column": 1, "kind": "Declare", "mut": "var", - "name": "z", - "init": { - "line": 3, - "column": 9, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 12, - "column": 1, + { + "line": 4, + "column": 1, "kind": "If", - "cond": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "then": { - "line": 10, - "column": 1, + { + "line": 4, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 9, - "column": 5, + "elems": [ + { + "line": 5, + "column": 5, "kind": "If", - "cond": { - "line": 5, - "column": 9, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Ident", - "name": "y" + "elems": [] }, - "then": { - "line": 7, - "column": 5, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 14, + "elems": [ + { + "line": 6, + "column": 9, "kind": "Assign", - "target": { - "line": 6, - "column": 9, + "elems": [ + { + "line": 6, + "column": 9, "kind": "Ident", - "name": "z" + "elems": [] }, - "value": { - "line": 6, - "column": 13, + { + "line": 6, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 9, - "column": 5, + ] + }, + { + "line": 7, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 8, - "column": 14, + "elems": [ + { + "line": 8, + "column": 9, "kind": "Assign", - "target": { - "line": 8, - "column": 9, + "elems": [ + { + "line": 8, + "column": 9, "kind": "Ident", - "name": "z" + "elems": [] }, - "value": { - "line": 8, - "column": 13, + { + "line": 8, + "column": 13, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } - ]} + ] + } + ] } - ]}, - "else": { - "line": 12, - "column": 1, + ] + }, + { + "line": 10, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 11, - "column": 10, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Assign", - "target": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "z" + "elems": [] }, - "value": { - "line": 11, - "column": 9, + { + "line": 11, + "column": 9, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/nested-while/ast.json b/test/grammar2/nested-while/ast.json index 0042f7f..82ac33d 100644 --- a/test/grammar2/nested-while/ast.json +++ b/test/grammar2/nested-while/ast.json @@ -1,148 +1,177 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "i", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "j", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 3, + "column": 1, "kind": "While", - "cond": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 10, "kind": "BinOp", - "op": "<", - "left": { - "line": 3, - "column": 8, + "elems": [ + { + "line": 3, + "column": 8, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 3, - "column": 12, + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, - "body": { - "line": 8, - "column": 1, + { + "line": 3, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "While", - "cond": { - "line": 4, - "column": 16, + "elems": [ + { + "line": 4, + "column": 14, "kind": "BinOp", - "op": "<", - "left": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "Ident", - "name": "j" + "elems": [] }, - "right": { - "line": 4, - "column": 16, + { + "line": 4, + "column": 16, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, - "body": { - "line": 6, - "column": 5, + { + "line": 4, + "column": 20, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 18, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Assign", - "target": { - "line": 5, - "column": 9, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Ident", - "name": "j" + "elems": [] }, - "value": { - "line": 5, - "column": 17, + { + "line": 5, + "column": 15, "kind": "BinOp", - "op": "+", - "left": { - "line": 5, - "column": 13, + "elems": [ + { + "line": 5, + "column": 13, "kind": "Ident", - "name": "j" + "elems": [] }, - "right": { - "line": 5, - "column": 17, + { + "line": 5, + "column": 17, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 14, + { + "line": 7, + "column": 5, "kind": "Assign", - "target": { - "line": 7, - "column": 5, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Ident", - "name": "i" + "elems": [] }, - "value": { - "line": 7, - "column": 13, + { + "line": 7, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { - "line": 7, - "column": 9, + "elems": [ + { + "line": 7, + "column": 9, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 7, - "column": 13, + { + "line": 7, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/not-with-literal/ast.json b/test/grammar2/not-with-literal/ast.json index db01795..8e45c8f 100644 --- a/test/grammar2/not-with-literal/ast.json +++ b/test/grammar2/not-with-literal/ast.json @@ -1,25 +1,34 @@ { "line": 1, - "column": 14, + "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 14, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "Unary", - "op": "!", - "operand": { - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 10, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] } + ] } -]} + ] +} diff --git a/test/grammar2/short-circuit-and/ast.json b/test/grammar2/short-circuit-and/ast.json index 877ecdd..7c05b27 100644 --- a/test/grammar2/short-circuit-and/ast.json +++ b/test/grammar2/short-circuit-and/ast.json @@ -1,113 +1,139 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 3, + "column": 1, "kind": "If", - "cond": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 12, "kind": "BinOp", - "op": "&&", - "left": { - "line": 3, - "column": 10, + "elems": [ + { + "line": 3, + "column": 7, "kind": "BinOp", - "op": "!=", - "left": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 3, - "column": 10, + { + "line": 3, + "column": 10, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 17, "kind": "BinOp", - "op": "!=", - "left": { - "line": 3, - "column": 15, + "elems": [ + { + "line": 3, + "column": 15, "kind": "Ident", - "name": "y" + "elems": [] }, - "right": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 20, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } + ] }, - "then": { - "line": 5, - "column": 1, + { + "line": 3, + "column": 23, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 11, + "elems": [ + { + "line": 4, + "column": 3, "kind": "Return", - "value": { - "line": 4, - "column": 10, + "elems": [ + { + "line": 4, + "column": 10, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 7, - "column": 1, + ] + }, + { + "line": 5, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 11, + "elems": [ + { + "line": 6, + "column": 3, "kind": "Return", - "value": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 10, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/short-circuit-or/ast.json b/test/grammar2/short-circuit-or/ast.json index c3778e0..7c05b27 100644 --- a/test/grammar2/short-circuit-or/ast.json +++ b/test/grammar2/short-circuit-or/ast.json @@ -1,113 +1,139 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "y", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 3, + "column": 1, "kind": "If", - "cond": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 12, "kind": "BinOp", - "op": "||", - "left": { - "line": 3, - "column": 10, + "elems": [ + { + "line": 3, + "column": 7, "kind": "BinOp", - "op": "!=", - "left": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 3, - "column": 10, + { + "line": 3, + "column": 10, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 17, "kind": "BinOp", - "op": "!=", - "left": { - "line": 3, - "column": 15, + "elems": [ + { + "line": 3, + "column": 15, "kind": "Ident", - "name": "y" + "elems": [] }, - "right": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 20, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } + ] }, - "then": { - "line": 5, - "column": 1, + { + "line": 3, + "column": 23, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 11, + "elems": [ + { + "line": 4, + "column": 3, "kind": "Return", - "value": { - "line": 4, - "column": 10, + "elems": [ + { + "line": 4, + "column": 10, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 7, - "column": 1, + ] + }, + { + "line": 5, + "column": 8, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 11, + "elems": [ + { + "line": 6, + "column": 3, "kind": "Return", - "value": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 10, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/while-break/ast.json b/test/grammar2/while-break/ast.json index 675fe4e..1c444fe 100644 --- a/test/grammar2/while-break/ast.json +++ b/test/grammar2/while-break/ast.json @@ -1,111 +1,131 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "i", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 2, + "column": 1, "kind": "While", - "cond": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 10, "kind": "BinOp", - "op": "<", - "left": { - "line": 2, - "column": 8, + "elems": [ + { + "line": 2, + "column": 8, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 2, - "column": 12, + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, - "body": { - "line": 7, - "column": 1, + { + "line": 2, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "If", - "cond": { - "line": 3, - "column": 14, + "elems": [ + { + "line": 3, + "column": 11, "kind": "BinOp", - "op": "==", - "left": { - "line": 3, - "column": 9, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 3, - "column": 14, + { + "line": 3, + "column": 14, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, - "then": { - "line": 5, - "column": 5, + { + "line": 3, + "column": 17, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 14, - "kind": "Break" + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Break", + "elems": [] } - ]} + ] + } + ] }, -{ - "line": 6, - "column": 14, + { + "line": 6, + "column": 5, "kind": "Assign", - "target": { - "line": 6, - "column": 5, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Ident", - "name": "i" + "elems": [] }, - "value": { - "line": 6, - "column": 13, + { + "line": 6, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { - "line": 6, - "column": 9, + "elems": [ + { + "line": 6, + "column": 9, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 6, - "column": 13, + { + "line": 6, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/while-continue/ast.json b/test/grammar2/while-continue/ast.json index b34382e..e24ab5a 100644 --- a/test/grammar2/while-continue/ast.json +++ b/test/grammar2/while-continue/ast.json @@ -1,153 +1,183 @@ { - "line": 9, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 10, + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "i", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 2, - "column": 10, + { + "line": 2, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 9, - "column": 1, + { + "line": 3, + "column": 1, "kind": "While", - "cond": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 10, "kind": "BinOp", - "op": "<", - "left": { - "line": 3, - "column": 8, + "elems": [ + { + "line": 3, + "column": 8, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 3, - "column": 12, + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, - "body": { - "line": 9, - "column": 1, + { + "line": 3, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 14, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Assign", - "target": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "i" + "elems": [] }, - "value": { - "line": 4, - "column": 13, + { + "line": 4, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { - "line": 4, - "column": 9, + "elems": [ + { + "line": 4, + "column": 9, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 4, - "column": 13, + { + "line": 4, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] }, -{ - "line": 7, - "column": 5, + { + "line": 5, + "column": 5, "kind": "If", - "cond": { - "line": 5, - "column": 14, + "elems": [ + { + "line": 5, + "column": 11, "kind": "BinOp", - "op": "==", - "left": { - "line": 5, - "column": 9, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Ident", - "name": "i" + "elems": [] }, - "right": { - "line": 5, - "column": 14, + { + "line": 5, + "column": 14, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, - "then": { - "line": 7, - "column": 5, + { + "line": 5, + "column": 17, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 17, - "kind": "Continue" + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Continue", + "elems": [] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 14, + { + "line": 8, + "column": 5, "kind": "Assign", - "target": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "value": { - "line": 8, - "column": 13, + { + "line": 8, + "column": 11, "kind": "BinOp", - "op": "+", - "left": { - "line": 8, - "column": 9, + "elems": [ + { + "line": 8, + "column": 9, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 8, - "column": 13, + { + "line": 8, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar2/while-if-else-break/ast.json b/test/grammar2/while-if-else-break/ast.json index bef8827..d3a3108 100644 --- a/test/grammar2/while-if-else-break/ast.json +++ b/test/grammar2/while-if-else-break/ast.json @@ -1,128 +1,151 @@ -{ - "line": 9, - "column": 9, - "kind": "Program", - "body": [ { "line": 1, - "column": 10, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 2, + "column": 1, "kind": "While", - "cond": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 10, "kind": "BinOp", - "op": "<", - "left": { - "line": 2, - "column": 8, + "elems": [ + { + "line": 2, + "column": 8, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 2, - "column": 12, + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, - "body": { - "line": 8, - "column": 1, + { + "line": 2, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "If", - "cond": { - "line": 3, - "column": 13, + "elems": [ + { + "line": 3, + "column": 11, "kind": "BinOp", - "op": "<", - "left": { - "line": 3, - "column": 9, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 3, - "column": 13, + { + "line": 3, + "column": 13, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, - "then": { - "line": 5, - "column": 5, + { + "line": 3, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 18, + "elems": [ + { + "line": 4, + "column": 9, "kind": "Assign", - "target": { - "line": 4, - "column": 9, + "elems": [ + { + "line": 4, + "column": 9, "kind": "Ident", - "name": "x" + "elems": [] }, - "value": { - "line": 4, - "column": 17, + { + "line": 4, + "column": 15, "kind": "BinOp", - "op": "+", - "left": { - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 13, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 4, - "column": 17, + { + "line": 4, + "column": 17, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } - ]}, - "else": { - "line": 7, - "column": 5, + ] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 14, - "kind": "Break" + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Break", + "elems": [] } - ]} + ] + } + ] } - ]} + ] + } + ] }, -{ - "line": 9, - "column": 9, + { + "line": 9, + "column": 1, "kind": "Return", - "value": { - "line": 9, - "column": 8, + "elems": [ + { + "line": 9, + "column": 8, "kind": "Ident", - "name": "x" + "elems": [] } + ] } -]} + ] +} diff --git a/test/grammar2/while-single-statement/ast.json b/test/grammar2/while-single-statement/ast.json index dc51c55..640feb3 100644 --- a/test/grammar2/while-single-statement/ast.json +++ b/test/grammar2/while-single-statement/ast.json @@ -1,59 +1,72 @@ -{ - "line": 3, - "column": 14, - "kind": "Program", - "body": [ { "line": 1, - "column": 10, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 1, - "column": 9, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 3, - "column": 14, + { + "line": 2, + "column": 1, "kind": "While", - "cond": { - "line": 2, - "column": 8, + "elems": [ + { + "line": 2, + "column": 8, "kind": "Ident", - "name": "x" + "elems": [] }, - "body": { - "line": 3, - "column": 14, + { + "line": 3, + "column": 5, "kind": "Assign", - "target": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "x" + "elems": [] }, - "value": { - "line": 3, - "column": 13, + { + "line": 3, + "column": 11, "kind": "BinOp", - "op": "-", - "left": { - "line": 3, - "column": 9, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 3, - "column": 13, + { + "line": 3, + "column": 13, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } + ] } -]} + ] +} diff --git a/test/grammar3/extern-calls/ast.json b/test/grammar3/extern-calls/ast.json index a204fbf..0a3de0e 100644 --- a/test/grammar3/extern-calls/ast.json +++ b/test/grammar3/extern-calls/ast.json @@ -1,79 +1,112 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 22, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "putchar", - "params": [{ - "line": 1, - "column": 20, - "kind": "Ident", - "name": "x" -}] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 20, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 6, - "column": 1, + { + "line": 3, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 24, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "var", - "name": "a", - "init": { - "line": 4, - "column": 23, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 20, "kind": "Call", - "callee": { - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 13, "kind": "Ident", - "name": "putchar" + "elems": [] }, - "args": [{ - "line": 4, - "column": 21, - "kind": "IntLiteral", - "value": 72 -}] + { + "line": 4, + "column": 21, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 5, - "column": 25, + { + "line": 5, + "column": 5, "kind": "Declare", "mut": "var", - "name": "b", - "init": { - "line": 5, - "column": 24, + "elems": [ + { + "line": 5, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 20, "kind": "Call", - "callee": { - "line": 5, - "column": 13, + "elems": [ + { + "line": 5, + "column": 13, "kind": "Ident", - "name": "putchar" + "elems": [] }, - "args": [{ - "line": 5, - "column": 21, - "kind": "IntLiteral", - "value": 105 -}] + { + "line": 5, + "column": 21, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/extern-decl/ast.json b/test/grammar3/extern-decl/ast.json index 7c855e3..f96e06c 100644 --- a/test/grammar3/extern-decl/ast.json +++ b/test/grammar3/extern-decl/ast.json @@ -1,42 +1,59 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 22, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "putchar", - "params": [{ - "line": 1, - "column": 20, - "kind": "Ident", - "name": "c" -}] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 20, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 5, - "column": 1, + { + "line": 3, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/extern-multi-params/ast.json b/test/grammar3/extern-multi-params/ast.json index 275190f..a3ef2cc 100644 --- a/test/grammar3/extern-multi-params/ast.json +++ b/test/grammar3/extern-multi-params/ast.json @@ -1,52 +1,71 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 24, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "foo", - "params": [{ - "line": 1, - "column": 16, - "kind": "Ident", - "name": "a" -}, { - "line": 1, - "column": 19, - "kind": "Ident", - "name": "b" -}, { - "line": 1, - "column": 22, - "kind": "Ident", - "name": "c" -}] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 16, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 22, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 5, - "column": 1, + { + "line": 3, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/extern-no-params/ast.json b/test/grammar3/extern-no-params/ast.json index be35bae..6ce9f8e 100644 --- a/test/grammar3/extern-no-params/ast.json +++ b/test/grammar3/extern-no-params/ast.json @@ -1,37 +1,53 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 17, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "foo", - "params": [] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 5, - "column": 1, + { + "line": 3, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/extern-with-func-ref/ast.json b/test/grammar3/extern-with-func-ref/ast.json index be44e64..6a91879 100644 --- a/test/grammar3/extern-with-func-ref/ast.json +++ b/test/grammar3/extern-with-func-ref/ast.json @@ -1,96 +1,132 @@ { - "line": 10, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "noop", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 5, - "column": 18, + { + "line": 5, + "column": 1, "kind": "ExternDecl", - "name": "foo", - "params": [{ - "line": 5, - "column": 16, - "kind": "Ident", - "name": "x" -}] + "elems": [ + { + "line": 5, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 10, - "column": 1, + { + "line": 7, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 10, - "column": 1, + "elems": [ + { + "line": 7, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 7, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 8, - "column": 24, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Declare", "mut": "var", - "name": "a", - "init": { - "line": 8, - "column": 23, + "elems": [ + { + "line": 8, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 8, + "column": 16, "kind": "Call", - "callee": { - "line": 8, - "column": 13, + "elems": [ + { + "line": 8, + "column": 13, "kind": "Ident", - "name": "foo" + "elems": [] }, - "args": [{ - "line": 8, - "column": 22, - "kind": "Call", - "callee": { - "line": 8, - "column": 17, - "kind": "Ident", - "name": "noop" - }, - "args": [] -}] + { + "line": 8, + "column": 21, + "kind": "Call", + "elems": [ + { + "line": 8, + "column": 17, + "kind": "Ident", + "elems": [] + } + ] + } + ] } + ] }, -{ - "line": 9, - "column": 13, + { + "line": 9, + "column": 5, "kind": "Return", - "value": { - "line": 9, - "column": 12, + "elems": [ + { + "line": 9, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/forward-reference/ast.json b/test/grammar3/forward-reference/ast.json index e9e6004..e411173 100644 --- a/test/grammar3/forward-reference/ast.json +++ b/test/grammar3/forward-reference/ast.json @@ -1,70 +1,92 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 19, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 18, + "elems": [ + { + "line": 2, + "column": 15, "kind": "Call", - "callee": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "Ident", - "name": "foo" + "elems": [] }, - "args": [{ - "line": 2, - "column": 16, - "kind": "IntLiteral", - "value": 42 -}] + { + "line": 2, + "column": 16, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "foo", - "params": [{ - "line": 5, - "column": 9, - "kind": "Ident", - "name": "x" -}], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Return", - "value": { - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 12, "kind": "Ident", - "name": "x" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-call-expression-stmt/ast.json b/test/grammar3/func-call-expression-stmt/ast.json index c48e7e9..a501f3a 100644 --- a/test/grammar3/func-call-expression-stmt/ast.json +++ b/test/grammar3/func-call-expression-stmt/ast.json @@ -1,60 +1,73 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 10, - "kind": "ExprStmt", - "value": { - "line": 2, - "column": 9, - "kind": "Call", - "callee": { - "line": 2, - "column": 5, - "kind": "Ident", - "name": "bar" - }, - "args": [] + "elems": [ + { + "line": 2, + "column": 8, + "kind": "Call", + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Return", - "value": { - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-call/ast.json b/test/grammar3/func-call/ast.json index 27e29f3..2f79b76 100644 --- a/test/grammar3/func-call/ast.json +++ b/test/grammar3/func-call/ast.json @@ -1,95 +1,125 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "double", - "params": [{ - "line": 1, - "column": 12, - "kind": "Ident", - "name": "x" -}], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 16, + "elems": [ + { + "line": 2, + "column": 14, "kind": "BinOp", - "op": "*", - "left": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 2, - "column": 16, + { + "line": 2, + "column": 16, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 23, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "var", - "name": "y", - "init": { - "line": 6, - "column": 22, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Call", - "callee": { - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 13, "kind": "Ident", - "name": "double" + "elems": [] }, - "args": [{ - "line": 6, - "column": 20, - "kind": "IntLiteral", - "value": 21 -}] + { + "line": 6, + "column": 20, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 7, - "column": 13, + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "y" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-def-return/ast.json b/test/grammar3/func-def-return/ast.json index 3d371c3..d61d45c 100644 --- a/test/grammar3/func-def-return/ast.json +++ b/test/grammar3/func-def-return/ast.json @@ -1,54 +1,73 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Return", - "value": { - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-empty-body/ast.json b/test/grammar3/func-empty-body/ast.json index 178a5e6..d69e673 100644 --- a/test/grammar3/func-empty-body/ast.json +++ b/test/grammar3/func-empty-body/ast.json @@ -1,43 +1,60 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 12, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", - "params": [], - "body": { - "line": 1, - "column": 12, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, "kind": "Block", - "body": [ - ]} + "elems": [ + ] + } + ] }, -{ - "line": 5, - "column": 1, + { + "line": 3, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-if-else-nested-call/ast.json b/test/grammar3/func-if-else-nested-call/ast.json index 1edbfcf..fc810fe 100644 --- a/test/grammar3/func-if-else-nested-call/ast.json +++ b/test/grammar3/func-if-else-nested-call/ast.json @@ -1,139 +1,177 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "max", - "params": [{ - "line": 1, - "column": 9, - "kind": "Ident", - "name": "a" -}, { - "line": 1, - "column": 12, - "kind": "Ident", - "name": "b" -}], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 5, + "elems": [ + { + "line": 2, + "column": 5, "kind": "If", - "cond": { - "line": 2, - "column": 13, + "elems": [ + { + "line": 2, + "column": 11, "kind": "BinOp", - "op": ">", - "left": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 9, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 2, - "column": 13, + { + "line": 2, + "column": 13, "kind": "Ident", - "name": "b" + "elems": [] } + ] }, - "then": { - "line": 4, - "column": 5, + { + "line": 2, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 3, - "column": 17, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Return", - "value": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 16, "kind": "Ident", - "name": "a" + "elems": [] } + ] } - ]}, - "else": { - "line": 6, - "column": 5, + ] + }, + { + "line": 4, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 17, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Return", - "value": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 16, "kind": "Ident", - "name": "b" + "elems": [] } + ] } - ]} + ] + } + ] } - ]} + ] + } + ] }, -{ - "line": 12, - "column": 1, + { + "line": 9, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 12, - "column": 1, + "elems": [ + { + "line": 9, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 9, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 10, - "column": 24, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "var", - "name": "m", - "init": { - "line": 10, - "column": 23, + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 16, "kind": "Call", - "callee": { - "line": 10, - "column": 13, + "elems": [ + { + "line": 10, + "column": 13, "kind": "Ident", - "name": "max" + "elems": [] + }, + { + "line": 10, + "column": 17, + "kind": "IntLiteral", + "elems": [] }, - "args": [{ - "line": 10, - "column": 17, - "kind": "IntLiteral", - "value": 10 -}, { - "line": 10, - "column": 21, - "kind": "IntLiteral", - "value": 20 -}] + { + "line": 10, + "column": 21, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 11, - "column": 13, + { + "line": 11, + "column": 5, "kind": "Return", - "value": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "m" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-params/ast.json b/test/grammar3/func-params/ast.json index bbeaa4a..edfb503 100644 --- a/test/grammar3/func-params/ast.json +++ b/test/grammar3/func-params/ast.json @@ -1,89 +1,118 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "add", - "params": [{ - "line": 1, - "column": 9, - "kind": "Ident", - "name": "a" -}, { - "line": 1, - "column": 12, - "kind": "Ident", - "name": "b" -}], - "body": { - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 23, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", - "name": "result", - "init": { - "line": 2, - "column": 22, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 20, "kind": "BinOp", - "op": "+", - "left": { - "line": 2, - "column": 18, + "elems": [ + { + "line": 2, + "column": 18, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 2, - "column": 22, + { + "line": 2, + "column": 22, "kind": "Ident", - "name": "b" + "elems": [] } + ] } + ] }, -{ - "line": 3, - "column": 18, + { + "line": 3, + "column": 5, "kind": "Return", - "value": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 13, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/func-return-expr/ast.json b/test/grammar3/func-return-expr/ast.json index 3b26b60..f43b2c0 100644 --- a/test/grammar3/func-return-expr/ast.json +++ b/test/grammar3/func-return-expr/ast.json @@ -1,82 +1,105 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "double", - "params": [{ - "line": 1, - "column": 12, - "kind": "Ident", - "name": "x" -}], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 15, + "elems": [ + { + "line": 2, + "column": 3, "kind": "Return", - "value": { - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 12, "kind": "BinOp", - "op": "*", - "left": { - "line": 2, - "column": 10, + "elems": [ + { + "line": 2, + "column": 10, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 2, - "column": 14, + { + "line": 2, + "column": 14, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 20, + "elems": [ + { + "line": 6, + "column": 3, "kind": "Return", - "value": { - "line": 6, - "column": 19, + "elems": [ + { + "line": 6, + "column": 16, "kind": "Call", - "callee": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 10, "kind": "Ident", - "name": "double" + "elems": [] }, - "args": [{ - "line": 6, - "column": 17, - "kind": "IntLiteral", - "value": 21 -}] + { + "line": 6, + "column": 17, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/interleaved-decls/ast.json b/test/grammar3/interleaved-decls/ast.json new file mode 100644 index 0000000..2b772c5 --- /dev/null +++ b/test/grammar3/interleaved-decls/ast.json @@ -0,0 +1,144 @@ +{ + "line": 1, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "FuncDecl", + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, + "kind": "Block", + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 2, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 5, + "column": 1, + "kind": "ExternDecl", + "elems": [ + { + "line": 5, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 7, + "column": 1, + "kind": "FuncDecl", + "elems": [ + { + "line": 7, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 7, + "column": 12, + "kind": "Block", + "elems": [ + { + "line": 8, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 8, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 11, + "column": 1, + "kind": "ExternDecl", + "elems": [ + { + "line": 11, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 13, + "column": 1, + "kind": "FuncDecl", + "elems": [ + { + "line": 13, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 13, + "column": 12, + "kind": "Block", + "elems": [ + { + "line": 14, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 14, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/grammar3/interleaved-decls/meta.json b/test/grammar3/interleaved-decls/meta.json new file mode 100644 index 0000000..ad6134a --- /dev/null +++ b/test/grammar3/interleaved-decls/meta.json @@ -0,0 +1,7 @@ +{ + "grammar": { + "lexer": ">=3", + "parser": ["3"] + }, + "stages": ["parser"] +} \ No newline at end of file diff --git a/test/grammar3/interleaved-decls/test.spl b/test/grammar3/interleaved-decls/test.spl new file mode 100644 index 0000000..9f3aa5a --- /dev/null +++ b/test/grammar3/interleaved-decls/test.spl @@ -0,0 +1,15 @@ +def bar() { + return 42; +} + +extern def foo(x); + +def baz(y) { + return y; +} + +extern def qux(); + +def main() { + return 0; +} \ No newline at end of file diff --git a/test/grammar3/multiple-externs/ast.json b/test/grammar3/multiple-externs/ast.json index d01df01..0b4cad6 100644 --- a/test/grammar3/multiple-externs/ast.json +++ b/test/grammar3/multiple-externs/ast.json @@ -1,59 +1,84 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 18, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "foo", - "params": [{ - "line": 1, - "column": 16, - "kind": "Ident", - "name": "x" -}] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 2, - "column": 21, + { + "line": 2, + "column": 1, "kind": "ExternDecl", - "name": "bar", - "params": [{ - "line": 2, - "column": 16, - "kind": "Ident", - "name": "y" -}, { - "line": 2, - "column": 19, - "kind": "Ident", - "name": "z" -}] + "elems": [ + { + "line": 2, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 16, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 19, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 6, - "column": 1, + { + "line": 4, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 4, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 13, + "elems": [ + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/mutual-recursion/ast.json b/test/grammar3/mutual-recursion/ast.json index fd7562f..ccdac2d 100644 --- a/test/grammar3/mutual-recursion/ast.json +++ b/test/grammar3/mutual-recursion/ast.json @@ -1,225 +1,275 @@ { - "line": 17, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "is_even", - "params": [{ - "line": 1, - "column": 13, - "kind": "Ident", - "name": "n" -}], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 13, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 3, + "elems": [ + { + "line": 2, + "column": 3, "kind": "If", - "cond": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 9, "kind": "BinOp", - "op": "==", - "left": { - "line": 2, - "column": 7, + "elems": [ + { + "line": 2, + "column": 7, "kind": "Ident", - "name": "n" + "elems": [] }, - "right": { - "line": 2, - "column": 12, + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "then": { - "line": 4, - "column": 3, + { + "line": 2, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 3, - "column": 13, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Return", - "value": { - "line": 3, - "column": 12, + "elems": [ + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 5, - "column": 23, + { + "line": 5, + "column": 3, "kind": "Return", - "value": { - "line": 5, - "column": 22, + "elems": [ + { + "line": 5, + "column": 16, "kind": "Call", - "callee": { - "line": 5, - "column": 10, + "elems": [ + { + "line": 5, + "column": 10, "kind": "Ident", - "name": "is_odd" + "elems": [] }, - "args": [{ - "line": 5, - "column": 21, - "kind": "BinOp", - "op": "-", - "left": { - "line": 5, - "column": 17, - "kind": "Ident", - "name": "n" - }, - "right": { - "line": 5, - "column": 21, - "kind": "IntLiteral", - "value": 1 - } -}] + { + "line": 5, + "column": 19, + "kind": "BinOp", + "elems": [ + { + "line": 5, + "column": 17, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 21, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 13, - "column": 1, + { + "line": 8, + "column": 1, "kind": "FuncDecl", - "name": "is_odd", - "params": [{ - "line": 8, - "column": 12, - "kind": "Ident", - "name": "n" -}], - "body": { - "line": 13, - "column": 1, + "elems": [ + { + "line": 8, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 8, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 8, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 11, - "column": 3, + "elems": [ + { + "line": 9, + "column": 3, "kind": "If", - "cond": { - "line": 9, - "column": 12, + "elems": [ + { + "line": 9, + "column": 9, "kind": "BinOp", - "op": "==", - "left": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 7, "kind": "Ident", - "name": "n" + "elems": [] }, - "right": { - "line": 9, - "column": 12, + { + "line": 9, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "then": { - "line": 11, - "column": 3, + { + "line": 9, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 10, - "column": 13, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Return", - "value": { - "line": 10, - "column": 12, + "elems": [ + { + "line": 10, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 12, - "column": 24, + { + "line": 12, + "column": 3, "kind": "Return", - "value": { - "line": 12, - "column": 23, + "elems": [ + { + "line": 12, + "column": 17, "kind": "Call", - "callee": { - "line": 12, - "column": 10, + "elems": [ + { + "line": 12, + "column": 10, "kind": "Ident", - "name": "is_even" + "elems": [] }, - "args": [{ - "line": 12, - "column": 22, - "kind": "BinOp", - "op": "-", - "left": { - "line": 12, - "column": 18, - "kind": "Ident", - "name": "n" - }, - "right": { - "line": 12, - "column": 22, - "kind": "IntLiteral", - "value": 1 - } -}] + { + "line": 12, + "column": 20, + "kind": "BinOp", + "elems": [ + { + "line": 12, + "column": 18, + "kind": "Ident", + "elems": [] + }, + { + "line": 12, + "column": 22, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 17, - "column": 1, + { + "line": 15, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 17, - "column": 1, + "elems": [ + { + "line": 15, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 15, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 16, - "column": 20, + "elems": [ + { + "line": 16, + "column": 3, "kind": "Return", - "value": { - "line": 16, - "column": 19, + "elems": [ + { + "line": 16, + "column": 17, "kind": "Call", - "callee": { - "line": 16, - "column": 10, + "elems": [ + { + "line": 16, + "column": 10, "kind": "Ident", - "name": "is_even" + "elems": [] }, - "args": [{ - "line": 16, - "column": 18, - "kind": "IntLiteral", - "value": 4 -}] + { + "line": 16, + "column": 18, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/nested-calls/ast.json b/test/grammar3/nested-calls/ast.json index 02650bb..fb6e642 100644 --- a/test/grammar3/nested-calls/ast.json +++ b/test/grammar3/nested-calls/ast.json @@ -1,137 +1,175 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "add", - "params": [{ - "line": 1, - "column": 9, - "kind": "Ident", - "name": "a" -}, { - "line": 1, - "column": 12, - "kind": "Ident", - "name": "b" -}], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 15, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 16, + "elems": [ + { + "line": 2, + "column": 14, "kind": "BinOp", - "op": "+", - "left": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 2, - "column": 16, + { + "line": 2, + "column": 16, "kind": "Ident", - "name": "b" + "elems": [] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 38, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 6, - "column": 37, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 16, "kind": "Call", - "callee": { - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 13, "kind": "Ident", - "name": "add" + "elems": [] }, - "args": [{ - "line": 6, - "column": 25, - "kind": "Call", - "callee": { - "line": 6, - "column": 17, - "kind": "Ident", - "name": "add" - }, - "args": [{ - "line": 6, - "column": 21, - "kind": "IntLiteral", - "value": 1 -}, { - "line": 6, - "column": 24, - "kind": "IntLiteral", - "value": 2 -}] -}, { - "line": 6, - "column": 36, - "kind": "Call", - "callee": { - "line": 6, - "column": 28, - "kind": "Ident", - "name": "add" - }, - "args": [{ - "line": 6, - "column": 32, - "kind": "IntLiteral", - "value": 3 -}, { - "line": 6, - "column": 35, - "kind": "IntLiteral", - "value": 4 -}] -}] + { + "line": 6, + "column": 20, + "kind": "Call", + "elems": [ + { + "line": 6, + "column": 17, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 21, + "kind": "IntLiteral", + "elems": [] + }, + { + "line": 6, + "column": 24, + "kind": "IntLiteral", + "elems": [] + } + ] + }, + { + "line": 6, + "column": 31, + "kind": "Call", + "elems": [ + { + "line": 6, + "column": 28, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 32, + "kind": "IntLiteral", + "elems": [] + }, + { + "line": 6, + "column": 35, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] }, -{ - "line": 7, - "column": 13, + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "x" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/no-main/ast.json b/test/grammar3/no-main/ast.json index 5666242..8edae35 100644 --- a/test/grammar3/no-main/ast.json +++ b/test/grammar3/no-main/ast.json @@ -1,30 +1,40 @@ { - "line": 3, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 11, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/pure-recursion/ast.json b/test/grammar3/pure-recursion/ast.json index bee784d..4c5b343 100644 --- a/test/grammar3/pure-recursion/ast.json +++ b/test/grammar3/pure-recursion/ast.json @@ -1,134 +1,164 @@ { - "line": 10, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "fact", - "params": [{ - "line": 1, - "column": 10, - "kind": "Ident", - "name": "n" -}], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 10, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 13, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 5, + "elems": [ + { + "line": 2, + "column": 5, "kind": "If", - "cond": { - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 11, "kind": "BinOp", - "op": "<=", - "left": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 9, "kind": "Ident", - "name": "n" + "elems": [] }, - "right": { - "line": 2, - "column": 14, + { + "line": 2, + "column": 14, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "then": { - "line": 4, - "column": 5, + { + "line": 2, + "column": 17, "kind": "Block", - "body": [ -{ - "line": 3, - "column": 17, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Return", - "value": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 16, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 5, - "column": 27, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 26, + "elems": [ + { + "line": 5, + "column": 14, "kind": "BinOp", - "op": "*", - "left": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "Ident", - "name": "n" + "elems": [] }, - "right": { - "line": 5, - "column": 26, + { + "line": 5, + "column": 20, "kind": "Call", - "callee": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 16, "kind": "Ident", - "name": "fact" + "elems": [] }, - "args": [{ - "line": 5, - "column": 25, - "kind": "BinOp", - "op": "-", - "left": { - "line": 5, - "column": 21, - "kind": "Ident", - "name": "n" - }, - "right": { - "line": 5, - "column": 25, - "kind": "IntLiteral", - "value": 1 - } -}] + { + "line": 5, + "column": 23, + "kind": "BinOp", + "elems": [ + { + "line": 5, + "column": 21, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 25, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 10, - "column": 1, + { + "line": 8, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 10, - "column": 1, + "elems": [ + { + "line": 8, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 8, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 9, - "column": 13, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Return", - "value": { - "line": 9, - "column": 12, + "elems": [ + { + "line": 9, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/recursion-extern/ast.json b/test/grammar3/recursion-extern/ast.json index 9e58e35..a07669d 100644 --- a/test/grammar3/recursion-extern/ast.json +++ b/test/grammar3/recursion-extern/ast.json @@ -1,207 +1,263 @@ { - "line": 14, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "fib", - "params": [{ - "line": 1, - "column": 9, - "kind": "Ident", - "name": "n" -}], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 4, - "column": 5, + "elems": [ + { + "line": 2, + "column": 5, "kind": "If", - "cond": { - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 11, "kind": "BinOp", - "op": "<=", - "left": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 9, "kind": "Ident", - "name": "n" + "elems": [] }, - "right": { - "line": 2, - "column": 14, + { + "line": 2, + "column": 14, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "then": { - "line": 4, - "column": 5, + { + "line": 2, + "column": 17, "kind": "Block", - "body": [ -{ - "line": 3, - "column": 17, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Return", - "value": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 16, "kind": "Ident", - "name": "n" + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 5, - "column": 35, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 34, + "elems": [ + { + "line": 5, + "column": 23, "kind": "BinOp", - "op": "+", - "left": { - "line": 5, - "column": 21, + "elems": [ + { + "line": 5, + "column": 15, "kind": "Call", - "callee": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "Ident", - "name": "fib" + "elems": [] }, - "args": [{ - "line": 5, - "column": 20, - "kind": "BinOp", - "op": "-", - "left": { - "line": 5, - "column": 16, - "kind": "Ident", - "name": "n" - }, - "right": { - "line": 5, - "column": 20, - "kind": "IntLiteral", - "value": 1 - } -}] + { + "line": 5, + "column": 18, + "kind": "BinOp", + "elems": [ + { + "line": 5, + "column": 16, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 20, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] }, - "right": { - "line": 5, - "column": 34, + { + "line": 5, + "column": 28, "kind": "Call", - "callee": { - "line": 5, - "column": 25, + "elems": [ + { + "line": 5, + "column": 25, "kind": "Ident", - "name": "fib" + "elems": [] }, - "args": [{ - "line": 5, - "column": 33, - "kind": "BinOp", - "op": "-", - "left": { - "line": 5, - "column": 29, - "kind": "Ident", - "name": "n" - }, - "right": { - "line": 5, - "column": 33, - "kind": "IntLiteral", - "value": 2 - } -}] + { + "line": 5, + "column": 31, + "kind": "BinOp", + "elems": [ + { + "line": 5, + "column": 29, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 33, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 21, + { + "line": 8, + "column": 1, "kind": "ExternDecl", - "name": "getchar", - "params": [] + "elems": [ + { + "line": 8, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 14, - "column": 1, + { + "line": 10, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 14, - "column": 1, + "elems": [ + { + "line": 10, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 11, - "column": 25, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Declare", "mut": "var", - "name": "result", - "init": { - "line": 11, - "column": 24, + "elems": [ + { + "line": 11, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 11, + "column": 21, "kind": "Call", - "callee": { - "line": 11, - "column": 18, + "elems": [ + { + "line": 11, + "column": 18, "kind": "Ident", - "name": "fib" + "elems": [] }, - "args": [{ - "line": 11, - "column": 22, - "kind": "IntLiteral", - "value": 10 -}] + { + "line": 11, + "column": 22, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 12, - "column": 22, + { + "line": 12, + "column": 5, "kind": "Declare", "mut": "var", - "name": "c", - "init": { - "line": 12, - "column": 21, + "elems": [ + { + "line": 12, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 12, + "column": 20, "kind": "Call", - "callee": { - "line": 12, - "column": 13, + "elems": [ + { + "line": 12, + "column": 13, "kind": "Ident", - "name": "getchar" - }, - "args": [] + "elems": [] + } + ] } + ] }, -{ - "line": 13, - "column": 18, + { + "line": 13, + "column": 5, "kind": "Return", - "value": { - "line": 13, - "column": 12, + "elems": [ + { + "line": 13, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar3/void-function/ast.json b/test/grammar3/void-function/ast.json index cb80ee2..4298c81 100644 --- a/test/grammar3/void-function/ast.json +++ b/test/grammar3/void-function/ast.json @@ -1,56 +1,80 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "noop", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 3, "kind": "Declare", "mut": "var", - "name": "x", - "init": { - "line": 2, - "column": 11, + "elems": [ + { + "line": 2, + "column": 7, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 11, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 7, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", - "params": [], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 3, "kind": "Return", - "value": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 10, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/all-types/ast.json b/test/grammar4/all-types/ast.json index 2475632..86e2abb 100644 --- a/test/grammar4/all-types/ast.json +++ b/test/grammar4/all-types/ast.json @@ -1,121 +1,175 @@ { - "line": 9, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 20, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int8", - "name": "a", - "init": { - "line": 2, - "column": 19, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 19, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 3, - "column": 21, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int16", - "name": "b", - "init": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 20, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 4, - "column": 21, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int32", - "name": "c", - "init": { - "line": 4, - "column": 20, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 20, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 5, - "column": 21, + { + "line": 5, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "d", - "init": { - "line": 5, - "column": 20, + "elems": [ + { + "line": 5, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 20, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 6, - "column": 23, + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "val", "type": "Bool", - "name": "e", - "init": { - "line": 6, - "column": 19, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] }, -{ - "line": 7, - "column": 25, + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "f", - "init": { - "line": 7, - "column": 21, + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 7, + "column": 21, "kind": "StringLiteral", - "value": "hi" + "elems": [] } + ] }, -{ - "line": 8, - "column": 26, + { + "line": 8, + "column": 5, "kind": "Return", - "value": { - "line": 8, - "column": 25, + "elems": [ + { + "line": 8, + "column": 12, "kind": "Cast", "type": "Int64", - "value": { - "line": 8, - "column": 24, + "elems": [ + { + "line": 8, + "column": 24, "kind": "Ident", - "name": "d" + "elems": [] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/bool-to-int-cast/ast.json b/test/grammar4/bool-to-int-cast/ast.json index f634b02..b95fcb5 100644 --- a/test/grammar4/bool-to-int-cast/ast.json +++ b/test/grammar4/bool-to-int-cast/ast.json @@ -1,65 +1,91 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 5, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 23, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "Bool", - "name": "x", - "init": { - "line": 2, - "column": 19, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 19, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] }, -{ - "line": 3, - "column": 34, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "y", - "init": { - "line": 3, - "column": 33, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 20, "kind": "Cast", "type": "Int64", - "value": { - "line": 3, - "column": 32, + "elems": [ + { + "line": 3, + "column": 32, "kind": "Ident", - "name": "x" + "elems": [] } + ] } + ] }, -{ - "line": 4, - "column": 13, + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "Ident", - "name": "y" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/bool-type/ast.json b/test/grammar4/bool-type/ast.json index 6de6d5b..fc38545 100644 --- a/test/grammar4/bool-type/ast.json +++ b/test/grammar4/bool-type/ast.json @@ -1,85 +1,117 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 23, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Bool", - "name": "a", - "init": { - "line": 2, - "column": 19, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 19, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] }, -{ - "line": 3, - "column": 24, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Bool", - "name": "b", - "init": { - "line": 3, - "column": 19, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 19, "kind": "BoolLiteral", - "value": false + "elems": [] } + ] }, -{ - "line": 4, - "column": 27, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "val", "type": "Bool", - "name": "cmp", - "init": { - "line": 4, - "column": 26, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 23, "kind": "BinOp", - "op": "==", - "left": { - "line": 4, - "column": 21, + "elems": [ + { + "line": 4, + "column": 21, "kind": "IntLiteral", - "value": 1 + "elems": [] }, - "right": { - "line": 4, - "column": 26, + { + "line": 4, + "column": 26, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] }, -{ - "line": 5, - "column": 13, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/cast-expr/ast.json b/test/grammar4/cast-expr/ast.json index 90888b7..8963e49 100644 --- a/test/grammar4/cast-expr/ast.json +++ b/test/grammar4/cast-expr/ast.json @@ -1,111 +1,157 @@ { - "line": 7, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 33, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int8", - "name": "x", - "init": { - "line": 2, - "column": 32, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 19, "kind": "Cast", "type": "Int8", - "value": { - "line": 2, - "column": 30, + "elems": [ + { + "line": 2, + "column": 30, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } + ] }, -{ - "line": 3, - "column": 34, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int16", - "name": "y", - "init": { - "line": 3, - "column": 33, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 20, "kind": "Cast", "type": "Int16", - "value": { - "line": 3, - "column": 32, + "elems": [ + { + "line": 3, + "column": 32, "kind": "Ident", - "name": "x" + "elems": [] } + ] } + ] }, -{ - "line": 4, - "column": 34, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int32", - "name": "z", - "init": { - "line": 4, - "column": 33, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 20, "kind": "Cast", "type": "Int32", - "value": { - "line": 4, - "column": 32, + "elems": [ + { + "line": 4, + "column": 32, "kind": "Ident", - "name": "y" + "elems": [] } + ] } + ] }, -{ - "line": 5, - "column": 34, + { + "line": 5, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "w", - "init": { - "line": 5, - "column": 33, + "elems": [ + { + "line": 5, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 20, "kind": "Cast", "type": "Int64", - "value": { - "line": 5, - "column": 32, + "elems": [ + { + "line": 5, + "column": 32, "kind": "Ident", - "name": "z" + "elems": [] } + ] } + ] }, -{ - "line": 6, - "column": 13, + { + "line": 6, + "column": 5, "kind": "Return", - "value": { - "line": 6, - "column": 12, + "elems": [ + { + "line": 6, + "column": 12, "kind": "Ident", - "name": "w" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/extern-typed/ast.json b/test/grammar4/extern-typed/ast.json index 53f7311..f9e5412 100644 --- a/test/grammar4/extern-typed/ast.json +++ b/test/grammar4/extern-typed/ast.json @@ -1,104 +1,160 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 1, - "column": 35, + "elems": [ + { + "line": 1, + "column": 1, "kind": "ExternDecl", - "name": "putchar", "returnType": "Int64", - "params": [{ - "line": 1, - "column": 23, - "kind": "Param", - "name": "c", - "type": "Int8" -}] + "elems": [ + { + "line": 1, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 20, + "kind": "Param", + "type": "Int8", + "elems": [ + { + "line": 1, + "column": 20, + "kind": "Ident", + "elems": [] + } + ] + } + ] }, -{ - "line": 2, - "column": 36, + { + "line": 2, + "column": 1, "kind": "ExternDecl", - "name": "exit", "returnType": "Int64", - "params": [{ - "line": 2, - "column": 23, - "kind": "Param", - "name": "code", - "type": "Int64" -}] + "elems": [ + { + "line": 2, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 17, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 2, + "column": 17, + "kind": "Ident", + "elems": [] + } + ] + } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 4, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 4, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 43, + "elems": [ + { + "line": 5, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "r", - "init": { - "line": 5, - "column": 42, + "elems": [ + { + "line": 5, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 27, "kind": "Call", - "callee": { - "line": 5, - "column": 20, + "elems": [ + { + "line": 5, + "column": 20, "kind": "Ident", - "name": "putchar" + "elems": [] }, - "args": [{ - "line": 5, - "column": 41, - "kind": "Cast", - "type": "Int8", - "value": { - "line": 5, - "column": 39, - "kind": "IntLiteral", - "value": 65 - } -}] + { + "line": 5, + "column": 28, + "kind": "Cast", + "type": "Int8", + "elems": [ + { + "line": 5, + "column": 39, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] } + ] }, -{ - "line": 6, - "column": 24, + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "code", - "init": { - "line": 6, - "column": 23, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 23, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 7, - "column": 16, + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "code" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/func-if-else-types/ast.json b/test/grammar4/func-if-else-types/ast.json index c64afbf..ece631d 100644 --- a/test/grammar4/func-if-else-types/ast.json +++ b/test/grammar4/func-if-else-types/ast.json @@ -1,144 +1,196 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "max", "returnType": "Int64", - "params": [{ - "line": 1, - "column": 12, - "kind": "Param", - "name": "a", - "type": "Int64" -}, { - "line": 1, - "column": 22, - "kind": "Param", - "name": "b", - "type": "Int64" -}], - "body": { - "line": 7, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 1, + "column": 19, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 1, + "column": 19, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 1, + "column": 36, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 5, + "elems": [ + { + "line": 2, + "column": 5, "kind": "If", - "cond": { - "line": 2, - "column": 13, + "elems": [ + { + "line": 2, + "column": 11, "kind": "BinOp", - "op": ">", - "left": { - "line": 2, - "column": 9, + "elems": [ + { + "line": 2, + "column": 9, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 2, - "column": 13, + { + "line": 2, + "column": 13, "kind": "Ident", - "name": "b" + "elems": [] } + ] }, - "then": { - "line": 4, - "column": 5, + { + "line": 2, + "column": 16, "kind": "Block", - "body": [ -{ - "line": 3, - "column": 17, + "elems": [ + { + "line": 3, + "column": 9, "kind": "Return", - "value": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 16, "kind": "Ident", - "name": "a" + "elems": [] } + ] } - ]}, - "else": { - "line": 6, - "column": 5, + ] + }, + { + "line": 4, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 17, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Return", - "value": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 16, "kind": "Ident", - "name": "b" + "elems": [] } + ] } - ]} + ] + } + ] } - ]} + ] + } + ] }, -{ - "line": 12, - "column": 1, + { + "line": 9, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 12, - "column": 1, + "elems": [ + { + "line": 9, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 9, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 10, - "column": 30, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "m", - "init": { - "line": 10, - "column": 29, + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 23, "kind": "Call", - "callee": { - "line": 10, - "column": 20, + "elems": [ + { + "line": 10, + "column": 20, "kind": "Ident", - "name": "max" + "elems": [] + }, + { + "line": 10, + "column": 24, + "kind": "IntLiteral", + "elems": [] }, - "args": [{ - "line": 10, - "column": 24, - "kind": "IntLiteral", - "value": 7 -}, { - "line": 10, - "column": 27, - "kind": "IntLiteral", - "value": 12 -}] + { + "line": 10, + "column": 27, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 11, - "column": 13, + { + "line": 11, + "column": 5, "kind": "Return", - "value": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "m" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/int-to-bool-cast/ast.json b/test/grammar4/int-to-bool-cast/ast.json index ea08ffd..d6352df 100644 --- a/test/grammar4/int-to-bool-cast/ast.json +++ b/test/grammar4/int-to-bool-cast/ast.json @@ -1,99 +1,131 @@ { - "line": 9, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 21, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "x", - "init": { - "line": 2, - "column": 20, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 20, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 3, - "column": 32, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "var", "type": "Bool", - "name": "y", - "init": { - "line": 3, - "column": 31, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 19, "kind": "Cast", "type": "Bool", - "value": { - "line": 3, - "column": 30, + "elems": [ + { + "line": 3, + "column": 30, "kind": "Ident", - "name": "x" + "elems": [] } + ] } + ] }, -{ - "line": 8, - "column": 5, + { + "line": 4, + "column": 5, "kind": "If", - "cond": { - "line": 4, - "column": 9, + "elems": [ + { + "line": 4, + "column": 9, "kind": "Ident", - "name": "y" + "elems": [] }, - "then": { - "line": 6, - "column": 5, + { + "line": 4, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 17, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Return", - "value": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 16, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 8, - "column": 5, + ] + }, + { + "line": 6, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 17, + "elems": [ + { + "line": 7, + "column": 9, "kind": "Return", - "value": { - "line": 7, - "column": 16, + "elems": [ + { + "line": 7, + "column": 16, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/interleaved-decls/ast.json b/test/grammar4/interleaved-decls/ast.json new file mode 100644 index 0000000..9f0c65e --- /dev/null +++ b/test/grammar4/interleaved-decls/ast.json @@ -0,0 +1,165 @@ +{ + "line": 1, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "FuncDecl", + "returnType": "Int64", + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 18, + "kind": "Block", + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 2, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 5, + "column": 1, + "kind": "ExternDecl", + "returnType": "Int64", + "elems": [ + { + "line": 5, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 16, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 5, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] + } + ] + }, + { + "line": 7, + "column": 1, + "kind": "FuncDecl", + "returnType": "Int64", + "elems": [ + { + "line": 7, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 7, + "column": 9, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 7, + "column": 26, + "kind": "Block", + "elems": [ + { + "line": 8, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 8, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 11, + "column": 1, + "kind": "ExternDecl", + "returnType": "Int64", + "elems": [ + { + "line": 11, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 13, + "column": 1, + "kind": "FuncDecl", + "returnType": "Int64", + "elems": [ + { + "line": 13, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 13, + "column": 19, + "kind": "Block", + "elems": [ + { + "line": 14, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 14, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/grammar4/interleaved-decls/meta.json b/test/grammar4/interleaved-decls/meta.json new file mode 100644 index 0000000..875a14b --- /dev/null +++ b/test/grammar4/interleaved-decls/meta.json @@ -0,0 +1,7 @@ +{ + "grammar": { + "lexer": ">=4", + "parser": ["4"] + }, + "stages": ["parser"] +} \ No newline at end of file diff --git a/test/grammar4/interleaved-decls/test.spl b/test/grammar4/interleaved-decls/test.spl new file mode 100644 index 0000000..716f325 --- /dev/null +++ b/test/grammar4/interleaved-decls/test.spl @@ -0,0 +1,15 @@ +def bar(): Int64 { + return 42; +} + +extern def foo(x: Int64): Int64; + +def baz(y: Int64): Int64 { + return y; +} + +extern def qux(): Int64; + +def main(): Int64 { + return 0; +} \ No newline at end of file diff --git a/test/grammar4/invalid-cast-syntax/ast.json b/test/grammar4/invalid-cast-syntax/ast.json index 684b51d..bba2ab2 100644 --- a/test/grammar4/invalid-cast-syntax/ast.json +++ b/test/grammar4/invalid-cast-syntax/ast.json @@ -1,6 +1,7 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -]} + "elems": [ + ] +} diff --git a/test/grammar4/missing-type-annotation/ast.json b/test/grammar4/missing-type-annotation/ast.json index 684b51d..bba2ab2 100644 --- a/test/grammar4/missing-type-annotation/ast.json +++ b/test/grammar4/missing-type-annotation/ast.json @@ -1,6 +1,7 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -]} + "elems": [ + ] +} diff --git a/test/grammar4/mixed-types/ast.json b/test/grammar4/mixed-types/ast.json index fce25f6..f425c6d 100644 --- a/test/grammar4/mixed-types/ast.json +++ b/test/grammar4/mixed-types/ast.json @@ -1,85 +1,120 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 26, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int32", - "name": "i32", - "init": { - "line": 2, - "column": 22, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 22, "kind": "IntLiteral", - "value": 1000 + "elems": [] } + ] }, -{ - "line": 3, - "column": 38, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int16", - "name": "i16", - "init": { - "line": 3, - "column": 37, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 22, "kind": "Cast", "type": "Int16", - "value": { - "line": 3, - "column": 34, + "elems": [ + { + "line": 3, + "column": 34, "kind": "Ident", - "name": "i32" + "elems": [] } + ] } + ] }, -{ - "line": 4, - "column": 38, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "i64", - "init": { - "line": 4, - "column": 37, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 22, "kind": "Cast", "type": "Int64", - "value": { - "line": 4, - "column": 34, + "elems": [ + { + "line": 4, + "column": 34, "kind": "Ident", - "name": "i16" + "elems": [] } + ] } + ] }, -{ - "line": 5, - "column": 15, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "Ident", - "name": "i64" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/no-main/ast.json b/test/grammar4/no-main/ast.json index 479a75f..f9d4213 100644 --- a/test/grammar4/no-main/ast.json +++ b/test/grammar4/no-main/ast.json @@ -1,31 +1,41 @@ { - "line": 3, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", "returnType": "Int64", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 18, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/string-comparison/ast.json b/test/grammar4/string-comparison/ast.json index 1e3d4a4..214b641 100644 --- a/test/grammar4/string-comparison/ast.json +++ b/test/grammar4/string-comparison/ast.json @@ -1,105 +1,136 @@ { - "line": 9, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 9, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 28, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "String", - "name": "a", - "init": { - "line": 2, - "column": 21, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 21, "kind": "StringLiteral", - "value": "hello" + "elems": [] } + ] }, -{ - "line": 3, - "column": 28, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "var", "type": "String", - "name": "b", - "init": { - "line": 3, - "column": 21, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 21, "kind": "StringLiteral", - "value": "hello" + "elems": [] } + ] }, -{ - "line": 8, - "column": 5, + { + "line": 4, + "column": 5, "kind": "If", - "cond": { - "line": 4, - "column": 14, + "elems": [ + { + "line": 4, + "column": 11, "kind": "BinOp", - "op": "==", - "left": { - "line": 4, - "column": 9, + "elems": [ + { + "line": 4, + "column": 9, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 4, - "column": 14, + { + "line": 4, + "column": 14, "kind": "Ident", - "name": "b" + "elems": [] } + ] }, - "then": { - "line": 6, - "column": 5, + { + "line": 4, + "column": 17, "kind": "Block", - "body": [ -{ - "line": 5, - "column": 17, + "elems": [ + { + "line": 5, + "column": 9, "kind": "Return", - "value": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 16, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } - ]}, - "else": { - "line": 8, - "column": 5, + ] + }, + { + "line": 6, + "column": 12, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 17, + "elems": [ + { + "line": 7, + "column": 9, "kind": "Return", - "value": { - "line": 7, - "column": 16, + "elems": [ + { + "line": 7, + "column": 16, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/string-escape/ast.json b/test/grammar4/string-escape/ast.json index 39e258a..46e5b1a 100644 --- a/test/grammar4/string-escape/ast.json +++ b/test/grammar4/string-escape/ast.json @@ -1,73 +1,104 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 38, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "s", - "init": { - "line": 2, - "column": 21, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 21, "kind": "StringLiteral", - "value": "hello\nworld\t!" + "elems": [] } + ] }, -{ - "line": 3, - "column": 36, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "t", - "init": { - "line": 3, - "column": 21, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 21, "kind": "StringLiteral", - "value": "quote \" here" + "elems": [] } + ] }, -{ - "line": 4, - "column": 34, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "u", - "init": { - "line": 4, - "column": 21, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 21, "kind": "StringLiteral", - "value": "back\\slash" + "elems": [] } + ] }, -{ - "line": 5, - "column": 13, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/string-literal/ast.json b/test/grammar4/string-literal/ast.json index 70617cd..3e04184 100644 --- a/test/grammar4/string-literal/ast.json +++ b/test/grammar4/string-literal/ast.json @@ -1,59 +1,83 @@ { - "line": 5, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 5, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 5, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 28, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "s", - "init": { - "line": 2, - "column": 21, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 21, "kind": "StringLiteral", - "value": "hello" + "elems": [] } + ] }, -{ - "line": 3, - "column": 30, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "String", - "name": "msg", - "init": { - "line": 3, - "column": 23, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 23, "kind": "StringLiteral", - "value": "world" + "elems": [] } + ] }, -{ - "line": 4, - "column": 13, + { + "line": 4, + "column": 5, "kind": "Return", - "value": { - "line": 4, - "column": 12, + "elems": [ + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/typed-declaration/ast.json b/test/grammar4/typed-declaration/ast.json index 63a36b2..3c68912 100644 --- a/test/grammar4/typed-declaration/ast.json +++ b/test/grammar4/typed-declaration/ast.json @@ -1,85 +1,117 @@ { - "line": 6, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 6, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 22, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": { - "line": 2, - "column": 20, + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 20, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, -{ - "line": 3, - "column": 22, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": { - "line": 3, - "column": 20, + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 3, + "column": 20, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, -{ - "line": 4, - "column": 27, + { + "line": 4, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "sum", - "init": { - "line": 4, - "column": 26, + "elems": [ + { + "line": 4, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 4, + "column": 24, "kind": "BinOp", - "op": "+", - "left": { - "line": 4, - "column": 22, + "elems": [ + { + "line": 4, + "column": 22, "kind": "Ident", - "name": "x" + "elems": [] }, - "right": { - "line": 4, - "column": 26, + { + "line": 4, + "column": 26, "kind": "Ident", - "name": "y" + "elems": [] } + ] } + ] }, -{ - "line": 5, - "column": 15, + { + "line": 5, + "column": 5, "kind": "Return", - "value": { - "line": 5, - "column": 12, + "elems": [ + { + "line": 5, + "column": 12, "kind": "Ident", - "name": "sum" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/typed-function/ast.json b/test/grammar4/typed-function/ast.json index ba6f2fb..b3ef79f 100644 --- a/test/grammar4/typed-function/ast.json +++ b/test/grammar4/typed-function/ast.json @@ -1,110 +1,156 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "add", "returnType": "Int64", - "params": [{ - "line": 1, - "column": 12, - "kind": "Param", - "name": "a", - "type": "Int64" -}, { - "line": 1, - "column": 22, - "kind": "Param", - "name": "b", - "type": "Int64" -}], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 9, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 1, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 1, + "column": 19, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 1, + "column": 19, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 1, + "column": 36, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 16, + "elems": [ + { + "line": 2, + "column": 14, "kind": "BinOp", - "op": "+", - "left": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "Ident", - "name": "a" + "elems": [] }, - "right": { - "line": 2, - "column": 16, + { + "line": 2, + "column": 16, "kind": "Ident", - "name": "b" + "elems": [] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 8, - "column": 1, + { + "line": 5, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 6, - "column": 34, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "result", - "init": { - "line": 6, - "column": 33, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 28, "kind": "Call", - "callee": { - "line": 6, - "column": 25, + "elems": [ + { + "line": 6, + "column": 25, "kind": "Ident", - "name": "add" + "elems": [] + }, + { + "line": 6, + "column": 29, + "kind": "IntLiteral", + "elems": [] }, - "args": [{ - "line": 6, - "column": 29, - "kind": "IntLiteral", - "value": 3 -}, { - "line": 6, - "column": 32, - "kind": "IntLiteral", - "value": 4 -}] + { + "line": 6, + "column": 32, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 7, - "column": 18, + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar4/var-no-init/ast.json b/test/grammar4/var-no-init/ast.json index 684b51d..bba2ab2 100644 --- a/test/grammar4/var-no-init/ast.json +++ b/test/grammar4/var-no-init/ast.json @@ -1,6 +1,7 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -]} + "elems": [ + ] +} diff --git a/test/grammar5/array-declaration/ast.json b/test/grammar5/array-declaration/ast.json index e8759fb..72486be 100644 --- a/test/grammar5/array-declaration/ast.json +++ b/test/grammar5/array-declaration/ast.json @@ -1,195 +1,238 @@ { - "line": 8, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 8, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 23, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[10](Int64)", - "name": "arr", - "init": null + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 15, + { + "line": 3, + "column": 8, "kind": "Assign", - "target": { - "line": 3, - "column": 10, + "elems": [ + { + "line": 3, + "column": 8, "kind": "Subscript", - "base": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 3, - "column": 9, + { + "line": 3, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 3, - "column": 14, + { + "line": 3, + "column": 14, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 4, - "column": 15, + { + "line": 4, + "column": 8, "kind": "Assign", - "target": { - "line": 4, - "column": 10, + "elems": [ + { + "line": 4, + "column": 8, "kind": "Subscript", - "base": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 4, - "column": 9, + { + "line": 4, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 4, - "column": 14, + { + "line": 4, + "column": 14, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 5, - "column": 15, + { + "line": 5, + "column": 8, "kind": "Assign", - "target": { - "line": 5, - "column": 10, + "elems": [ + { + "line": 5, + "column": 8, "kind": "Subscript", - "base": { - "line": 5, - "column": 5, + "elems": [ + { + "line": 5, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 5, - "column": 9, + { + "line": 5, + "column": 9, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "value": { - "line": 5, - "column": 14, + { + "line": 5, + "column": 14, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 6, - "column": 46, + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "sum", - "init": { - "line": 6, - "column": 45, + "elems": [ + { + "line": 6, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 38, "kind": "BinOp", - "op": "+", - "left": { - "line": 6, - "column": 36, + "elems": [ + { + "line": 6, + "column": 29, "kind": "BinOp", - "op": "+", - "left": { - "line": 6, - "column": 27, + "elems": [ + { + "line": 6, + "column": 25, "kind": "Subscript", - "base": { - "line": 6, - "column": 22, + "elems": [ + { + "line": 6, + "column": 22, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 6, - "column": 26, + { + "line": 6, + "column": 26, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 6, - "column": 36, + { + "line": 6, + "column": 34, "kind": "Subscript", - "base": { - "line": 6, - "column": 31, + "elems": [ + { + "line": 6, + "column": 31, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 6, - "column": 35, + { + "line": 6, + "column": 35, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] }, - "right": { - "line": 6, - "column": 45, + { + "line": 6, + "column": 43, "kind": "Subscript", - "base": { - "line": 6, - "column": 40, + "elems": [ + { + "line": 6, + "column": 40, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 6, - "column": 44, + { + "line": 6, + "column": 44, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } + ] }, -{ - "line": 7, - "column": 15, + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "sum" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/array-of-structs/ast.json b/test/grammar5/array-of-structs/ast.json index 14dc8c2..6c0fb25 100644 --- a/test/grammar5/array-of-structs/ast.json +++ b/test/grammar5/array-of-structs/ast.json @@ -1,247 +1,344 @@ { - "line": 13, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 11, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 11, + { + "line": 3, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 13, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 13, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 22, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[2](Point)", - "name": "pts", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 17, + { + "line": 8, + "column": 11, "kind": "Assign", - "target": { - "line": 8, - "column": 12, + "elems": [ + { + "line": 8, + "column": 11, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 10, + "elems": [ + { + "line": 8, + "column": 8, "kind": "Subscript", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 8, - "column": 9, + { + "line": 8, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "x" + { + "line": 8, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 16, + { + "line": 8, + "column": 16, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 9, - "column": 17, + { + "line": 9, + "column": 11, "kind": "Assign", - "target": { - "line": 9, - "column": 12, + "elems": [ + { + "line": 9, + "column": 11, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 10, + "elems": [ + { + "line": 9, + "column": 8, "kind": "Subscript", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 9, - "column": 9, + { + "line": 9, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "y" + { + "line": 9, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 16, + { + "line": 9, + "column": 16, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 10, - "column": 17, + { + "line": 10, + "column": 11, "kind": "Assign", - "target": { - "line": 10, - "column": 12, + "elems": [ + { + "line": 10, + "column": 11, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 10, + "elems": [ + { + "line": 10, + "column": 8, "kind": "Subscript", - "base": { - "line": 10, - "column": 5, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 10, - "column": 9, + { + "line": 10, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "x" + { + "line": 10, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 10, - "column": 16, + { + "line": 10, + "column": 16, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 11, - "column": 17, + { + "line": 11, + "column": 11, "kind": "Assign", - "target": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 11, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 10, + "elems": [ + { + "line": 11, + "column": 8, "kind": "Subscript", - "base": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 11, - "column": 9, + { + "line": 11, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "y" + { + "line": 11, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 11, - "column": 16, + { + "line": 11, + "column": 16, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 12, - "column": 31, + { + "line": 12, + "column": 5, "kind": "Return", - "value": { - "line": 12, - "column": 30, + "elems": [ + { + "line": 12, + "column": 21, "kind": "BinOp", - "op": "+", - "left": { - "line": 12, - "column": 19, + "elems": [ + { + "line": 12, + "column": 18, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 17, + "elems": [ + { + "line": 12, + "column": 15, "kind": "Subscript", - "base": { - "line": 12, - "column": 12, + "elems": [ + { + "line": 12, + "column": 12, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 12, - "column": 16, + { + "line": 12, + "column": 16, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "x" + { + "line": 12, + "column": 19, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 12, - "column": 30, + { + "line": 12, + "column": 29, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 28, + "elems": [ + { + "line": 12, + "column": 26, "kind": "Subscript", - "base": { - "line": 12, - "column": 23, + "elems": [ + { + "line": 12, + "column": 23, "kind": "Ident", - "name": "pts" + "elems": [] }, - "index": { - "line": 12, - "column": 27, + { + "line": 12, + "column": 27, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "y" + { + "line": 12, + "column": 30, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/array-struct/ast.json b/test/grammar5/array-struct/ast.json index e961cea..c594d96 100644 --- a/test/grammar5/array-struct/ast.json +++ b/test/grammar5/array-struct/ast.json @@ -1,358 +1,494 @@ { - "line": 16, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 16, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 16, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 25, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[3](Point)", - "name": "points", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 20, + { + "line": 8, + "column": 14, "kind": "Assign", - "target": { - "line": 8, - "column": 15, + "elems": [ + { + "line": 8, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 13, + "elems": [ + { + "line": 8, + "column": 11, "kind": "Subscript", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 8, - "column": 12, + { + "line": 8, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "x" + { + "line": 8, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 19, + { + "line": 8, + "column": 19, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 9, - "column": 20, + { + "line": 9, + "column": 14, "kind": "Assign", - "target": { - "line": 9, - "column": 15, + "elems": [ + { + "line": 9, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 13, + "elems": [ + { + "line": 9, + "column": 11, "kind": "Subscript", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 9, - "column": 12, + { + "line": 9, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "y" + { + "line": 9, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 19, + { + "line": 9, + "column": 19, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 10, - "column": 20, + { + "line": 10, + "column": 14, "kind": "Assign", - "target": { - "line": 10, - "column": 15, + "elems": [ + { + "line": 10, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 13, + "elems": [ + { + "line": 10, + "column": 11, "kind": "Subscript", - "base": { - "line": 10, - "column": 5, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 10, - "column": 12, + { + "line": 10, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "x" + { + "line": 10, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 10, - "column": 19, + { + "line": 10, + "column": 19, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 11, - "column": 20, + { + "line": 11, + "column": 14, "kind": "Assign", - "target": { - "line": 11, - "column": 15, + "elems": [ + { + "line": 11, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 13, + "elems": [ + { + "line": 11, + "column": 11, "kind": "Subscript", - "base": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 11, - "column": 12, + { + "line": 11, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "y" + { + "line": 11, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 11, - "column": 19, + { + "line": 11, + "column": 19, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 12, - "column": 20, + { + "line": 12, + "column": 14, "kind": "Assign", - "target": { - "line": 12, - "column": 15, + "elems": [ + { + "line": 12, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 13, + "elems": [ + { + "line": 12, + "column": 11, "kind": "Subscript", - "base": { - "line": 12, - "column": 5, + "elems": [ + { + "line": 12, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 12, - "column": 12, + { + "line": 12, + "column": 12, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "field": "x" + { + "line": 12, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 12, - "column": 19, + { + "line": 12, + "column": 19, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, -{ - "line": 13, - "column": 20, + { + "line": 13, + "column": 14, "kind": "Assign", - "target": { - "line": 13, - "column": 15, + "elems": [ + { + "line": 13, + "column": 14, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 13, + "elems": [ + { + "line": 13, + "column": 11, "kind": "Subscript", - "base": { - "line": 13, - "column": 5, + "elems": [ + { + "line": 13, + "column": 5, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 13, - "column": 12, + { + "line": 13, + "column": 12, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "field": "y" + { + "line": 13, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 13, - "column": 19, + { + "line": 13, + "column": 19, "kind": "IntLiteral", - "value": 6 + "elems": [] } + ] }, -{ - "line": 14, - "column": 61, + { + "line": 14, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "sum", - "init": { - "line": 14, - "column": 60, + "elems": [ + { + "line": 14, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 14, + "column": 48, "kind": "BinOp", - "op": "+", - "left": { - "line": 14, - "column": 46, + "elems": [ + { + "line": 14, + "column": 34, "kind": "BinOp", - "op": "+", - "left": { - "line": 14, - "column": 32, + "elems": [ + { + "line": 14, + "column": 31, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 30, + "elems": [ + { + "line": 14, + "column": 28, "kind": "Subscript", - "base": { - "line": 14, - "column": 22, + "elems": [ + { + "line": 14, + "column": 22, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 14, - "column": 29, + { + "line": 14, + "column": 29, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "x" + { + "line": 14, + "column": 32, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 14, - "column": 46, + { + "line": 14, + "column": 45, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 44, + "elems": [ + { + "line": 14, + "column": 42, "kind": "Subscript", - "base": { - "line": 14, - "column": 36, + "elems": [ + { + "line": 14, + "column": 36, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 14, - "column": 43, + { + "line": 14, + "column": 43, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "field": "y" + { + "line": 14, + "column": 46, + "kind": "Ident", + "elems": [] + } + ] } + ] }, - "right": { - "line": 14, - "column": 60, + { + "line": 14, + "column": 59, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 58, + "elems": [ + { + "line": 14, + "column": 56, "kind": "Subscript", - "base": { - "line": 14, - "column": 50, + "elems": [ + { + "line": 14, + "column": 50, "kind": "Ident", - "name": "points" + "elems": [] }, - "index": { - "line": 14, - "column": 57, + { + "line": 14, + "column": 57, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "field": "x" + { + "line": 14, + "column": 60, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 15, - "column": 15, + { + "line": 15, + "column": 5, "kind": "Return", - "value": { - "line": 15, - "column": 12, + "elems": [ + { + "line": 15, + "column": 12, "kind": "Ident", - "name": "sum" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/array-subscript/ast.json b/test/grammar5/array-subscript/ast.json index 92aef60..9a9c80c 100644 --- a/test/grammar5/array-subscript/ast.json +++ b/test/grammar5/array-subscript/ast.json @@ -1,231 +1,284 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 12, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 12, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 22, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[5](Int64)", - "name": "arr", - "init": null + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 17, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "i", - "init": null + "elems": [ + { + "line": 3, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 4, - "column": 10, + { + "line": 4, + "column": 5, "kind": "Assign", - "target": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "i" + "elems": [] }, - "value": { - "line": 4, - "column": 9, + { + "line": 4, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, -{ - "line": 5, - "column": 16, + { + "line": 5, + "column": 8, "kind": "Assign", - "target": { - "line": 5, - "column": 10, + "elems": [ + { + "line": 5, + "column": 8, "kind": "Subscript", - "base": { - "line": 5, - "column": 5, + "elems": [ + { + "line": 5, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 5, - "column": 9, + { + "line": 5, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 5, - "column": 14, + { + "line": 5, + "column": 14, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, -{ - "line": 6, - "column": 16, + { + "line": 6, + "column": 8, "kind": "Assign", - "target": { - "line": 6, - "column": 10, + "elems": [ + { + "line": 6, + "column": 8, "kind": "Subscript", - "base": { - "line": 6, - "column": 5, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 6, - "column": 9, + { + "line": 6, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 6, - "column": 14, + { + "line": 6, + "column": 14, "kind": "IntLiteral", - "value": 20 + "elems": [] } + ] }, -{ - "line": 7, - "column": 16, + { + "line": 7, + "column": 8, "kind": "Assign", - "target": { - "line": 7, - "column": 10, + "elems": [ + { + "line": 7, + "column": 8, "kind": "Subscript", - "base": { - "line": 7, - "column": 5, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 7, - "column": 9, + { + "line": 7, + "column": 9, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "value": { - "line": 7, - "column": 14, + { + "line": 7, + "column": 14, "kind": "IntLiteral", - "value": 30 + "elems": [] } + ] }, -{ - "line": 8, - "column": 16, + { + "line": 8, + "column": 8, "kind": "Assign", - "target": { - "line": 8, - "column": 10, + "elems": [ + { + "line": 8, + "column": 8, "kind": "Subscript", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 8, - "column": 9, + { + "line": 8, + "column": 9, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, - "value": { - "line": 8, - "column": 14, + { + "line": 8, + "column": 14, "kind": "IntLiteral", - "value": 40 + "elems": [] } + ] }, -{ - "line": 9, - "column": 16, + { + "line": 9, + "column": 8, "kind": "Assign", - "target": { - "line": 9, - "column": 10, + "elems": [ + { + "line": 9, + "column": 8, "kind": "Subscript", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 9, - "column": 9, + { + "line": 9, + "column": 9, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, - "value": { - "line": 9, - "column": 14, + { + "line": 9, + "column": 14, "kind": "IntLiteral", - "value": 50 + "elems": [] } + ] }, -{ - "line": 10, - "column": 31, + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "result", - "init": { - "line": 10, - "column": 30, + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 28, "kind": "Subscript", - "base": { - "line": 10, - "column": 25, + "elems": [ + { + "line": 10, + "column": 25, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 10, - "column": 29, + { + "line": 10, + "column": 29, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] }, -{ - "line": 11, - "column": 18, + { + "line": 11, + "column": 5, "kind": "Return", - "value": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/assignment-lvalue/ast.json b/test/grammar5/assignment-lvalue/ast.json index 8f0095c..0365f12 100644 --- a/test/grammar5/assignment-lvalue/ast.json +++ b/test/grammar5/assignment-lvalue/ast.json @@ -1,251 +1,352 @@ { - "line": 15, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Pair", - "fields": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "first", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 18, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "second", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 15, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 15, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 16, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Pair", - "name": "p", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 22, + { + "line": 8, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[4](Int64)", - "name": "arr", - "init": null + "elems": [ + { + "line": 8, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 9, - "column": 17, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "first" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 15, + { + "line": 9, + "column": 15, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, -{ - "line": 10, - "column": 18, + { + "line": 10, + "column": 6, "kind": "Assign", - "target": { - "line": 10, - "column": 7, + "elems": [ + { + "line": 10, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 5, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "second" + { + "line": 10, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 10, - "column": 16, + { + "line": 10, + "column": 16, "kind": "IntLiteral", - "value": 20 + "elems": [] } + ] }, -{ - "line": 11, - "column": 21, + { + "line": 11, + "column": 8, "kind": "Assign", - "target": { - "line": 11, - "column": 10, + "elems": [ + { + "line": 11, + "column": 8, "kind": "Subscript", - "base": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 11, - "column": 9, + { + "line": 11, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 11, - "column": 16, + { + "line": 11, + "column": 15, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 14, + "elems": [ + { + "line": 11, + "column": 14, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "first" + { + "line": 11, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] } + ] }, -{ - "line": 12, - "column": 22, + { + "line": 12, + "column": 8, "kind": "Assign", - "target": { - "line": 12, - "column": 10, + "elems": [ + { + "line": 12, + "column": 8, "kind": "Subscript", - "base": { - "line": 12, - "column": 5, + "elems": [ + { + "line": 12, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 12, - "column": 9, + { + "line": 12, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 12, - "column": 16, + { + "line": 12, + "column": 15, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 14, + "elems": [ + { + "line": 12, + "column": 14, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "second" + { + "line": 12, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] } + ] }, -{ - "line": 13, - "column": 30, + { + "line": 13, + "column": 6, "kind": "Assign", - "target": { - "line": 13, - "column": 7, + "elems": [ + { + "line": 13, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 5, + "elems": [ + { + "line": 13, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "first" + { + "line": 13, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 13, - "column": 29, + { + "line": 13, + "column": 22, "kind": "BinOp", - "op": "+", - "left": { - "line": 13, - "column": 20, + "elems": [ + { + "line": 13, + "column": 18, "kind": "Subscript", - "base": { - "line": 13, - "column": 15, + "elems": [ + { + "line": 13, + "column": 15, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 13, - "column": 19, + { + "line": 13, + "column": 19, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 13, - "column": 29, + { + "line": 13, + "column": 27, "kind": "Subscript", - "base": { - "line": 13, - "column": 24, + "elems": [ + { + "line": 13, + "column": 24, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 13, - "column": 28, + { + "line": 13, + "column": 28, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } + ] }, -{ - "line": 14, - "column": 19, + { + "line": 14, + "column": 5, "kind": "Return", - "value": { - "line": 14, - "column": 14, + "elems": [ + { + "line": 14, + "column": 13, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 12, + "elems": [ + { + "line": 14, + "column": 12, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "first" + { + "line": 14, + "column": 14, + "kind": "Ident", + "elems": [] + } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/generic-field-access/ast.json b/test/grammar5/generic-field-access/ast.json index d7c3717..e9136ee 100644 --- a/test/grammar5/generic-field-access/ast.json +++ b/test/grammar5/generic-field-access/ast.json @@ -1,161 +1,236 @@ { - "line": 13, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Rectangle", - "fields": [ -{ - "line": 2, - "column": 15, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "width", - "init": null + "elems": [ + { + "line": 2, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 16, + { + "line": 3, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "height", - "init": null + "elems": [ + { + "line": 3, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 13, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 13, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 21, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Rectangle", - "name": "r", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 16, + { + "line": 8, + "column": 6, "kind": "Assign", - "target": { - "line": 8, - "column": 7, + "elems": [ + { + "line": 8, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "width" + { + "line": 8, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 15, + { + "line": 8, + "column": 15, "kind": "IntLiteral", - "value": 6 + "elems": [] } + ] }, -{ - "line": 9, - "column": 17, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "height" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 16, + { + "line": 9, + "column": 16, "kind": "IntLiteral", - "value": 7 + "elems": [] } + ] }, -{ - "line": 10, - "column": 20, + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "area", - "init": null + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 11, - "column": 30, + { + "line": 11, + "column": 5, "kind": "Assign", - "target": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "area" + "elems": [] }, - "value": { - "line": 11, - "column": 24, + { + "line": 11, + "column": 20, "kind": "BinOp", - "op": "*", - "left": { - "line": 11, - "column": 14, + "elems": [ + { + "line": 11, + "column": 13, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "width" + { + "line": 11, + "column": 14, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 11, - "column": 24, + { + "line": 11, + "column": 23, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 22, + "elems": [ + { + "line": 11, + "column": 22, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "height" + { + "line": 11, + "column": 24, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 12, - "column": 16, + { + "line": 12, + "column": 5, "kind": "Return", - "value": { - "line": 12, - "column": 12, + "elems": [ + { + "line": 12, + "column": 12, "kind": "Ident", - "name": "area" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/interleaved-decls/ast.json b/test/grammar5/interleaved-decls/ast.json new file mode 100644 index 0000000..95c3f4d --- /dev/null +++ b/test/grammar5/interleaved-decls/ast.json @@ -0,0 +1,358 @@ +{ + "line": 1, + "column": 1, + "kind": "Program", + "elems": [ + { + "line": 1, + "column": 1, + "kind": "StructDecl", + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, + "kind": "Declare", + "mut": "val", + "type": "Int64", + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 3, + "column": 5, + "kind": "Declare", + "mut": "val", + "type": "Int64", + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] + } + ] + }, + { + "line": 6, + "column": 1, + "kind": "ExternDecl", + "returnType": "Int64", + "elems": [ + { + "line": 6, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 16, + "kind": "Param", + "type": "Point", + "elems": [ + { + "line": 6, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] + } + ] + }, + { + "line": 8, + "column": 1, + "kind": "FuncDecl", + "returnType": "Int64", + "elems": [ + { + "line": 8, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 8, + "column": 18, + "kind": "Block", + "elems": [ + { + "line": 9, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 9, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 12, + "column": 1, + "kind": "StructDecl", + "elems": [ + { + "line": 12, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 13, + "column": 5, + "kind": "Declare", + "mut": "val", + "type": "Point", + "elems": [ + { + "line": 13, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 14, + "column": 5, + "kind": "Declare", + "mut": "val", + "type": "Int64", + "elems": [ + { + "line": 14, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] + } + ] + }, + { + "line": 17, + "column": 1, + "kind": "ExternDecl", + "returnType": "Int64", + "elems": [ + { + "line": 17, + "column": 12, + "kind": "Ident", + "elems": [] + }, + { + "line": 17, + "column": 16, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 17, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] + } + ] + }, + { + "line": 19, + "column": 1, + "kind": "FuncDecl", + "returnType": "Point", + "elems": [ + { + "line": 19, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 19, + "column": 15, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 19, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 19, + "column": 25, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 19, + "column": 25, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 19, + "column": 42, + "kind": "Block", + "elems": [ + { + "line": 20, + "column": 5, + "kind": "Declare", + "mut": "var", + "type": "Point", + "elems": [ + { + "line": 20, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 21, + "column": 6, + "kind": "Assign", + "elems": [ + { + "line": 21, + "column": 6, + "kind": "FieldAccess", + "elems": [ + { + "line": 21, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 21, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 21, + "column": 11, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 22, + "column": 6, + "kind": "Assign", + "elems": [ + { + "line": 22, + "column": 6, + "kind": "FieldAccess", + "elems": [ + { + "line": 22, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 22, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 22, + "column": 11, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 23, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 23, + "column": 12, + "kind": "Ident", + "elems": [] + } + ] + } + ] + } + ] + }, + { + "line": 26, + "column": 1, + "kind": "FuncDecl", + "returnType": "Int64", + "elems": [ + { + "line": 26, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 26, + "column": 19, + "kind": "Block", + "elems": [ + { + "line": 27, + "column": 5, + "kind": "Return", + "elems": [ + { + "line": 27, + "column": 12, + "kind": "IntLiteral", + "elems": [] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/grammar5/interleaved-decls/meta.json b/test/grammar5/interleaved-decls/meta.json new file mode 100644 index 0000000..0c3ee9d --- /dev/null +++ b/test/grammar5/interleaved-decls/meta.json @@ -0,0 +1,7 @@ +{ + "grammar": { + "lexer": ">=5", + "parser": ["5"] + }, + "stages": ["parser"] +} \ No newline at end of file diff --git a/test/grammar5/interleaved-decls/test.spl b/test/grammar5/interleaved-decls/test.spl new file mode 100644 index 0000000..728434c --- /dev/null +++ b/test/grammar5/interleaved-decls/test.spl @@ -0,0 +1,28 @@ +struct Point { + x: Int64; + y: Int64; +} + +extern def foo(p: Point): Int64; + +def bar(): Int64 { + return 42; +} + +struct Line { + start: Point; + end: Int64; +} + +extern def baz(x: Int64): Int64; + +def makePoint(x: Int64, y: Int64): Point { + var p: Point; + p.x = x; + p.y = y; + return p; +} + +def main(): Int64 { + return 0; +} \ No newline at end of file diff --git a/test/grammar5/invalid-struct-syntax/ast.json b/test/grammar5/invalid-struct-syntax/ast.json index bb95e83..e555c6a 100644 --- a/test/grammar5/invalid-struct-syntax/ast.json +++ b/test/grammar5/invalid-struct-syntax/ast.json @@ -1,31 +1,50 @@ { - "line": 4, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 9, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 4, - "column": 1, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]} -]} + ] + } + ] +} diff --git a/test/grammar5/multi-dim-array/ast.json b/test/grammar5/multi-dim-array/ast.json index 60fc115..9521ac5 100644 --- a/test/grammar5/multi-dim-array/ast.json +++ b/test/grammar5/multi-dim-array/ast.json @@ -1,378 +1,451 @@ { - "line": 11, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 11, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 11, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 28, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[2](Array[2](Int64))", - "name": "matrix", - "init": null + "elems": [ + { + "line": 2, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 21, + { + "line": 3, + "column": 14, "kind": "Assign", - "target": { - "line": 3, - "column": 16, + "elems": [ + { + "line": 3, + "column": 14, "kind": "Subscript", - "base": { - "line": 3, - "column": 13, + "elems": [ + { + "line": 3, + "column": 11, "kind": "Subscript", - "base": { - "line": 3, - "column": 5, + "elems": [ + { + "line": 3, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 3, - "column": 12, + { + "line": 3, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "index": { - "line": 3, - "column": 15, + { + "line": 3, + "column": 15, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 3, - "column": 20, + { + "line": 3, + "column": 20, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 4, - "column": 21, + { + "line": 4, + "column": 14, "kind": "Assign", - "target": { - "line": 4, - "column": 16, + "elems": [ + { + "line": 4, + "column": 14, "kind": "Subscript", - "base": { - "line": 4, - "column": 13, + "elems": [ + { + "line": 4, + "column": 11, "kind": "Subscript", - "base": { - "line": 4, - "column": 5, + "elems": [ + { + "line": 4, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 4, - "column": 12, + { + "line": 4, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "index": { - "line": 4, - "column": 15, + { + "line": 4, + "column": 15, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 4, - "column": 20, + { + "line": 4, + "column": 20, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 5, - "column": 21, + { + "line": 5, + "column": 14, "kind": "Assign", - "target": { - "line": 5, - "column": 16, + "elems": [ + { + "line": 5, + "column": 14, "kind": "Subscript", - "base": { - "line": 5, - "column": 13, + "elems": [ + { + "line": 5, + "column": 11, "kind": "Subscript", - "base": { - "line": 5, - "column": 5, + "elems": [ + { + "line": 5, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 5, - "column": 12, + { + "line": 5, + "column": 12, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "index": { - "line": 5, - "column": 15, + { + "line": 5, + "column": 15, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "value": { - "line": 5, - "column": 20, + { + "line": 5, + "column": 20, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 6, - "column": 21, + { + "line": 6, + "column": 14, "kind": "Assign", - "target": { - "line": 6, - "column": 16, + "elems": [ + { + "line": 6, + "column": 14, "kind": "Subscript", - "base": { - "line": 6, - "column": 13, + "elems": [ + { + "line": 6, + "column": 11, "kind": "Subscript", - "base": { - "line": 6, - "column": 5, + "elems": [ + { + "line": 6, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 6, - "column": 12, + { + "line": 6, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "index": { - "line": 6, - "column": 15, + { + "line": 6, + "column": 15, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 6, - "column": 20, + { + "line": 6, + "column": 20, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 7, - "column": 21, + { + "line": 7, + "column": 14, "kind": "Assign", - "target": { - "line": 7, - "column": 16, + "elems": [ + { + "line": 7, + "column": 14, "kind": "Subscript", - "base": { - "line": 7, - "column": 13, + "elems": [ + { + "line": 7, + "column": 11, "kind": "Subscript", - "base": { - "line": 7, - "column": 5, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 7, - "column": 12, + { + "line": 7, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "index": { - "line": 7, - "column": 15, + { + "line": 7, + "column": 15, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 7, - "column": 20, + { + "line": 7, + "column": 20, "kind": "IntLiteral", - "value": 5 + "elems": [] } + ] }, -{ - "line": 8, - "column": 21, + { + "line": 8, + "column": 14, "kind": "Assign", - "target": { - "line": 8, - "column": 16, + "elems": [ + { + "line": 8, + "column": 14, "kind": "Subscript", - "base": { - "line": 8, - "column": 13, + "elems": [ + { + "line": 8, + "column": 11, "kind": "Subscript", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 8, - "column": 12, + { + "line": 8, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "index": { - "line": 8, - "column": 15, + { + "line": 8, + "column": 15, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, - "value": { - "line": 8, - "column": 20, + { + "line": 8, + "column": 20, "kind": "IntLiteral", - "value": 6 + "elems": [] } + ] }, -{ - "line": 9, - "column": 64, + { + "line": 9, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "sum", - "init": { - "line": 9, - "column": 63, + "elems": [ + { + "line": 9, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 9, + "column": 50, "kind": "BinOp", - "op": "+", - "left": { - "line": 9, - "column": 48, + "elems": [ + { + "line": 9, + "column": 35, "kind": "BinOp", - "op": "+", - "left": { - "line": 9, - "column": 33, + "elems": [ + { + "line": 9, + "column": 31, "kind": "Subscript", - "base": { - "line": 9, - "column": 30, + "elems": [ + { + "line": 9, + "column": 28, "kind": "Subscript", - "base": { - "line": 9, - "column": 22, + "elems": [ + { + "line": 9, + "column": 22, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 9, - "column": 29, + { + "line": 9, + "column": 29, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "index": { - "line": 9, - "column": 32, + { + "line": 9, + "column": 32, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 9, - "column": 48, + { + "line": 9, + "column": 46, "kind": "Subscript", - "base": { - "line": 9, - "column": 45, + "elems": [ + { + "line": 9, + "column": 43, "kind": "Subscript", - "base": { - "line": 9, - "column": 37, + "elems": [ + { + "line": 9, + "column": 37, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 9, - "column": 44, + { + "line": 9, + "column": 44, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "index": { - "line": 9, - "column": 47, + { + "line": 9, + "column": 47, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] }, - "right": { - "line": 9, - "column": 63, + { + "line": 9, + "column": 61, "kind": "Subscript", - "base": { - "line": 9, - "column": 60, + "elems": [ + { + "line": 9, + "column": 58, "kind": "Subscript", - "base": { - "line": 9, - "column": 52, + "elems": [ + { + "line": 9, + "column": 52, "kind": "Ident", - "name": "matrix" + "elems": [] }, - "index": { - "line": 9, - "column": 59, + { + "line": 9, + "column": 59, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "index": { - "line": 9, - "column": 62, + { + "line": 9, + "column": 62, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] } + ] } + ] }, -{ - "line": 10, - "column": 15, + { + "line": 10, + "column": 5, "kind": "Return", - "value": { - "line": 10, - "column": 12, + "elems": [ + { + "line": 10, + "column": 12, "kind": "Ident", - "name": "sum" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/no-main/ast.json b/test/grammar5/no-main/ast.json index 479a75f..f9d4213 100644 --- a/test/grammar5/no-main/ast.json +++ b/test/grammar5/no-main/ast.json @@ -1,31 +1,41 @@ { - "line": 3, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "FuncDecl", - "name": "foo", "returnType": "Int64", - "params": [], - "body": { - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 1, + "column": 18, "kind": "Block", - "body": [ -{ - "line": 2, - "column": 14, + "elems": [ + { + "line": 2, + "column": 5, "kind": "Return", - "value": { - "line": 2, - "column": 12, + "elems": [ + { + "line": 2, + "column": 12, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/simple-struct/ast.json b/test/grammar5/simple-struct/ast.json index cb6b2e9..3dcdfaa 100644 --- a/test/grammar5/simple-struct/ast.json +++ b/test/grammar5/simple-struct/ast.json @@ -1,149 +1,223 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 12, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 12, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 17, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "p", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 13, + { + "line": 8, + "column": 6, "kind": "Assign", - "target": { - "line": 8, - "column": 7, + "elems": [ + { + "line": 8, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "x" + { + "line": 8, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 11, + { + "line": 8, + "column": 11, "kind": "IntLiteral", - "value": 10 + "elems": [] } + ] }, -{ - "line": 9, - "column": 13, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "y" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 11, + { + "line": 9, + "column": 11, "kind": "IntLiteral", - "value": 20 + "elems": [] } + ] }, -{ - "line": 10, - "column": 31, + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "sum", - "init": { - "line": 10, - "column": 30, + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 26, "kind": "BinOp", - "op": "+", - "left": { - "line": 10, - "column": 24, + "elems": [ + { + "line": 10, + "column": 23, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 22, + "elems": [ + { + "line": 10, + "column": 22, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "x" + { + "line": 10, + "column": 24, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 10, - "column": 30, + { + "line": 10, + "column": 29, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 28, + "elems": [ + { + "line": 10, + "column": 28, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "y" + { + "line": 10, + "column": 30, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 11, - "column": 15, + { + "line": 11, + "column": 5, "kind": "Return", - "value": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "sum" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/struct-field-access/ast.json b/test/grammar5/struct-field-access/ast.json index 78acf28..c78b557 100644 --- a/test/grammar5/struct-field-access/ast.json +++ b/test/grammar5/struct-field-access/ast.json @@ -1,149 +1,223 @@ { - "line": 12, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Rectangle", - "fields": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "width", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 18, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "height", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 12, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 12, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 21, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Rectangle", - "name": "r", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 17, + { + "line": 8, + "column": 6, "kind": "Assign", - "target": { - "line": 8, - "column": 7, + "elems": [ + { + "line": 8, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "width" + { + "line": 8, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 15, + { + "line": 8, + "column": 15, "kind": "IntLiteral", - "value": 30 + "elems": [] } + ] }, -{ - "line": 9, - "column": 18, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "height" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 16, + { + "line": 9, + "column": 16, "kind": "IntLiteral", - "value": 15 + "elems": [] } + ] }, -{ - "line": 10, - "column": 41, + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "area", - "init": { - "line": 10, - "column": 35, + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 31, "kind": "BinOp", - "op": "*", - "left": { - "line": 10, - "column": 25, + "elems": [ + { + "line": 10, + "column": 24, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 23, + "elems": [ + { + "line": 10, + "column": 23, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "width" + { + "line": 10, + "column": 25, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 10, - "column": 35, + { + "line": 10, + "column": 34, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 33, + "elems": [ + { + "line": 10, + "column": 33, "kind": "Ident", - "name": "r" + "elems": [] }, - "field": "height" + { + "line": 10, + "column": 35, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 11, - "column": 16, + { + "line": 11, + "column": 5, "kind": "Return", - "value": { - "line": 11, - "column": 12, + "elems": [ + { + "line": 11, + "column": 12, "kind": "Ident", - "name": "area" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/struct-function/ast.json b/test/grammar5/struct-function/ast.json index b5cce01..b7024b6 100644 --- a/test/grammar5/struct-function/ast.json +++ b/test/grammar5/struct-function/ast.json @@ -1,228 +1,338 @@ { - "line": 18, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 11, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "makePoint", "returnType": "Point", - "params": [{ - "line": 6, - "column": 19, - "kind": "Param", - "name": "px", - "type": "Int64" -}, { - "line": 6, - "column": 30, - "kind": "Param", - "name": "py", - "type": "Int64" -}], - "body": { - "line": 11, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 15, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 6, + "column": 15, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 6, + "column": 26, + "kind": "Param", + "type": "Int64", + "elems": [ + { + "line": 6, + "column": 26, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 6, + "column": 44, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 17, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "p", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 13, + { + "line": 8, + "column": 6, "kind": "Assign", - "target": { - "line": 8, - "column": 7, + "elems": [ + { + "line": 8, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 8, - "column": 5, + "elems": [ + { + "line": 8, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "x" + { + "line": 8, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 8, - "column": 11, + { + "line": 8, + "column": 11, "kind": "Ident", - "name": "px" + "elems": [] } + ] }, -{ - "line": 9, - "column": 13, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "y" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 11, + { + "line": 9, + "column": 11, "kind": "Ident", - "name": "py" + "elems": [] } + ] }, -{ - "line": 10, - "column": 13, + { + "line": 10, + "column": 5, "kind": "Return", - "value": { - "line": 10, - "column": 12, + "elems": [ + { + "line": 10, + "column": 12, "kind": "Ident", - "name": "p" + "elems": [] } + ] } - ]} + ] + } + ] }, -{ - "line": 18, - "column": 1, + { + "line": 13, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 18, - "column": 1, + "elems": [ + { + "line": 13, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 13, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 14, - "column": 18, + "elems": [ + { + "line": 14, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "pt", - "init": null + "elems": [ + { + "line": 14, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 15, - "column": 25, + { + "line": 15, + "column": 5, "kind": "Assign", - "target": { - "line": 15, - "column": 5, + "elems": [ + { + "line": 15, + "column": 5, "kind": "Ident", - "name": "pt" + "elems": [] }, - "value": { - "line": 15, - "column": 24, + { + "line": 15, + "column": 19, "kind": "Call", - "callee": { - "line": 15, - "column": 10, + "elems": [ + { + "line": 15, + "column": 10, "kind": "Ident", - "name": "makePoint" + "elems": [] + }, + { + "line": 15, + "column": 20, + "kind": "IntLiteral", + "elems": [] }, - "args": [{ - "line": 15, - "column": 20, - "kind": "IntLiteral", - "value": 3 -}, { - "line": 15, - "column": 23, - "kind": "IntLiteral", - "value": 4 -}] + { + "line": 15, + "column": 23, + "kind": "IntLiteral", + "elems": [] + } + ] } + ] }, -{ - "line": 16, - "column": 36, + { + "line": 16, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "result", - "init": { - "line": 16, - "column": 35, + "elems": [ + { + "line": 16, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 16, + "column": 30, "kind": "BinOp", - "op": "+", - "left": { - "line": 16, - "column": 28, + "elems": [ + { + "line": 16, + "column": 27, "kind": "FieldAccess", - "base": { - "line": 16, - "column": 25, + "elems": [ + { + "line": 16, + "column": 25, "kind": "Ident", - "name": "pt" + "elems": [] }, - "field": "x" + { + "line": 16, + "column": 28, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 16, - "column": 35, + { + "line": 16, + "column": 34, "kind": "FieldAccess", - "base": { - "line": 16, - "column": 32, + "elems": [ + { + "line": 16, + "column": 32, "kind": "Ident", - "name": "pt" + "elems": [] }, - "field": "y" + { + "line": 16, + "column": 35, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 17, - "column": 18, + { + "line": 17, + "column": 5, "kind": "Return", - "value": { - "line": 17, - "column": 12, + "elems": [ + { + "line": 17, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/struct-mixed-fields/ast.json b/test/grammar5/struct-mixed-fields/ast.json index 2d4b23c..764a3af 100644 --- a/test/grammar5/struct-mixed-fields/ast.json +++ b/test/grammar5/struct-mixed-fields/ast.json @@ -1,343 +1,500 @@ { - "line": 21, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 8, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Mixed", - "fields": [ -{ - "line": 2, - "column": 10, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int8", - "name": "a", - "init": null + "elems": [ + { + "line": 2, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 11, + { + "line": 3, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int16", - "name": "b", - "init": null + "elems": [ + { + "line": 3, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 4, - "column": 11, + { + "line": 4, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int32", - "name": "c", - "init": null + "elems": [ + { + "line": 4, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 5, - "column": 11, + { + "line": 5, + "column": 3, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "d", - "init": null + "elems": [ + { + "line": 5, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 6, - "column": 10, + { + "line": 6, + "column": 3, "kind": "Declare", "mut": "val", "type": "Bool", - "name": "e", - "init": null + "elems": [ + { + "line": 6, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 7, - "column": 12, + { + "line": 7, + "column": 3, "kind": "Declare", "mut": "val", "type": "String", - "name": "f", - "init": null + "elems": [ + { + "line": 7, + "column": 3, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 21, - "column": 1, + ] + }, + { + "line": 10, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 21, - "column": 1, + "elems": [ + { + "line": 10, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 11, - "column": 17, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Declare", "mut": "var", "type": "Mixed", - "name": "m", - "init": null + "elems": [ + { + "line": 11, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 12, - "column": 12, + { + "line": 12, + "column": 6, "kind": "Assign", - "target": { - "line": 12, - "column": 7, + "elems": [ + { + "line": 12, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 5, + "elems": [ + { + "line": 12, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "a" + { + "line": 12, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 12, - "column": 11, + { + "line": 12, + "column": 11, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 13, - "column": 12, + { + "line": 13, + "column": 6, "kind": "Assign", - "target": { - "line": 13, - "column": 7, + "elems": [ + { + "line": 13, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 5, + "elems": [ + { + "line": 13, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "b" + { + "line": 13, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 13, - "column": 11, + { + "line": 13, + "column": 11, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 14, - "column": 12, + { + "line": 14, + "column": 6, "kind": "Assign", - "target": { - "line": 14, - "column": 7, + "elems": [ + { + "line": 14, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 5, + "elems": [ + { + "line": 14, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "c" + { + "line": 14, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 14, - "column": 11, + { + "line": 14, + "column": 11, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 15, - "column": 12, + { + "line": 15, + "column": 6, "kind": "Assign", - "target": { - "line": 15, - "column": 7, + "elems": [ + { + "line": 15, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 15, - "column": 5, + "elems": [ + { + "line": 15, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "d" + { + "line": 15, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 15, - "column": 11, + { + "line": 15, + "column": 11, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 16, - "column": 15, + { + "line": 16, + "column": 6, "kind": "Assign", - "target": { - "line": 16, - "column": 7, + "elems": [ + { + "line": 16, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 16, - "column": 5, + "elems": [ + { + "line": 16, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "e" + { + "line": 16, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 16, - "column": 11, + { + "line": 16, + "column": 11, "kind": "BoolLiteral", - "value": true + "elems": [] } + ] }, -{ - "line": 17, - "column": 15, + { + "line": 17, + "column": 6, "kind": "Assign", - "target": { - "line": 17, - "column": 7, + "elems": [ + { + "line": 17, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 17, - "column": 5, + "elems": [ + { + "line": 17, + "column": 5, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "f" + { + "line": 17, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 17, - "column": 11, + { + "line": 17, + "column": 11, "kind": "StringLiteral", - "value": "hi" + "elems": [] } + ] }, -{ - "line": 18, - "column": 22, + { + "line": 18, + "column": 5, "kind": "Declare", "mut": "var", "type": "Int64", - "name": "result", - "init": null + "elems": [ + { + "line": 18, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 19, - "column": 74, + { + "line": 19, + "column": 5, "kind": "Assign", - "target": { - "line": 19, - "column": 5, + "elems": [ + { + "line": 19, + "column": 5, "kind": "Ident", - "name": "result" + "elems": [] }, - "value": { - "line": 19, - "column": 73, + { + "line": 19, + "column": 69, "kind": "BinOp", - "op": "+", - "left": { - "line": 19, - "column": 67, + "elems": [ + { + "line": 19, + "column": 50, "kind": "BinOp", - "op": "+", - "left": { - "line": 19, - "column": 48, + "elems": [ + { + "line": 19, + "column": 31, "kind": "BinOp", - "op": "+", - "left": { - "line": 19, - "column": 29, + "elems": [ + { + "line": 19, + "column": 14, "kind": "Cast", "type": "Int64", - "value": { - "line": 19, - "column": 28, + "elems": [ + { + "line": 19, + "column": 27, "kind": "FieldAccess", - "base": { - "line": 19, - "column": 26, + "elems": [ + { + "line": 19, + "column": 26, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "a" + { + "line": 19, + "column": 28, + "kind": "Ident", + "elems": [] + } + ] } + ] }, - "right": { - "line": 19, - "column": 48, + { + "line": 19, + "column": 33, "kind": "Cast", "type": "Int64", - "value": { - "line": 19, - "column": 47, + "elems": [ + { + "line": 19, + "column": 46, "kind": "FieldAccess", - "base": { - "line": 19, - "column": 45, + "elems": [ + { + "line": 19, + "column": 45, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "b" + { + "line": 19, + "column": 47, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, - "right": { - "line": 19, - "column": 67, + { + "line": 19, + "column": 52, "kind": "Cast", "type": "Int64", - "value": { - "line": 19, - "column": 66, + "elems": [ + { + "line": 19, + "column": 65, "kind": "FieldAccess", - "base": { - "line": 19, - "column": 64, + "elems": [ + { + "line": 19, + "column": 64, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "c" + { + "line": 19, + "column": 66, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, - "right": { - "line": 19, - "column": 73, + { + "line": 19, + "column": 72, "kind": "FieldAccess", - "base": { - "line": 19, - "column": 71, + "elems": [ + { + "line": 19, + "column": 71, "kind": "Ident", - "name": "m" + "elems": [] }, - "field": "d" + { + "line": 19, + "column": 73, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] }, -{ - "line": 20, - "column": 18, + { + "line": 20, + "column": 5, "kind": "Return", - "value": { - "line": 20, - "column": 12, + "elems": [ + { + "line": 20, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/struct-nested/ast.json b/test/grammar5/struct-nested/ast.json index 74d73b4..bc5edbc 100644 --- a/test/grammar5/struct-nested/ast.json +++ b/test/grammar5/struct-nested/ast.json @@ -1,163 +1,256 @@ { - "line": 14, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 3, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Inner", - "fields": [ -{ - "line": 2, - "column": 17, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "value", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 7, - "column": 1, + ] + }, + { + "line": 4, + "column": 1, "kind": "StructDecl", - "name": "Outer", - "fields": [ -{ - "line": 5, - "column": 17, + "elems": [ + { + "line": 4, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 5, + "column": 5, "kind": "Declare", "mut": "val", "type": "Inner", - "name": "inner", - "init": null + "elems": [ + { + "line": 5, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 6, - "column": 17, + { + "line": 6, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "extra", - "init": null + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 14, - "column": 1, + ] + }, + { + "line": 9, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 14, - "column": 1, + "elems": [ + { + "line": 9, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 9, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 10, - "column": 17, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Declare", "mut": "var", "type": "Outer", - "name": "o", - "init": null + "elems": [ + { + "line": 10, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 11, - "column": 23, + { + "line": 11, + "column": 12, "kind": "Assign", - "target": { - "line": 11, - "column": 13, + "elems": [ + { + "line": 11, + "column": 12, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 7, + "elems": [ + { + "line": 11, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "o" + "elems": [] }, - "field": "inner" + { + "line": 11, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "field": "value" + { + "line": 11, + "column": 13, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 11, - "column": 21, + { + "line": 11, + "column": 21, "kind": "IntLiteral", - "value": 42 + "elems": [] } + ] }, -{ - "line": 12, - "column": 16, + { + "line": 12, + "column": 6, "kind": "Assign", - "target": { - "line": 12, - "column": 7, + "elems": [ + { + "line": 12, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 5, + "elems": [ + { + "line": 12, + "column": 5, "kind": "Ident", - "name": "o" + "elems": [] }, - "field": "extra" + { + "line": 12, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 12, - "column": 15, + { + "line": 12, + "column": 15, "kind": "IntLiteral", - "value": 7 + "elems": [] } + ] }, -{ - "line": 13, - "column": 35, + { + "line": 13, + "column": 5, "kind": "Return", - "value": { - "line": 13, - "column": 30, + "elems": [ + { + "line": 13, + "column": 26, "kind": "BinOp", - "op": "+", - "left": { - "line": 13, - "column": 20, + "elems": [ + { + "line": 13, + "column": 19, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 14, + "elems": [ + { + "line": 13, + "column": 13, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 12, + "elems": [ + { + "line": 13, + "column": 12, "kind": "Ident", - "name": "o" + "elems": [] }, - "field": "inner" + { + "line": 13, + "column": 14, + "kind": "Ident", + "elems": [] + } + ] }, - "field": "value" + { + "line": 13, + "column": 20, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 13, - "column": 30, + { + "line": 13, + "column": 29, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 28, + "elems": [ + { + "line": 13, + "column": 28, "kind": "Ident", - "name": "o" + "elems": [] }, - "field": "extra" + { + "line": 13, + "column": 30, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/struct-param/ast.json b/test/grammar5/struct-param/ast.json index c07d638..6690ef4 100644 --- a/test/grammar5/struct-param/ast.json +++ b/test/grammar5/struct-param/ast.json @@ -1,293 +1,435 @@ { - "line": 19, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 8, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "dotProduct", "returnType": "Int64", - "params": [{ - "line": 6, - "column": 19, - "kind": "Param", - "name": "a", - "type": "Point" -}, { - "line": 6, - "column": 29, - "kind": "Param", - "name": "b", - "type": "Point" -}], - "body": { - "line": 8, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 16, + "kind": "Param", + "type": "Point", + "elems": [ + { + "line": 6, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 6, + "column": 26, + "kind": "Param", + "type": "Point", + "elems": [ + { + "line": 6, + "column": 26, + "kind": "Ident", + "elems": [] + } + ] + }, + { + "line": 6, + "column": 43, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 33, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Return", - "value": { - "line": 7, - "column": 32, + "elems": [ + { + "line": 7, + "column": 22, "kind": "BinOp", - "op": "+", - "left": { - "line": 7, - "column": 20, + "elems": [ + { + "line": 7, + "column": 16, "kind": "BinOp", - "op": "*", - "left": { - "line": 7, - "column": 14, + "elems": [ + { + "line": 7, + "column": 13, "kind": "FieldAccess", - "base": { - "line": 7, - "column": 12, + "elems": [ + { + "line": 7, + "column": 12, "kind": "Ident", - "name": "a" + "elems": [] }, - "field": "x" + { + "line": 7, + "column": 14, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 7, - "column": 20, + { + "line": 7, + "column": 19, "kind": "FieldAccess", - "base": { - "line": 7, - "column": 18, + "elems": [ + { + "line": 7, + "column": 18, "kind": "Ident", - "name": "b" + "elems": [] }, - "field": "x" + { + "line": 7, + "column": 20, + "kind": "Ident", + "elems": [] + } + ] } + ] }, - "right": { - "line": 7, - "column": 32, + { + "line": 7, + "column": 28, "kind": "BinOp", - "op": "*", - "left": { - "line": 7, - "column": 26, + "elems": [ + { + "line": 7, + "column": 25, "kind": "FieldAccess", - "base": { - "line": 7, - "column": 24, + "elems": [ + { + "line": 7, + "column": 24, "kind": "Ident", - "name": "a" + "elems": [] }, - "field": "y" + { + "line": 7, + "column": 26, + "kind": "Ident", + "elems": [] + } + ] }, - "right": { - "line": 7, - "column": 32, + { + "line": 7, + "column": 31, "kind": "FieldAccess", - "base": { - "line": 7, - "column": 30, + "elems": [ + { + "line": 7, + "column": 30, "kind": "Ident", - "name": "b" + "elems": [] }, - "field": "y" + { + "line": 7, + "column": 32, + "kind": "Ident", + "elems": [] + } + ] } + ] } + ] } + ] } - ]} + ] + } + ] }, -{ - "line": 19, - "column": 1, + { + "line": 10, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 19, - "column": 1, + "elems": [ + { + "line": 10, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 10, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 11, - "column": 18, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "p1", - "init": null + "elems": [ + { + "line": 11, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 12, - "column": 18, + { + "line": 12, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "p2", - "init": null + "elems": [ + { + "line": 12, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 13, - "column": 13, + { + "line": 13, + "column": 7, "kind": "Assign", - "target": { - "line": 13, - "column": 8, + "elems": [ + { + "line": 13, + "column": 7, "kind": "FieldAccess", - "base": { - "line": 13, - "column": 5, + "elems": [ + { + "line": 13, + "column": 5, "kind": "Ident", - "name": "p1" + "elems": [] }, - "field": "x" + { + "line": 13, + "column": 8, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 13, - "column": 12, + { + "line": 13, + "column": 12, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, -{ - "line": 14, - "column": 13, + { + "line": 14, + "column": 7, "kind": "Assign", - "target": { - "line": 14, - "column": 8, + "elems": [ + { + "line": 14, + "column": 7, "kind": "FieldAccess", - "base": { - "line": 14, - "column": 5, + "elems": [ + { + "line": 14, + "column": 5, "kind": "Ident", - "name": "p1" + "elems": [] }, - "field": "y" + { + "line": 14, + "column": 8, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 14, - "column": 12, + { + "line": 14, + "column": 12, "kind": "IntLiteral", - "value": 2 + "elems": [] } + ] }, -{ - "line": 15, - "column": 13, + { + "line": 15, + "column": 7, "kind": "Assign", - "target": { - "line": 15, - "column": 8, + "elems": [ + { + "line": 15, + "column": 7, "kind": "FieldAccess", - "base": { - "line": 15, - "column": 5, + "elems": [ + { + "line": 15, + "column": 5, "kind": "Ident", - "name": "p2" + "elems": [] }, - "field": "x" + { + "line": 15, + "column": 8, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 15, - "column": 12, + { + "line": 15, + "column": 12, "kind": "IntLiteral", - "value": 3 + "elems": [] } + ] }, -{ - "line": 16, - "column": 13, + { + "line": 16, + "column": 7, "kind": "Assign", - "target": { - "line": 16, - "column": 8, + "elems": [ + { + "line": 16, + "column": 7, "kind": "FieldAccess", - "base": { - "line": 16, - "column": 5, + "elems": [ + { + "line": 16, + "column": 5, "kind": "Ident", - "name": "p2" + "elems": [] }, - "field": "y" + { + "line": 16, + "column": 8, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 16, - "column": 12, + { + "line": 16, + "column": 12, "kind": "IntLiteral", - "value": 4 + "elems": [] } + ] }, -{ - "line": 17, - "column": 43, + { + "line": 17, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "result", - "init": { - "line": 17, - "column": 42, + "elems": [ + { + "line": 17, + "column": 9, + "kind": "Ident", + "elems": [] + }, + { + "line": 17, + "column": 35, "kind": "Call", - "callee": { - "line": 17, - "column": 25, + "elems": [ + { + "line": 17, + "column": 25, "kind": "Ident", - "name": "dotProduct" + "elems": [] }, - "args": [{ - "line": 17, - "column": 36, - "kind": "Ident", - "name": "p1" -}, { - "line": 17, - "column": 40, - "kind": "Ident", - "name": "p2" -}] + { + "line": 17, + "column": 36, + "kind": "Ident", + "elems": [] + }, + { + "line": 17, + "column": 40, + "kind": "Ident", + "elems": [] + } + ] } + ] }, -{ - "line": 18, - "column": 18, + { + "line": 18, + "column": 5, "kind": "Return", - "value": { - "line": 18, - "column": 12, + "elems": [ + { + "line": 18, + "column": 12, "kind": "Ident", - "name": "result" + "elems": [] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/grammar5/untyped-decl/ast.json b/test/grammar5/untyped-decl/ast.json index 684b51d..bba2ab2 100644 --- a/test/grammar5/untyped-decl/ast.json +++ b/test/grammar5/untyped-decl/ast.json @@ -1,6 +1,7 @@ { - "line": 2, - "column": 9, + "line": 1, + "column": 1, "kind": "Program", - "body": [ -]} + "elems": [ + ] +} diff --git a/test/grammar5/var-no-init/ast.json b/test/grammar5/var-no-init/ast.json index a7dab32..3953dd6 100644 --- a/test/grammar5/var-no-init/ast.json +++ b/test/grammar5/var-no-init/ast.json @@ -1,222 +1,307 @@ { - "line": 14, + "line": 1, "column": 1, "kind": "Program", - "body": [ -{ - "line": 4, - "column": 1, + "elems": [ + { + "line": 1, + "column": 1, "kind": "StructDecl", - "name": "Point", - "fields": [ -{ - "line": 2, - "column": 13, + "elems": [ + { + "line": 1, + "column": 8, + "kind": "Ident", + "elems": [] + }, + { + "line": 2, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "x", - "init": null + "elems": [ + { + "line": 2, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 3, - "column": 13, + { + "line": 3, + "column": 5, "kind": "Declare", "mut": "val", "type": "Int64", - "name": "y", - "init": null + "elems": [ + { + "line": 3, + "column": 5, + "kind": "Ident", + "elems": [] + } + ] } - ]}, -{ - "line": 14, - "column": 1, + ] + }, + { + "line": 6, + "column": 1, "kind": "FuncDecl", - "name": "main", "returnType": "Int64", - "params": [], - "body": { - "line": 14, - "column": 1, + "elems": [ + { + "line": 6, + "column": 5, + "kind": "Ident", + "elems": [] + }, + { + "line": 6, + "column": 19, "kind": "Block", - "body": [ -{ - "line": 7, - "column": 17, + "elems": [ + { + "line": 7, + "column": 5, "kind": "Declare", "mut": "var", "type": "Point", - "name": "p", - "init": null + "elems": [ + { + "line": 7, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 8, - "column": 22, + { + "line": 8, + "column": 5, "kind": "Declare", "mut": "var", "type": "Array[8](Int64)", - "name": "arr", - "init": null + "elems": [ + { + "line": 8, + "column": 9, + "kind": "Ident", + "elems": [] + } + ] }, -{ - "line": 9, - "column": 14, + { + "line": 9, + "column": 6, "kind": "Assign", - "target": { - "line": 9, - "column": 7, + "elems": [ + { + "line": 9, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 9, - "column": 5, + "elems": [ + { + "line": 9, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "x" + { + "line": 9, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 9, - "column": 11, + { + "line": 9, + "column": 11, "kind": "IntLiteral", - "value": 100 + "elems": [] } + ] }, -{ - "line": 10, - "column": 14, + { + "line": 10, + "column": 6, "kind": "Assign", - "target": { - "line": 10, - "column": 7, + "elems": [ + { + "line": 10, + "column": 6, "kind": "FieldAccess", - "base": { - "line": 10, - "column": 5, + "elems": [ + { + "line": 10, + "column": 5, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "y" + { + "line": 10, + "column": 7, + "kind": "Ident", + "elems": [] + } + ] }, - "value": { - "line": 10, - "column": 11, + { + "line": 10, + "column": 11, "kind": "IntLiteral", - "value": 200 + "elems": [] } + ] }, -{ - "line": 11, - "column": 17, + { + "line": 11, + "column": 8, "kind": "Assign", - "target": { - "line": 11, - "column": 10, + "elems": [ + { + "line": 11, + "column": 8, "kind": "Subscript", - "base": { - "line": 11, - "column": 5, + "elems": [ + { + "line": 11, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 11, - "column": 9, + { + "line": 11, + "column": 9, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "value": { - "line": 11, - "column": 16, + { + "line": 11, + "column": 15, "kind": "FieldAccess", - "base": { - "line": 11, - "column": 14, + "elems": [ + { + "line": 11, + "column": 14, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "x" + { + "line": 11, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] } + ] }, -{ - "line": 12, - "column": 17, + { + "line": 12, + "column": 8, "kind": "Assign", - "target": { - "line": 12, - "column": 10, + "elems": [ + { + "line": 12, + "column": 8, "kind": "Subscript", - "base": { - "line": 12, - "column": 5, + "elems": [ + { + "line": 12, + "column": 5, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 12, - "column": 9, + { + "line": 12, + "column": 9, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] }, - "value": { - "line": 12, - "column": 16, + { + "line": 12, + "column": 15, "kind": "FieldAccess", - "base": { - "line": 12, - "column": 14, + "elems": [ + { + "line": 12, + "column": 14, "kind": "Ident", - "name": "p" + "elems": [] }, - "field": "y" + { + "line": 12, + "column": 16, + "kind": "Ident", + "elems": [] + } + ] } + ] }, -{ - "line": 13, - "column": 27, + { + "line": 13, + "column": 5, "kind": "Return", - "value": { - "line": 13, - "column": 26, + "elems": [ + { + "line": 13, + "column": 19, "kind": "BinOp", - "op": "+", - "left": { - "line": 13, - "column": 17, + "elems": [ + { + "line": 13, + "column": 15, "kind": "Subscript", - "base": { - "line": 13, - "column": 12, + "elems": [ + { + "line": 13, + "column": 12, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 13, - "column": 16, + { + "line": 13, + "column": 16, "kind": "IntLiteral", - "value": 0 + "elems": [] } + ] }, - "right": { - "line": 13, - "column": 26, + { + "line": 13, + "column": 24, "kind": "Subscript", - "base": { - "line": 13, - "column": 21, + "elems": [ + { + "line": 13, + "column": 21, "kind": "Ident", - "name": "arr" + "elems": [] }, - "index": { - "line": 13, - "column": 25, + { + "line": 13, + "column": 25, "kind": "IntLiteral", - "value": 1 + "elems": [] } + ] } + ] } + ] } - ]} + ] + } + ] } -]} + ] +} diff --git a/test/schemas/ast.schema.json b/test/schemas/ast.schema.json new file mode 100644 index 0000000..0d16772 --- /dev/null +++ b/test/schemas/ast.schema.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "schemas/ast.schema.json", + "title": "Test ast.json", + "description": "Schema for test case AST files (ast.json) in the SysProLang compiler test suite.", + "definitions": { + "astNode": { + "description": "A recursive AST node. Every node has at least line, column, kind and elems. Other fields (value, name, op, body, elems, …) are allowed.", + "type": "object", + "properties": { + "line": { + "description": "Line number (1-based) where the node starts in the source file.", + "type": "integer", + "minimum": 1 + }, + "column": { + "description": "Column number (1-based) where the node starts in the source line.", + "type": "integer", + "minimum": 1 + }, + "kind": { + "description": "AST node kind (e.g., Program, Declare, IntLiteral, BinOp, …).", + "type": "string" + }, + "elems": { + "description": "Ordered list of child nodes (alternative to named fields like body, left, right, etc.).", + "type": "array", + "items": { + "$ref": "#/definitions/astNode" + } + } + }, + "required": ["line", "column", "kind", "elems"], + "additionalProperties": true + } + }, + "$ref": "#/definitions/astNode" +} diff --git a/test/schemas/meta.schema.json b/test/schemas/meta.schema.json index 632dcc0..3e6de1f 100644 --- a/test/schemas/meta.schema.json +++ b/test/schemas/meta.schema.json @@ -82,6 +82,7 @@ } }, "additionalProperties": false, + "required": ["grammar", "stages", "exit"], "definitions": { "exitSpec": { "description": "An exit code specification: \"nonzero\" or an exact integer.", diff --git a/test/schemas/tokens.schema.json b/test/schemas/tokens.schema.json new file mode 100644 index 0000000..1efff5e --- /dev/null +++ b/test/schemas/tokens.schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "schemas/tokens.schema.json", + "title": "Test tokens.json", + "description": "Schema for test case token lists (tokens.json) in the SysProLang compiler test suite.", + "type": "array", + "items": { + "title": "Token", + "description": "A single token produced by the lexer.", + "type": "object", + "properties": { + "kind": { + "description": "Token kind identifier (e.g., IDENT, INT, PLUS, SEMI, EOF, …).", + "type": "string" + }, + "line": { + "description": "Line number (1-based) where the token starts in the source file.", + "type": "integer", + "minimum": 1 + }, + "column": { + "description": "Column number (1-based) where the token starts in the source line.", + "type": "integer", + "minimum": 1 + } + }, + "required": ["kind", "line", "column"] + }, + "minItems": 1 +} \ No newline at end of file diff --git a/test/validate_schemas.py b/test/validate_schemas.py new file mode 100644 index 0000000..ce78c9e --- /dev/null +++ b/test/validate_schemas.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""Validate all config.json, meta.json, tokens.json and ast.json files against their JSON schemas. + +Usage: + python test/validate_schemas.py + +Exit code: + 0 — all files valid + 1 — one or more files invalid (details printed to stderr) +""" + +import glob +import json +import os +import sys +import traceback + +try: + from jsonschema import validate, ValidationError +except ImportError: + print("error: 'jsonschema' package not installed. Run: pip install jsonschema", + file=sys.stderr) + sys.exit(1) + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +SCHEMA_DIR = os.path.join(SCRIPT_DIR, "schemas") + + +def load_schema(name): + path = os.path.join(SCHEMA_DIR, name) + with open(path, encoding="utf-8") as f: + return json.load(f) + + +def validate_file(filepath, schema, label): + """Validate a single JSON file against a schema. Returns (path, error|None).""" + try: + with open(filepath, encoding="utf-8") as f: + data = json.load(f) + validate(instance=data, schema=schema) + return (filepath, None) + except json.JSONDecodeError as e: + return (filepath, f"invalid JSON: {e}") + except ValidationError as e: + # Short, readable error: field path + message + path = " → ".join(str(p) for p in e.absolute_path) if e.absolute_path else "(root)" + return (filepath, f"{path}: {e.message.split(chr(10))[0]}") + except Exception as e: + return (filepath, traceback.format_exc()) + + +def main(): + config_schema = load_schema("config.schema.json") + meta_schema = load_schema("meta.schema.json") + + # 1. Validate config.json + config_path = os.path.join(SCRIPT_DIR, "config.json") + results = [validate_file(config_path, config_schema, "config.json")] + + # 2. Validate all meta.json files under test/ + test_root = SCRIPT_DIR # SCRIPT_DIR is test/ + meta_pattern = os.path.join(test_root, "**", "meta.json") + for path in sorted(glob.glob(meta_pattern, recursive=True)): + results.append(validate_file(path, meta_schema, "meta.json")) + + tokens_schema = load_schema("tokens.schema.json") + + # 3. Validate all tokens.json files under test/ + tokens_pattern = os.path.join(test_root, "**", "tokens.json") + for path in sorted(glob.glob(tokens_pattern, recursive=True)): + results.append(validate_file(path, tokens_schema, "tokens.json")) + + ast_schema = load_schema("ast.schema.json") + + # 4. Validate all ast.json files under test/ + ast_pattern = os.path.join(test_root, "**", "ast.json") + for path in sorted(glob.glob(ast_pattern, recursive=True)): + results.append(validate_file(path, ast_schema, "ast.json")) + + # Print results + failed = 0 + for path, error in results: + rel = os.path.relpath(path, os.path.dirname(SCRIPT_DIR)) + if error is None: + print(f"✓ {rel}") + else: + print(f"✗ {rel}") + print(f" {error}", file=sys.stderr) + failed += 1 + + total = len(results) + print(f"\n{total - failed}/{total} files valid (config.json / meta.json / tokens.json / ast.json)", file=sys.stderr) + return 1 if failed else 0 + + +if __name__ == "__main__": + sys.exit(main()) \ No newline at end of file