From 2bdca90479584fe533d4ef4507e874833dcbf76a Mon Sep 17 00:00:00 2001 From: Youngteac Hong Date: Tue, 8 Oct 2024 22:43:31 +0900 Subject: [PATCH] Reorganize the grammar to fit TypeScript (#4) This commit introduces element-level schema definitions: - TypeScript-like type definition syntax - Primitive types and Element types of Yorkie - Support for user-defined types Test code has been added to validate these grammar specifications. * Add diagnostics for CodeMirror (#5) This commit introduces a CodeMirror editor example for validating Yorkie schema. Users can now visually inspect and validate Yorkie schema directly in the browser. Currently, the validation only highlights parsing errors. Future improvements could include detection and display of semantic errors for a more comprehensive schema validation experience. --------- Co-authored-by: Sumi Jeong <125195487+sigmaith@users.noreply.github.com> Co-authored-by: Yourim Cha --- antlr/Schema.g4 | 46 - antlr/Schema.interp | 49 - antlr/Schema.tokens | 24 - antlr/SchemaLexer.interp | 56 - antlr/SchemaLexer.tokens | 24 - antlr/SchemaLexer.ts | 132 --- antlr/SchemaListener.ts | 157 --- antlr/SchemaParser.ts | 1159 -------------------- antlr/SchemaVisitor.ts | 112 -- antlr/YorkieSchema.g4 | 120 +++ antlr/YorkieSchema.interp | 105 ++ antlr/YorkieSchema.tokens | 65 ++ antlr/YorkieSchemaLexer.interp | 125 +++ antlr/YorkieSchemaLexer.tokens | 65 ++ antlr/YorkieSchemaLexer.ts | 262 +++++ antlr/YorkieSchemaListener.ts | 277 +++++ antlr/YorkieSchemaParser.ts | 1860 ++++++++++++++++++++++++++++++++ antlr/YorkieSchemaVisitor.ts | 192 ++++ index.html | 12 +- package-lock.json | 130 +++ package.json | 6 +- src/counter.ts | 9 - src/main.ts | 61 +- src/style.css | 96 -- src/typescript.svg | 1 - src/validator.ts | 148 ++- test/schema.test.ts | 284 ++++- 27 files changed, 3627 insertions(+), 1950 deletions(-) delete mode 100644 antlr/Schema.g4 delete mode 100644 antlr/Schema.interp delete mode 100644 antlr/Schema.tokens delete mode 100644 antlr/SchemaLexer.interp delete mode 100644 antlr/SchemaLexer.tokens delete mode 100644 antlr/SchemaLexer.ts delete mode 100644 antlr/SchemaListener.ts delete mode 100644 antlr/SchemaParser.ts delete mode 100644 antlr/SchemaVisitor.ts create mode 100644 antlr/YorkieSchema.g4 create mode 100644 antlr/YorkieSchema.interp create mode 100644 antlr/YorkieSchema.tokens create mode 100644 antlr/YorkieSchemaLexer.interp create mode 100644 antlr/YorkieSchemaLexer.tokens create mode 100644 antlr/YorkieSchemaLexer.ts create mode 100644 antlr/YorkieSchemaListener.ts create mode 100644 antlr/YorkieSchemaParser.ts create mode 100644 antlr/YorkieSchemaVisitor.ts delete mode 100644 src/counter.ts delete mode 100644 src/style.css delete mode 100644 src/typescript.svg diff --git a/antlr/Schema.g4 b/antlr/Schema.g4 deleted file mode 100644 index f441faf..0000000 --- a/antlr/Schema.g4 +++ /dev/null @@ -1,46 +0,0 @@ -grammar Schema; - -// Entry point of the grammar -start: typeDefinitions EOF; -typeDefinitions - : typeDefinition (WHITESPACE* typeDefinitions)? - ; -typeDefinition - : 'type' IDENTIFIER '{' fieldList '}' - ; -fieldList - : field (WHITESPACE* fieldList)? - ; -field - : IDENTIFIER WHITESPACE* ':' WHITESPACE* fieldType - ; -fieldType - : typeExpression arraySuffix* - ; -typeExpression - : unionType - | simpleType - ; -simpleType - : primitiveType - | IDENTIFIER - ; -arraySuffix - : '[]' - ; -unionType - : '(' WHITESPACE* unionTypeInner WHITESPACE* ')' - | unionTypeInner - ; -unionTypeInner - : simpleType (WHITESPACE* '|' WHITESPACE* simpleType)* - ; -primitiveType - : ('string' | 'number' | 'boolean') - ; -IDENTIFIER - : [a-zA-Z_] [a-zA-Z0-9_]* - ; -WHITESPACE - : [ \t\n\r]+ -> skip - ; diff --git a/antlr/Schema.interp b/antlr/Schema.interp deleted file mode 100644 index a4153e1..0000000 --- a/antlr/Schema.interp +++ /dev/null @@ -1,49 +0,0 @@ -token literal names: -null -'type' -'{' -'}' -':' -'[]' -'(' -')' -'|' -'string' -'number' -'boolean' -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -IDENTIFIER -WHITESPACE - -rule names: -start -typeDefinitions -typeDefinition -fieldList -field -fieldType -typeExpression -simpleType -arraySuffix -unionType -unionTypeInner -primitiveType - - -atn: -[3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 3, 15, 130, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 7, 3, 32, 10, 3, 12, 3, 14, 3, 35, 11, 3, 3, 3, 5, 3, 38, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 7, 5, 48, 10, 5, 12, 5, 14, 5, 51, 11, 5, 3, 5, 5, 5, 54, 10, 5, 3, 6, 3, 6, 7, 6, 58, 10, 6, 12, 6, 14, 6, 61, 11, 6, 3, 6, 3, 6, 7, 6, 65, 10, 6, 12, 6, 14, 6, 68, 11, 6, 3, 6, 3, 6, 3, 7, 3, 7, 7, 7, 74, 10, 7, 12, 7, 14, 7, 77, 11, 7, 3, 8, 3, 8, 5, 8, 81, 10, 8, 3, 9, 3, 9, 5, 9, 85, 10, 9, 3, 10, 3, 10, 3, 11, 3, 11, 7, 11, 91, 10, 11, 12, 11, 14, 11, 94, 11, 11, 3, 11, 3, 11, 7, 11, 98, 10, 11, 12, 11, 14, 11, 101, 11, 11, 3, 11, 3, 11, 3, 11, 5, 11, 106, 10, 11, 3, 12, 3, 12, 7, 12, 110, 10, 12, 12, 12, 14, 12, 113, 11, 12, 3, 12, 3, 12, 7, 12, 117, 10, 12, 12, 12, 14, 12, 120, 11, 12, 3, 12, 7, 12, 123, 10, 12, 12, 12, 14, 12, 126, 11, 12, 3, 13, 3, 13, 3, 13, 2, 2, 2, 14, 2, 2, 4, 2, 6, 2, 8, 2, 10, 2, 12, 2, 14, 2, 16, 2, 18, 2, 20, 2, 22, 2, 24, 2, 2, 3, 3, 2, 11, 13, 2, 132, 2, 26, 3, 2, 2, 2, 4, 29, 3, 2, 2, 2, 6, 39, 3, 2, 2, 2, 8, 45, 3, 2, 2, 2, 10, 55, 3, 2, 2, 2, 12, 71, 3, 2, 2, 2, 14, 80, 3, 2, 2, 2, 16, 84, 3, 2, 2, 2, 18, 86, 3, 2, 2, 2, 20, 105, 3, 2, 2, 2, 22, 107, 3, 2, 2, 2, 24, 127, 3, 2, 2, 2, 26, 27, 5, 4, 3, 2, 27, 28, 7, 2, 2, 3, 28, 3, 3, 2, 2, 2, 29, 37, 5, 6, 4, 2, 30, 32, 7, 15, 2, 2, 31, 30, 3, 2, 2, 2, 32, 35, 3, 2, 2, 2, 33, 31, 3, 2, 2, 2, 33, 34, 3, 2, 2, 2, 34, 36, 3, 2, 2, 2, 35, 33, 3, 2, 2, 2, 36, 38, 5, 4, 3, 2, 37, 33, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 5, 3, 2, 2, 2, 39, 40, 7, 3, 2, 2, 40, 41, 7, 14, 2, 2, 41, 42, 7, 4, 2, 2, 42, 43, 5, 8, 5, 2, 43, 44, 7, 5, 2, 2, 44, 7, 3, 2, 2, 2, 45, 53, 5, 10, 6, 2, 46, 48, 7, 15, 2, 2, 47, 46, 3, 2, 2, 2, 48, 51, 3, 2, 2, 2, 49, 47, 3, 2, 2, 2, 49, 50, 3, 2, 2, 2, 50, 52, 3, 2, 2, 2, 51, 49, 3, 2, 2, 2, 52, 54, 5, 8, 5, 2, 53, 49, 3, 2, 2, 2, 53, 54, 3, 2, 2, 2, 54, 9, 3, 2, 2, 2, 55, 59, 7, 14, 2, 2, 56, 58, 7, 15, 2, 2, 57, 56, 3, 2, 2, 2, 58, 61, 3, 2, 2, 2, 59, 57, 3, 2, 2, 2, 59, 60, 3, 2, 2, 2, 60, 62, 3, 2, 2, 2, 61, 59, 3, 2, 2, 2, 62, 66, 7, 6, 2, 2, 63, 65, 7, 15, 2, 2, 64, 63, 3, 2, 2, 2, 65, 68, 3, 2, 2, 2, 66, 64, 3, 2, 2, 2, 66, 67, 3, 2, 2, 2, 67, 69, 3, 2, 2, 2, 68, 66, 3, 2, 2, 2, 69, 70, 5, 12, 7, 2, 70, 11, 3, 2, 2, 2, 71, 75, 5, 14, 8, 2, 72, 74, 5, 18, 10, 2, 73, 72, 3, 2, 2, 2, 74, 77, 3, 2, 2, 2, 75, 73, 3, 2, 2, 2, 75, 76, 3, 2, 2, 2, 76, 13, 3, 2, 2, 2, 77, 75, 3, 2, 2, 2, 78, 81, 5, 20, 11, 2, 79, 81, 5, 16, 9, 2, 80, 78, 3, 2, 2, 2, 80, 79, 3, 2, 2, 2, 81, 15, 3, 2, 2, 2, 82, 85, 5, 24, 13, 2, 83, 85, 7, 14, 2, 2, 84, 82, 3, 2, 2, 2, 84, 83, 3, 2, 2, 2, 85, 17, 3, 2, 2, 2, 86, 87, 7, 7, 2, 2, 87, 19, 3, 2, 2, 2, 88, 92, 7, 8, 2, 2, 89, 91, 7, 15, 2, 2, 90, 89, 3, 2, 2, 2, 91, 94, 3, 2, 2, 2, 92, 90, 3, 2, 2, 2, 92, 93, 3, 2, 2, 2, 93, 95, 3, 2, 2, 2, 94, 92, 3, 2, 2, 2, 95, 99, 5, 22, 12, 2, 96, 98, 7, 15, 2, 2, 97, 96, 3, 2, 2, 2, 98, 101, 3, 2, 2, 2, 99, 97, 3, 2, 2, 2, 99, 100, 3, 2, 2, 2, 100, 102, 3, 2, 2, 2, 101, 99, 3, 2, 2, 2, 102, 103, 7, 9, 2, 2, 103, 106, 3, 2, 2, 2, 104, 106, 5, 22, 12, 2, 105, 88, 3, 2, 2, 2, 105, 104, 3, 2, 2, 2, 106, 21, 3, 2, 2, 2, 107, 124, 5, 16, 9, 2, 108, 110, 7, 15, 2, 2, 109, 108, 3, 2, 2, 2, 110, 113, 3, 2, 2, 2, 111, 109, 3, 2, 2, 2, 111, 112, 3, 2, 2, 2, 112, 114, 3, 2, 2, 2, 113, 111, 3, 2, 2, 2, 114, 118, 7, 10, 2, 2, 115, 117, 7, 15, 2, 2, 116, 115, 3, 2, 2, 2, 117, 120, 3, 2, 2, 2, 118, 116, 3, 2, 2, 2, 118, 119, 3, 2, 2, 2, 119, 121, 3, 2, 2, 2, 120, 118, 3, 2, 2, 2, 121, 123, 5, 16, 9, 2, 122, 111, 3, 2, 2, 2, 123, 126, 3, 2, 2, 2, 124, 122, 3, 2, 2, 2, 124, 125, 3, 2, 2, 2, 125, 23, 3, 2, 2, 2, 126, 124, 3, 2, 2, 2, 127, 128, 9, 2, 2, 2, 128, 25, 3, 2, 2, 2, 17, 33, 37, 49, 53, 59, 66, 75, 80, 84, 92, 99, 105, 111, 118, 124] \ No newline at end of file diff --git a/antlr/Schema.tokens b/antlr/Schema.tokens deleted file mode 100644 index 2a46a5c..0000000 --- a/antlr/Schema.tokens +++ /dev/null @@ -1,24 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -IDENTIFIER=12 -WHITESPACE=13 -'type'=1 -'{'=2 -'}'=3 -':'=4 -'[]'=5 -'('=6 -')'=7 -'|'=8 -'string'=9 -'number'=10 -'boolean'=11 diff --git a/antlr/SchemaLexer.interp b/antlr/SchemaLexer.interp deleted file mode 100644 index 3031e76..0000000 --- a/antlr/SchemaLexer.interp +++ /dev/null @@ -1,56 +0,0 @@ -token literal names: -null -'type' -'{' -'}' -':' -'[]' -'(' -')' -'|' -'string' -'number' -'boolean' -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -IDENTIFIER -WHITESPACE - -rule names: -T__0 -T__1 -T__2 -T__3 -T__4 -T__5 -T__6 -T__7 -T__8 -T__9 -T__10 -IDENTIFIER -WHITESPACE - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 2, 15, 85, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 7, 13, 74, 10, 13, 12, 13, 14, 13, 77, 11, 13, 3, 14, 6, 14, 80, 10, 14, 13, 14, 14, 14, 81, 3, 14, 3, 14, 2, 2, 2, 15, 3, 2, 3, 5, 2, 4, 7, 2, 5, 9, 2, 6, 11, 2, 7, 13, 2, 8, 15, 2, 9, 17, 2, 10, 19, 2, 11, 21, 2, 12, 23, 2, 13, 25, 2, 14, 27, 2, 15, 3, 2, 5, 5, 2, 67, 92, 97, 97, 99, 124, 6, 2, 50, 59, 67, 92, 97, 97, 99, 124, 5, 2, 11, 12, 15, 15, 34, 34, 2, 86, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 3, 29, 3, 2, 2, 2, 5, 34, 3, 2, 2, 2, 7, 36, 3, 2, 2, 2, 9, 38, 3, 2, 2, 2, 11, 40, 3, 2, 2, 2, 13, 43, 3, 2, 2, 2, 15, 45, 3, 2, 2, 2, 17, 47, 3, 2, 2, 2, 19, 49, 3, 2, 2, 2, 21, 56, 3, 2, 2, 2, 23, 63, 3, 2, 2, 2, 25, 71, 3, 2, 2, 2, 27, 79, 3, 2, 2, 2, 29, 30, 7, 118, 2, 2, 30, 31, 7, 123, 2, 2, 31, 32, 7, 114, 2, 2, 32, 33, 7, 103, 2, 2, 33, 4, 3, 2, 2, 2, 34, 35, 7, 125, 2, 2, 35, 6, 3, 2, 2, 2, 36, 37, 7, 127, 2, 2, 37, 8, 3, 2, 2, 2, 38, 39, 7, 60, 2, 2, 39, 10, 3, 2, 2, 2, 40, 41, 7, 93, 2, 2, 41, 42, 7, 95, 2, 2, 42, 12, 3, 2, 2, 2, 43, 44, 7, 42, 2, 2, 44, 14, 3, 2, 2, 2, 45, 46, 7, 43, 2, 2, 46, 16, 3, 2, 2, 2, 47, 48, 7, 126, 2, 2, 48, 18, 3, 2, 2, 2, 49, 50, 7, 117, 2, 2, 50, 51, 7, 118, 2, 2, 51, 52, 7, 116, 2, 2, 52, 53, 7, 107, 2, 2, 53, 54, 7, 112, 2, 2, 54, 55, 7, 105, 2, 2, 55, 20, 3, 2, 2, 2, 56, 57, 7, 112, 2, 2, 57, 58, 7, 119, 2, 2, 58, 59, 7, 111, 2, 2, 59, 60, 7, 100, 2, 2, 60, 61, 7, 103, 2, 2, 61, 62, 7, 116, 2, 2, 62, 22, 3, 2, 2, 2, 63, 64, 7, 100, 2, 2, 64, 65, 7, 113, 2, 2, 65, 66, 7, 113, 2, 2, 66, 67, 7, 110, 2, 2, 67, 68, 7, 103, 2, 2, 68, 69, 7, 99, 2, 2, 69, 70, 7, 112, 2, 2, 70, 24, 3, 2, 2, 2, 71, 75, 9, 2, 2, 2, 72, 74, 9, 3, 2, 2, 73, 72, 3, 2, 2, 2, 74, 77, 3, 2, 2, 2, 75, 73, 3, 2, 2, 2, 75, 76, 3, 2, 2, 2, 76, 26, 3, 2, 2, 2, 77, 75, 3, 2, 2, 2, 78, 80, 9, 4, 2, 2, 79, 78, 3, 2, 2, 2, 80, 81, 3, 2, 2, 2, 81, 79, 3, 2, 2, 2, 81, 82, 3, 2, 2, 2, 82, 83, 3, 2, 2, 2, 83, 84, 8, 14, 2, 2, 84, 28, 3, 2, 2, 2, 5, 2, 75, 81, 3, 8, 2, 2] \ No newline at end of file diff --git a/antlr/SchemaLexer.tokens b/antlr/SchemaLexer.tokens deleted file mode 100644 index 2a46a5c..0000000 --- a/antlr/SchemaLexer.tokens +++ /dev/null @@ -1,24 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -IDENTIFIER=12 -WHITESPACE=13 -'type'=1 -'{'=2 -'}'=3 -':'=4 -'[]'=5 -'('=6 -')'=7 -'|'=8 -'string'=9 -'number'=10 -'boolean'=11 diff --git a/antlr/SchemaLexer.ts b/antlr/SchemaLexer.ts deleted file mode 100644 index 699dbeb..0000000 --- a/antlr/SchemaLexer.ts +++ /dev/null @@ -1,132 +0,0 @@ -// Generated from antlr/Schema.g4 by ANTLR 4.9.0-SNAPSHOT - - -import { ATN } from "antlr4ts/atn/ATN"; -import { ATNDeserializer } from "antlr4ts/atn/ATNDeserializer"; -import { CharStream } from "antlr4ts/CharStream"; -import { Lexer } from "antlr4ts/Lexer"; -import { LexerATNSimulator } from "antlr4ts/atn/LexerATNSimulator"; -import { NotNull } from "antlr4ts/Decorators"; -import { Override } from "antlr4ts/Decorators"; -import { RuleContext } from "antlr4ts/RuleContext"; -import { Vocabulary } from "antlr4ts/Vocabulary"; -import { VocabularyImpl } from "antlr4ts/VocabularyImpl"; - -import * as Utils from "antlr4ts/misc/Utils"; - - -export class SchemaLexer extends Lexer { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly T__9 = 10; - public static readonly T__10 = 11; - public static readonly IDENTIFIER = 12; - public static readonly WHITESPACE = 13; - - // tslint:disable:no-trailing-whitespace - public static readonly channelNames: string[] = [ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN", - ]; - - // tslint:disable:no-trailing-whitespace - public static readonly modeNames: string[] = [ - "DEFAULT_MODE", - ]; - - public static readonly ruleNames: string[] = [ - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "IDENTIFIER", "WHITESPACE", - ]; - - private static readonly _LITERAL_NAMES: Array = [ - undefined, "'type'", "'{'", "'}'", "':'", "'[]'", "'('", "')'", "'|'", - "'string'", "'number'", "'boolean'", - ]; - private static readonly _SYMBOLIC_NAMES: Array = [ - undefined, undefined, undefined, undefined, undefined, undefined, undefined, - undefined, undefined, undefined, undefined, undefined, "IDENTIFIER", "WHITESPACE", - ]; - public static readonly VOCABULARY: Vocabulary = new VocabularyImpl(SchemaLexer._LITERAL_NAMES, SchemaLexer._SYMBOLIC_NAMES, []); - - // @Override - // @NotNull - public get vocabulary(): Vocabulary { - return SchemaLexer.VOCABULARY; - } - // tslint:enable:no-trailing-whitespace - - - constructor(input: CharStream) { - super(input); - this._interp = new LexerATNSimulator(SchemaLexer._ATN, this); - } - - // @Override - public get grammarFileName(): string { return "Schema.g4"; } - - // @Override - public get ruleNames(): string[] { return SchemaLexer.ruleNames; } - - // @Override - public get serializedATN(): string { return SchemaLexer._serializedATN; } - - // @Override - public get channelNames(): string[] { return SchemaLexer.channelNames; } - - // @Override - public get modeNames(): string[] { return SchemaLexer.modeNames; } - - public static readonly _serializedATN: string = - "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x02\x0FU\b\x01\x04" + - "\x02\t\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06\x04" + - "\x07\t\x07\x04\b\t\b\x04\t\t\t\x04\n\t\n\x04\v\t\v\x04\f\t\f\x04\r\t\r" + - "\x04\x0E\t\x0E\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03\x03\x03\x03" + - "\x03\x04\x03\x04\x03\x05\x03\x05\x03\x06\x03\x06\x03\x06\x03\x07\x03\x07" + - "\x03\b\x03\b\x03\t\x03\t\x03\n\x03\n\x03\n\x03\n\x03\n\x03\n\x03\n\x03" + - "\v\x03\v\x03\v\x03\v\x03\v\x03\v\x03\v\x03\f\x03\f\x03\f\x03\f\x03\f\x03" + - "\f\x03\f\x03\f\x03\r\x03\r\x07\rJ\n\r\f\r\x0E\rM\v\r\x03\x0E\x06\x0EP" + - "\n\x0E\r\x0E\x0E\x0EQ\x03\x0E\x03\x0E\x02\x02\x02\x0F\x03\x02\x03\x05" + - "\x02\x04\x07\x02\x05\t\x02\x06\v\x02\x07\r\x02\b\x0F\x02\t\x11\x02\n\x13" + - "\x02\v\x15\x02\f\x17\x02\r\x19\x02\x0E\x1B\x02\x0F\x03\x02\x05\x05\x02" + - "C\\aac|\x06\x022;C\\aac|\x05\x02\v\f\x0F\x0F\"\"\x02V\x02\x03\x03\x02" + - "\x02\x02\x02\x05\x03\x02\x02\x02\x02\x07\x03\x02\x02\x02\x02\t\x03\x02" + - "\x02\x02\x02\v\x03\x02\x02\x02\x02\r\x03\x02\x02\x02\x02\x0F\x03\x02\x02" + - "\x02\x02\x11\x03\x02\x02\x02\x02\x13\x03\x02\x02\x02\x02\x15\x03\x02\x02" + - "\x02\x02\x17\x03\x02\x02\x02\x02\x19\x03\x02\x02\x02\x02\x1B\x03\x02\x02" + - "\x02\x03\x1D\x03\x02\x02\x02\x05\"\x03\x02\x02\x02\x07$\x03\x02\x02\x02" + - "\t&\x03\x02\x02\x02\v(\x03\x02\x02\x02\r+\x03\x02\x02\x02\x0F-\x03\x02" + - "\x02\x02\x11/\x03\x02\x02\x02\x131\x03\x02\x02\x02\x158\x03\x02\x02\x02" + - "\x17?\x03\x02\x02\x02\x19G\x03\x02\x02\x02\x1BO\x03\x02\x02\x02\x1D\x1E" + - "\x07v\x02\x02\x1E\x1F\x07{\x02\x02\x1F \x07r\x02\x02 !\x07g\x02\x02!\x04" + - "\x03\x02\x02\x02\"#\x07}\x02\x02#\x06\x03\x02\x02\x02$%\x07\x7F\x02\x02" + - "%\b\x03\x02\x02\x02&\'\x07<\x02\x02\'\n\x03\x02\x02\x02()\x07]\x02\x02" + - ")*\x07_\x02\x02*\f\x03\x02\x02\x02+,\x07*\x02\x02,\x0E\x03\x02\x02\x02" + - "-.\x07+\x02\x02.\x10\x03\x02\x02\x02/0\x07~\x02\x020\x12\x03\x02\x02\x02" + - "12\x07u\x02\x0223\x07v\x02\x0234\x07t\x02\x0245\x07k\x02\x0256\x07p\x02" + - "\x0267\x07i\x02\x027\x14\x03\x02\x02\x0289\x07p\x02\x029:\x07w\x02\x02" + - ":;\x07o\x02\x02;<\x07d\x02\x02<=\x07g\x02\x02=>\x07t\x02\x02>\x16\x03" + - "\x02\x02\x02?@\x07d\x02\x02@A\x07q\x02\x02AB\x07q\x02\x02BC\x07n\x02\x02" + - "CD\x07g\x02\x02DE\x07c\x02\x02EF\x07p\x02\x02F\x18\x03\x02\x02\x02GK\t" + - "\x02\x02\x02HJ\t\x03\x02\x02IH\x03\x02\x02\x02JM\x03\x02\x02\x02KI\x03" + - "\x02\x02\x02KL\x03\x02\x02\x02L\x1A\x03\x02\x02\x02MK\x03\x02\x02\x02" + - "NP\t\x04\x02\x02ON\x03\x02\x02\x02PQ\x03\x02\x02\x02QO\x03\x02\x02\x02" + - "QR\x03\x02\x02\x02RS\x03\x02\x02\x02ST\b\x0E\x02\x02T\x1C\x03\x02\x02" + - "\x02\x05\x02KQ\x03\b\x02\x02"; - public static __ATN: ATN; - public static get _ATN(): ATN { - if (!SchemaLexer.__ATN) { - SchemaLexer.__ATN = new ATNDeserializer().deserialize(Utils.toCharArray(SchemaLexer._serializedATN)); - } - - return SchemaLexer.__ATN; - } - -} - diff --git a/antlr/SchemaListener.ts b/antlr/SchemaListener.ts deleted file mode 100644 index b3c9710..0000000 --- a/antlr/SchemaListener.ts +++ /dev/null @@ -1,157 +0,0 @@ -// Generated from antlr/Schema.g4 by ANTLR 4.9.0-SNAPSHOT - - -import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; - -import { StartContext } from "./SchemaParser"; -import { TypeDefinitionsContext } from "./SchemaParser"; -import { TypeDefinitionContext } from "./SchemaParser"; -import { FieldListContext } from "./SchemaParser"; -import { FieldContext } from "./SchemaParser"; -import { FieldTypeContext } from "./SchemaParser"; -import { TypeExpressionContext } from "./SchemaParser"; -import { SimpleTypeContext } from "./SchemaParser"; -import { ArraySuffixContext } from "./SchemaParser"; -import { UnionTypeContext } from "./SchemaParser"; -import { UnionTypeInnerContext } from "./SchemaParser"; -import { PrimitiveTypeContext } from "./SchemaParser"; - - -/** - * This interface defines a complete listener for a parse tree produced by - * `SchemaParser`. - */ -export interface SchemaListener extends ParseTreeListener { - /** - * Enter a parse tree produced by `SchemaParser.start`. - * @param ctx the parse tree - */ - enterStart?: (ctx: StartContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.start`. - * @param ctx the parse tree - */ - exitStart?: (ctx: StartContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.typeDefinitions`. - * @param ctx the parse tree - */ - enterTypeDefinitions?: (ctx: TypeDefinitionsContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.typeDefinitions`. - * @param ctx the parse tree - */ - exitTypeDefinitions?: (ctx: TypeDefinitionsContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.typeDefinition`. - * @param ctx the parse tree - */ - enterTypeDefinition?: (ctx: TypeDefinitionContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.typeDefinition`. - * @param ctx the parse tree - */ - exitTypeDefinition?: (ctx: TypeDefinitionContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.fieldList`. - * @param ctx the parse tree - */ - enterFieldList?: (ctx: FieldListContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.fieldList`. - * @param ctx the parse tree - */ - exitFieldList?: (ctx: FieldListContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.field`. - * @param ctx the parse tree - */ - enterField?: (ctx: FieldContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.field`. - * @param ctx the parse tree - */ - exitField?: (ctx: FieldContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.fieldType`. - * @param ctx the parse tree - */ - enterFieldType?: (ctx: FieldTypeContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.fieldType`. - * @param ctx the parse tree - */ - exitFieldType?: (ctx: FieldTypeContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.typeExpression`. - * @param ctx the parse tree - */ - enterTypeExpression?: (ctx: TypeExpressionContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.typeExpression`. - * @param ctx the parse tree - */ - exitTypeExpression?: (ctx: TypeExpressionContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.simpleType`. - * @param ctx the parse tree - */ - enterSimpleType?: (ctx: SimpleTypeContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.simpleType`. - * @param ctx the parse tree - */ - exitSimpleType?: (ctx: SimpleTypeContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.arraySuffix`. - * @param ctx the parse tree - */ - enterArraySuffix?: (ctx: ArraySuffixContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.arraySuffix`. - * @param ctx the parse tree - */ - exitArraySuffix?: (ctx: ArraySuffixContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.unionType`. - * @param ctx the parse tree - */ - enterUnionType?: (ctx: UnionTypeContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.unionType`. - * @param ctx the parse tree - */ - exitUnionType?: (ctx: UnionTypeContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.unionTypeInner`. - * @param ctx the parse tree - */ - enterUnionTypeInner?: (ctx: UnionTypeInnerContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.unionTypeInner`. - * @param ctx the parse tree - */ - exitUnionTypeInner?: (ctx: UnionTypeInnerContext) => void; - - /** - * Enter a parse tree produced by `SchemaParser.primitiveType`. - * @param ctx the parse tree - */ - enterPrimitiveType?: (ctx: PrimitiveTypeContext) => void; - /** - * Exit a parse tree produced by `SchemaParser.primitiveType`. - * @param ctx the parse tree - */ - exitPrimitiveType?: (ctx: PrimitiveTypeContext) => void; -} - diff --git a/antlr/SchemaParser.ts b/antlr/SchemaParser.ts deleted file mode 100644 index 742c3f3..0000000 --- a/antlr/SchemaParser.ts +++ /dev/null @@ -1,1159 +0,0 @@ -// Generated from antlr/Schema.g4 by ANTLR 4.9.0-SNAPSHOT - - -import { ATN } from "antlr4ts/atn/ATN"; -import { ATNDeserializer } from "antlr4ts/atn/ATNDeserializer"; -import { FailedPredicateException } from "antlr4ts/FailedPredicateException"; -import { NotNull } from "antlr4ts/Decorators"; -import { NoViableAltException } from "antlr4ts/NoViableAltException"; -import { Override } from "antlr4ts/Decorators"; -import { Parser } from "antlr4ts/Parser"; -import { ParserRuleContext } from "antlr4ts/ParserRuleContext"; -import { ParserATNSimulator } from "antlr4ts/atn/ParserATNSimulator"; -import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; -import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; -import { RecognitionException } from "antlr4ts/RecognitionException"; -import { RuleContext } from "antlr4ts/RuleContext"; -//import { RuleVersion } from "antlr4ts/RuleVersion"; -import { TerminalNode } from "antlr4ts/tree/TerminalNode"; -import { Token } from "antlr4ts/Token"; -import { TokenStream } from "antlr4ts/TokenStream"; -import { Vocabulary } from "antlr4ts/Vocabulary"; -import { VocabularyImpl } from "antlr4ts/VocabularyImpl"; - -import * as Utils from "antlr4ts/misc/Utils"; - -import { SchemaListener } from "./SchemaListener"; -import { SchemaVisitor } from "./SchemaVisitor"; - - -export class SchemaParser extends Parser { - public static readonly T__0 = 1; - public static readonly T__1 = 2; - public static readonly T__2 = 3; - public static readonly T__3 = 4; - public static readonly T__4 = 5; - public static readonly T__5 = 6; - public static readonly T__6 = 7; - public static readonly T__7 = 8; - public static readonly T__8 = 9; - public static readonly T__9 = 10; - public static readonly T__10 = 11; - public static readonly IDENTIFIER = 12; - public static readonly WHITESPACE = 13; - public static readonly RULE_start = 0; - public static readonly RULE_typeDefinitions = 1; - public static readonly RULE_typeDefinition = 2; - public static readonly RULE_fieldList = 3; - public static readonly RULE_field = 4; - public static readonly RULE_fieldType = 5; - public static readonly RULE_typeExpression = 6; - public static readonly RULE_simpleType = 7; - public static readonly RULE_arraySuffix = 8; - public static readonly RULE_unionType = 9; - public static readonly RULE_unionTypeInner = 10; - public static readonly RULE_primitiveType = 11; - // tslint:disable:no-trailing-whitespace - public static readonly ruleNames: string[] = [ - "start", "typeDefinitions", "typeDefinition", "fieldList", "field", "fieldType", - "typeExpression", "simpleType", "arraySuffix", "unionType", "unionTypeInner", - "primitiveType", - ]; - - private static readonly _LITERAL_NAMES: Array = [ - undefined, "'type'", "'{'", "'}'", "':'", "'[]'", "'('", "')'", "'|'", - "'string'", "'number'", "'boolean'", - ]; - private static readonly _SYMBOLIC_NAMES: Array = [ - undefined, undefined, undefined, undefined, undefined, undefined, undefined, - undefined, undefined, undefined, undefined, undefined, "IDENTIFIER", "WHITESPACE", - ]; - public static readonly VOCABULARY: Vocabulary = new VocabularyImpl(SchemaParser._LITERAL_NAMES, SchemaParser._SYMBOLIC_NAMES, []); - - // @Override - // @NotNull - public get vocabulary(): Vocabulary { - return SchemaParser.VOCABULARY; - } - // tslint:enable:no-trailing-whitespace - - // @Override - public get grammarFileName(): string { return "Schema.g4"; } - - // @Override - public get ruleNames(): string[] { return SchemaParser.ruleNames; } - - // @Override - public get serializedATN(): string { return SchemaParser._serializedATN; } - - protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException { - return new FailedPredicateException(this, predicate, message); - } - - constructor(input: TokenStream) { - super(input); - this._interp = new ParserATNSimulator(SchemaParser._ATN, this); - } - // @RuleVersion(0) - public start(): StartContext { - let _localctx: StartContext = new StartContext(this._ctx, this.state); - this.enterRule(_localctx, 0, SchemaParser.RULE_start); - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 24; - this.typeDefinitions(); - this.state = 25; - this.match(SchemaParser.EOF); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public typeDefinitions(): TypeDefinitionsContext { - let _localctx: TypeDefinitionsContext = new TypeDefinitionsContext(this._ctx, this.state); - this.enterRule(_localctx, 2, SchemaParser.RULE_typeDefinitions); - let _la: number; - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 27; - this.typeDefinition(); - this.state = 35; - this._errHandler.sync(this); - _la = this._input.LA(1); - if (_la === SchemaParser.T__0 || _la === SchemaParser.WHITESPACE) { - { - this.state = 31; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 28; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 33; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 34; - this.typeDefinitions(); - } - } - - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public typeDefinition(): TypeDefinitionContext { - let _localctx: TypeDefinitionContext = new TypeDefinitionContext(this._ctx, this.state); - this.enterRule(_localctx, 4, SchemaParser.RULE_typeDefinition); - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 37; - this.match(SchemaParser.T__0); - this.state = 38; - this.match(SchemaParser.IDENTIFIER); - this.state = 39; - this.match(SchemaParser.T__1); - this.state = 40; - this.fieldList(); - this.state = 41; - this.match(SchemaParser.T__2); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public fieldList(): FieldListContext { - let _localctx: FieldListContext = new FieldListContext(this._ctx, this.state); - this.enterRule(_localctx, 6, SchemaParser.RULE_fieldList); - let _la: number; - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 43; - this.field(); - this.state = 51; - this._errHandler.sync(this); - _la = this._input.LA(1); - if (_la === SchemaParser.IDENTIFIER || _la === SchemaParser.WHITESPACE) { - { - this.state = 47; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 44; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 49; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 50; - this.fieldList(); - } - } - - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public field(): FieldContext { - let _localctx: FieldContext = new FieldContext(this._ctx, this.state); - this.enterRule(_localctx, 8, SchemaParser.RULE_field); - let _la: number; - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 53; - this.match(SchemaParser.IDENTIFIER); - this.state = 57; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 54; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 59; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 60; - this.match(SchemaParser.T__3); - this.state = 64; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 61; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 66; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 67; - this.fieldType(); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public fieldType(): FieldTypeContext { - let _localctx: FieldTypeContext = new FieldTypeContext(this._ctx, this.state); - this.enterRule(_localctx, 10, SchemaParser.RULE_fieldType); - let _la: number; - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 69; - this.typeExpression(); - this.state = 73; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.T__4) { - { - { - this.state = 70; - this.arraySuffix(); - } - } - this.state = 75; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public typeExpression(): TypeExpressionContext { - let _localctx: TypeExpressionContext = new TypeExpressionContext(this._ctx, this.state); - this.enterRule(_localctx, 12, SchemaParser.RULE_typeExpression); - try { - this.state = 78; - this._errHandler.sync(this); - switch ( this.interpreter.adaptivePredict(this._input, 7, this._ctx) ) { - case 1: - this.enterOuterAlt(_localctx, 1); - { - this.state = 76; - this.unionType(); - } - break; - - case 2: - this.enterOuterAlt(_localctx, 2); - { - this.state = 77; - this.simpleType(); - } - break; - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public simpleType(): SimpleTypeContext { - let _localctx: SimpleTypeContext = new SimpleTypeContext(this._ctx, this.state); - this.enterRule(_localctx, 14, SchemaParser.RULE_simpleType); - try { - this.state = 82; - this._errHandler.sync(this); - switch (this._input.LA(1)) { - case SchemaParser.T__8: - case SchemaParser.T__9: - case SchemaParser.T__10: - this.enterOuterAlt(_localctx, 1); - { - this.state = 80; - this.primitiveType(); - } - break; - case SchemaParser.IDENTIFIER: - this.enterOuterAlt(_localctx, 2); - { - this.state = 81; - this.match(SchemaParser.IDENTIFIER); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public arraySuffix(): ArraySuffixContext { - let _localctx: ArraySuffixContext = new ArraySuffixContext(this._ctx, this.state); - this.enterRule(_localctx, 16, SchemaParser.RULE_arraySuffix); - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 84; - this.match(SchemaParser.T__4); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public unionType(): UnionTypeContext { - let _localctx: UnionTypeContext = new UnionTypeContext(this._ctx, this.state); - this.enterRule(_localctx, 18, SchemaParser.RULE_unionType); - let _la: number; - try { - this.state = 103; - this._errHandler.sync(this); - switch (this._input.LA(1)) { - case SchemaParser.T__5: - this.enterOuterAlt(_localctx, 1); - { - this.state = 86; - this.match(SchemaParser.T__5); - this.state = 90; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 87; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 92; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 93; - this.unionTypeInner(); - this.state = 97; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 94; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 99; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 100; - this.match(SchemaParser.T__6); - } - break; - case SchemaParser.T__8: - case SchemaParser.T__9: - case SchemaParser.T__10: - case SchemaParser.IDENTIFIER: - this.enterOuterAlt(_localctx, 2); - { - this.state = 102; - this.unionTypeInner(); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public unionTypeInner(): UnionTypeInnerContext { - let _localctx: UnionTypeInnerContext = new UnionTypeInnerContext(this._ctx, this.state); - this.enterRule(_localctx, 20, SchemaParser.RULE_unionTypeInner); - let _la: number; - try { - let _alt: number; - this.enterOuterAlt(_localctx, 1); - { - this.state = 105; - this.simpleType(); - this.state = 122; - this._errHandler.sync(this); - _alt = this.interpreter.adaptivePredict(this._input, 14, this._ctx); - while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { - if (_alt === 1) { - { - { - this.state = 109; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 106; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 111; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 112; - this.match(SchemaParser.T__7); - this.state = 116; - this._errHandler.sync(this); - _la = this._input.LA(1); - while (_la === SchemaParser.WHITESPACE) { - { - { - this.state = 113; - this.match(SchemaParser.WHITESPACE); - } - } - this.state = 118; - this._errHandler.sync(this); - _la = this._input.LA(1); - } - this.state = 119; - this.simpleType(); - } - } - } - this.state = 124; - this._errHandler.sync(this); - _alt = this.interpreter.adaptivePredict(this._input, 14, this._ctx); - } - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - // @RuleVersion(0) - public primitiveType(): PrimitiveTypeContext { - let _localctx: PrimitiveTypeContext = new PrimitiveTypeContext(this._ctx, this.state); - this.enterRule(_localctx, 22, SchemaParser.RULE_primitiveType); - let _la: number; - try { - this.enterOuterAlt(_localctx, 1); - { - this.state = 125; - _la = this._input.LA(1); - if (!((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << SchemaParser.T__8) | (1 << SchemaParser.T__9) | (1 << SchemaParser.T__10))) !== 0))) { - this._errHandler.recoverInline(this); - } else { - if (this._input.LA(1) === Token.EOF) { - this.matchedEOF = true; - } - - this._errHandler.reportMatch(this); - this.consume(); - } - } - } - catch (re) { - if (re instanceof RecognitionException) { - _localctx.exception = re; - this._errHandler.reportError(this, re); - this._errHandler.recover(this, re); - } else { - throw re; - } - } - finally { - this.exitRule(); - } - return _localctx; - } - - public static readonly _serializedATN: string = - "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x03\x0F\x82\x04\x02" + - "\t\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06\x04\x07" + - "\t\x07\x04\b\t\b\x04\t\t\t\x04\n\t\n\x04\v\t\v\x04\f\t\f\x04\r\t\r\x03" + - "\x02\x03\x02\x03\x02\x03\x03\x03\x03\x07\x03 \n\x03\f\x03\x0E\x03#\v\x03" + - "\x03\x03\x05\x03&\n\x03\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04\x03\x04" + - "\x03\x05\x03\x05\x07\x050\n\x05\f\x05\x0E\x053\v\x05\x03\x05\x05\x056" + - "\n\x05\x03\x06\x03\x06\x07\x06:\n\x06\f\x06\x0E\x06=\v\x06\x03\x06\x03" + - "\x06\x07\x06A\n\x06\f\x06\x0E\x06D\v\x06\x03\x06\x03\x06\x03\x07\x03\x07" + - "\x07\x07J\n\x07\f\x07\x0E\x07M\v\x07\x03\b\x03\b\x05\bQ\n\b\x03\t\x03" + - "\t\x05\tU\n\t\x03\n\x03\n\x03\v\x03\v\x07\v[\n\v\f\v\x0E\v^\v\v\x03\v" + - "\x03\v\x07\vb\n\v\f\v\x0E\ve\v\v\x03\v\x03\v\x03\v\x05\vj\n\v\x03\f\x03" + - "\f\x07\fn\n\f\f\f\x0E\fq\v\f\x03\f\x03\f\x07\fu\n\f\f\f\x0E\fx\v\f\x03" + - "\f\x07\f{\n\f\f\f\x0E\f~\v\f\x03\r\x03\r\x03\r\x02\x02\x02\x0E\x02\x02" + - "\x04\x02\x06\x02\b\x02\n\x02\f\x02\x0E\x02\x10\x02\x12\x02\x14\x02\x16" + - "\x02\x18\x02\x02\x03\x03\x02\v\r\x02\x84\x02\x1A\x03\x02\x02\x02\x04\x1D" + - "\x03\x02\x02\x02\x06\'\x03\x02\x02\x02\b-\x03\x02\x02\x02\n7\x03\x02\x02" + - "\x02\fG\x03\x02\x02\x02\x0EP\x03\x02\x02\x02\x10T\x03\x02\x02\x02\x12" + - "V\x03\x02\x02\x02\x14i\x03\x02\x02\x02\x16k\x03\x02\x02\x02\x18\x7F\x03" + - "\x02\x02\x02\x1A\x1B\x05\x04\x03\x02\x1B\x1C\x07\x02\x02\x03\x1C\x03\x03" + - "\x02\x02\x02\x1D%\x05\x06\x04\x02\x1E \x07\x0F\x02\x02\x1F\x1E\x03\x02" + - "\x02\x02 #\x03\x02\x02\x02!\x1F\x03\x02\x02\x02!\"\x03\x02\x02\x02\"$" + - "\x03\x02\x02\x02#!\x03\x02\x02\x02$&\x05\x04\x03\x02%!\x03\x02\x02\x02" + - "%&\x03\x02\x02\x02&\x05\x03\x02\x02\x02\'(\x07\x03\x02\x02()\x07\x0E\x02" + - "\x02)*\x07\x04\x02\x02*+\x05\b\x05\x02+,\x07\x05\x02\x02,\x07\x03\x02" + - "\x02\x02-5\x05\n\x06\x02.0\x07\x0F\x02\x02/.\x03\x02\x02\x0203\x03\x02" + - "\x02\x021/\x03\x02\x02\x0212\x03\x02\x02\x0224\x03\x02\x02\x0231\x03\x02" + - "\x02\x0246\x05\b\x05\x0251\x03\x02\x02\x0256\x03\x02\x02\x026\t\x03\x02" + - "\x02\x027;\x07\x0E\x02\x028:\x07\x0F\x02\x0298\x03\x02\x02\x02:=\x03\x02" + - "\x02\x02;9\x03\x02\x02\x02;<\x03\x02\x02\x02<>\x03\x02\x02\x02=;\x03\x02" + - "\x02\x02>B\x07\x06\x02\x02?A\x07\x0F\x02\x02@?\x03\x02\x02\x02AD\x03\x02" + - "\x02\x02B@\x03\x02\x02\x02BC\x03\x02\x02\x02CE\x03\x02\x02\x02DB\x03\x02" + - "\x02\x02EF\x05\f\x07\x02F\v\x03\x02\x02\x02GK\x05\x0E\b\x02HJ\x05\x12" + - "\n\x02IH\x03\x02\x02\x02JM\x03\x02\x02\x02KI\x03\x02\x02\x02KL\x03\x02" + - "\x02\x02L\r\x03\x02\x02\x02MK\x03\x02\x02\x02NQ\x05\x14\v\x02OQ\x05\x10" + - "\t\x02PN\x03\x02\x02\x02PO\x03\x02\x02\x02Q\x0F\x03\x02\x02\x02RU\x05" + - "\x18\r\x02SU\x07\x0E\x02\x02TR\x03\x02\x02\x02TS\x03\x02\x02\x02U\x11" + - "\x03\x02\x02\x02VW\x07\x07\x02\x02W\x13\x03\x02\x02\x02X\\\x07\b\x02\x02" + - "Y[\x07\x0F\x02\x02ZY\x03\x02\x02\x02[^\x03\x02\x02\x02\\Z\x03\x02\x02" + - "\x02\\]\x03\x02\x02\x02]_\x03\x02\x02\x02^\\\x03\x02\x02\x02_c\x05\x16" + - "\f\x02`b\x07\x0F\x02\x02a`\x03\x02\x02\x02be\x03\x02\x02\x02ca\x03\x02" + - "\x02\x02cd\x03\x02\x02\x02df\x03\x02\x02\x02ec\x03\x02\x02\x02fg\x07\t" + - "\x02\x02gj\x03\x02\x02\x02hj\x05\x16\f\x02iX\x03\x02\x02\x02ih\x03\x02" + - "\x02\x02j\x15\x03\x02\x02\x02k|\x05\x10\t\x02ln\x07\x0F\x02\x02ml\x03" + - "\x02\x02\x02nq\x03\x02\x02\x02om\x03\x02\x02\x02op\x03\x02\x02\x02pr\x03" + - "\x02\x02\x02qo\x03\x02\x02\x02rv\x07\n\x02\x02su\x07\x0F\x02\x02ts\x03" + - "\x02\x02\x02ux\x03\x02\x02\x02vt\x03\x02\x02\x02vw\x03\x02\x02\x02wy\x03" + - "\x02\x02\x02xv\x03\x02\x02\x02y{\x05\x10\t\x02zo\x03\x02\x02\x02{~\x03" + - "\x02\x02\x02|z\x03\x02\x02\x02|}\x03\x02\x02\x02}\x17\x03\x02\x02\x02" + - "~|\x03\x02\x02\x02\x7F\x80\t\x02\x02\x02\x80\x19\x03\x02\x02\x02\x11!" + - "%15;BKPT\\ciov|"; - public static __ATN: ATN; - public static get _ATN(): ATN { - if (!SchemaParser.__ATN) { - SchemaParser.__ATN = new ATNDeserializer().deserialize(Utils.toCharArray(SchemaParser._serializedATN)); - } - - return SchemaParser.__ATN; - } - -} - -export class StartContext extends ParserRuleContext { - public typeDefinitions(): TypeDefinitionsContext { - return this.getRuleContext(0, TypeDefinitionsContext); - } - public EOF(): TerminalNode { return this.getToken(SchemaParser.EOF, 0); } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_start; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterStart) { - listener.enterStart(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitStart) { - listener.exitStart(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitStart) { - return visitor.visitStart(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class TypeDefinitionsContext extends ParserRuleContext { - public typeDefinition(): TypeDefinitionContext { - return this.getRuleContext(0, TypeDefinitionContext); - } - public typeDefinitions(): TypeDefinitionsContext | undefined { - return this.tryGetRuleContext(0, TypeDefinitionsContext); - } - public WHITESPACE(): TerminalNode[]; - public WHITESPACE(i: number): TerminalNode; - public WHITESPACE(i?: number): TerminalNode | TerminalNode[] { - if (i === undefined) { - return this.getTokens(SchemaParser.WHITESPACE); - } else { - return this.getToken(SchemaParser.WHITESPACE, i); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_typeDefinitions; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterTypeDefinitions) { - listener.enterTypeDefinitions(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitTypeDefinitions) { - listener.exitTypeDefinitions(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitTypeDefinitions) { - return visitor.visitTypeDefinitions(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class TypeDefinitionContext extends ParserRuleContext { - public IDENTIFIER(): TerminalNode { return this.getToken(SchemaParser.IDENTIFIER, 0); } - public fieldList(): FieldListContext { - return this.getRuleContext(0, FieldListContext); - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_typeDefinition; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterTypeDefinition) { - listener.enterTypeDefinition(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitTypeDefinition) { - listener.exitTypeDefinition(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitTypeDefinition) { - return visitor.visitTypeDefinition(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class FieldListContext extends ParserRuleContext { - public field(): FieldContext { - return this.getRuleContext(0, FieldContext); - } - public fieldList(): FieldListContext | undefined { - return this.tryGetRuleContext(0, FieldListContext); - } - public WHITESPACE(): TerminalNode[]; - public WHITESPACE(i: number): TerminalNode; - public WHITESPACE(i?: number): TerminalNode | TerminalNode[] { - if (i === undefined) { - return this.getTokens(SchemaParser.WHITESPACE); - } else { - return this.getToken(SchemaParser.WHITESPACE, i); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_fieldList; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterFieldList) { - listener.enterFieldList(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitFieldList) { - listener.exitFieldList(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitFieldList) { - return visitor.visitFieldList(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class FieldContext extends ParserRuleContext { - public IDENTIFIER(): TerminalNode { return this.getToken(SchemaParser.IDENTIFIER, 0); } - public fieldType(): FieldTypeContext { - return this.getRuleContext(0, FieldTypeContext); - } - public WHITESPACE(): TerminalNode[]; - public WHITESPACE(i: number): TerminalNode; - public WHITESPACE(i?: number): TerminalNode | TerminalNode[] { - if (i === undefined) { - return this.getTokens(SchemaParser.WHITESPACE); - } else { - return this.getToken(SchemaParser.WHITESPACE, i); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_field; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterField) { - listener.enterField(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitField) { - listener.exitField(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitField) { - return visitor.visitField(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class FieldTypeContext extends ParserRuleContext { - public typeExpression(): TypeExpressionContext { - return this.getRuleContext(0, TypeExpressionContext); - } - public arraySuffix(): ArraySuffixContext[]; - public arraySuffix(i: number): ArraySuffixContext; - public arraySuffix(i?: number): ArraySuffixContext | ArraySuffixContext[] { - if (i === undefined) { - return this.getRuleContexts(ArraySuffixContext); - } else { - return this.getRuleContext(i, ArraySuffixContext); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_fieldType; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterFieldType) { - listener.enterFieldType(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitFieldType) { - listener.exitFieldType(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitFieldType) { - return visitor.visitFieldType(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class TypeExpressionContext extends ParserRuleContext { - public unionType(): UnionTypeContext | undefined { - return this.tryGetRuleContext(0, UnionTypeContext); - } - public simpleType(): SimpleTypeContext | undefined { - return this.tryGetRuleContext(0, SimpleTypeContext); - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_typeExpression; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterTypeExpression) { - listener.enterTypeExpression(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitTypeExpression) { - listener.exitTypeExpression(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitTypeExpression) { - return visitor.visitTypeExpression(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class SimpleTypeContext extends ParserRuleContext { - public primitiveType(): PrimitiveTypeContext | undefined { - return this.tryGetRuleContext(0, PrimitiveTypeContext); - } - public IDENTIFIER(): TerminalNode | undefined { return this.tryGetToken(SchemaParser.IDENTIFIER, 0); } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_simpleType; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterSimpleType) { - listener.enterSimpleType(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitSimpleType) { - listener.exitSimpleType(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitSimpleType) { - return visitor.visitSimpleType(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class ArraySuffixContext extends ParserRuleContext { - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_arraySuffix; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterArraySuffix) { - listener.enterArraySuffix(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitArraySuffix) { - listener.exitArraySuffix(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitArraySuffix) { - return visitor.visitArraySuffix(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class UnionTypeContext extends ParserRuleContext { - public unionTypeInner(): UnionTypeInnerContext { - return this.getRuleContext(0, UnionTypeInnerContext); - } - public WHITESPACE(): TerminalNode[]; - public WHITESPACE(i: number): TerminalNode; - public WHITESPACE(i?: number): TerminalNode | TerminalNode[] { - if (i === undefined) { - return this.getTokens(SchemaParser.WHITESPACE); - } else { - return this.getToken(SchemaParser.WHITESPACE, i); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_unionType; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterUnionType) { - listener.enterUnionType(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitUnionType) { - listener.exitUnionType(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitUnionType) { - return visitor.visitUnionType(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class UnionTypeInnerContext extends ParserRuleContext { - public simpleType(): SimpleTypeContext[]; - public simpleType(i: number): SimpleTypeContext; - public simpleType(i?: number): SimpleTypeContext | SimpleTypeContext[] { - if (i === undefined) { - return this.getRuleContexts(SimpleTypeContext); - } else { - return this.getRuleContext(i, SimpleTypeContext); - } - } - public WHITESPACE(): TerminalNode[]; - public WHITESPACE(i: number): TerminalNode; - public WHITESPACE(i?: number): TerminalNode | TerminalNode[] { - if (i === undefined) { - return this.getTokens(SchemaParser.WHITESPACE); - } else { - return this.getToken(SchemaParser.WHITESPACE, i); - } - } - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_unionTypeInner; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterUnionTypeInner) { - listener.enterUnionTypeInner(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitUnionTypeInner) { - listener.exitUnionTypeInner(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitUnionTypeInner) { - return visitor.visitUnionTypeInner(this); - } else { - return visitor.visitChildren(this); - } - } -} - - -export class PrimitiveTypeContext extends ParserRuleContext { - constructor(parent: ParserRuleContext | undefined, invokingState: number) { - super(parent, invokingState); - } - // @Override - public get ruleIndex(): number { return SchemaParser.RULE_primitiveType; } - // @Override - public enterRule(listener: SchemaListener): void { - if (listener.enterPrimitiveType) { - listener.enterPrimitiveType(this); - } - } - // @Override - public exitRule(listener: SchemaListener): void { - if (listener.exitPrimitiveType) { - listener.exitPrimitiveType(this); - } - } - // @Override - public accept(visitor: SchemaVisitor): Result { - if (visitor.visitPrimitiveType) { - return visitor.visitPrimitiveType(this); - } else { - return visitor.visitChildren(this); - } - } -} - - diff --git a/antlr/SchemaVisitor.ts b/antlr/SchemaVisitor.ts deleted file mode 100644 index b8765e2..0000000 --- a/antlr/SchemaVisitor.ts +++ /dev/null @@ -1,112 +0,0 @@ -// Generated from antlr/Schema.g4 by ANTLR 4.9.0-SNAPSHOT - - -import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; - -import { StartContext } from "./SchemaParser"; -import { TypeDefinitionsContext } from "./SchemaParser"; -import { TypeDefinitionContext } from "./SchemaParser"; -import { FieldListContext } from "./SchemaParser"; -import { FieldContext } from "./SchemaParser"; -import { FieldTypeContext } from "./SchemaParser"; -import { TypeExpressionContext } from "./SchemaParser"; -import { SimpleTypeContext } from "./SchemaParser"; -import { ArraySuffixContext } from "./SchemaParser"; -import { UnionTypeContext } from "./SchemaParser"; -import { UnionTypeInnerContext } from "./SchemaParser"; -import { PrimitiveTypeContext } from "./SchemaParser"; - - -/** - * This interface defines a complete generic visitor for a parse tree produced - * by `SchemaParser`. - * - * @param The return type of the visit operation. Use `void` for - * operations with no return type. - */ -export interface SchemaVisitor extends ParseTreeVisitor { - /** - * Visit a parse tree produced by `SchemaParser.start`. - * @param ctx the parse tree - * @return the visitor result - */ - visitStart?: (ctx: StartContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.typeDefinitions`. - * @param ctx the parse tree - * @return the visitor result - */ - visitTypeDefinitions?: (ctx: TypeDefinitionsContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.typeDefinition`. - * @param ctx the parse tree - * @return the visitor result - */ - visitTypeDefinition?: (ctx: TypeDefinitionContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.fieldList`. - * @param ctx the parse tree - * @return the visitor result - */ - visitFieldList?: (ctx: FieldListContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.field`. - * @param ctx the parse tree - * @return the visitor result - */ - visitField?: (ctx: FieldContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.fieldType`. - * @param ctx the parse tree - * @return the visitor result - */ - visitFieldType?: (ctx: FieldTypeContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.typeExpression`. - * @param ctx the parse tree - * @return the visitor result - */ - visitTypeExpression?: (ctx: TypeExpressionContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.simpleType`. - * @param ctx the parse tree - * @return the visitor result - */ - visitSimpleType?: (ctx: SimpleTypeContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.arraySuffix`. - * @param ctx the parse tree - * @return the visitor result - */ - visitArraySuffix?: (ctx: ArraySuffixContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.unionType`. - * @param ctx the parse tree - * @return the visitor result - */ - visitUnionType?: (ctx: UnionTypeContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.unionTypeInner`. - * @param ctx the parse tree - * @return the visitor result - */ - visitUnionTypeInner?: (ctx: UnionTypeInnerContext) => Result; - - /** - * Visit a parse tree produced by `SchemaParser.primitiveType`. - * @param ctx the parse tree - * @return the visitor result - */ - visitPrimitiveType?: (ctx: PrimitiveTypeContext) => Result; -} - diff --git a/antlr/YorkieSchema.g4 b/antlr/YorkieSchema.g4 new file mode 100644 index 0000000..b6950cf --- /dev/null +++ b/antlr/YorkieSchema.g4 @@ -0,0 +1,120 @@ +grammar YorkieSchema; + +// Top-level structure +document: declaration* EOF; + +declaration + : typeAliasDeclaration + | variableDeclaration + ; + +typeAliasDeclaration + : 'type' Identifier typeParameters? '=' type ';' + ; + +variableDeclaration + : 'let' Identifier typeAnnotation? ('=' expression)? ';' + ; + +// Type definitions +typeAnnotation + : ':' type + ; + +type + : unionType + ; + +unionType + : intersectionType ('|' intersectionType)* + ; + +intersectionType + : arrayType ('&' arrayType)* + ; + +arrayType + : primaryType ('[' ']')* + ; + +primaryType + : parenthesizedType + | primitiveType + | objectType + | yorkieType + | typeReference + ; + +primitiveType + : 'number' + | 'string' + | 'boolean' + | 'any' + | 'void' + | 'null' + | 'undefined' + ; + +objectType + : '{' (propertySignature)* '}' + ; + +propertySignature + : propertyName typeAnnotation ';' + ; + +propertyName + : Identifier + | StringLiteral + ; + +// Yorkie specific types +yorkieType + : 'yorkie.Object' + | 'yorkie.Array' + | 'yorkie.Counter' + | 'yorkie.Text' + | 'yorkie.Tree' + ; + +typeReference + : Identifier typeArguments? + ; + +parenthesizedType + : '(' type ')' + ; + +// Generics +typeParameters + : '<' typeParameter (',' typeParameter)* '>' + ; + +typeParameter + : Identifier ('extends' type)? + ; + +typeArguments + : '<' type (',' type)* '>' + ; + +// Expressions +expression + : Identifier + | literal + ; + +literal + : StringLiteral + | NumberLiteral + | BooleanLiteral + ; + +// Lexer rules +Identifier: [a-zA-Z_][a-zA-Z0-9_]*; +StringLiteral: '"' (~["\r\n])* '"'; +NumberLiteral: [0-9]+('.'[0-9]+)?; +BooleanLiteral: 'true' | 'false'; +SingleLineComment: '//' ~[\r\n]* -> channel(HIDDEN); +MultiLineComment: '/*' .*? '*/' -> channel(HIDDEN); +WS: [ \t\r\n]+ -> skip; diff --git a/antlr/YorkieSchema.interp b/antlr/YorkieSchema.interp new file mode 100644 index 0000000..bcda26a --- /dev/null +++ b/antlr/YorkieSchema.interp @@ -0,0 +1,105 @@ +token literal names: +null +'type' +'=' +';' +'let' +':' +'|' +'&' +'[' +']' +'number' +'string' +'boolean' +'any' +'void' +'null' +'undefined' +'{' +'}' +'yorkie.Object' +'yorkie.Array' +'yorkie.Counter' +'yorkie.Text' +'yorkie.Tree' +'(' +')' +'<' +',' +'>' +'extends' +null +null +null +null +null +null +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +Identifier +StringLiteral +NumberLiteral +BooleanLiteral +SingleLineComment +MultiLineComment +WS + +rule names: +document +declaration +typeAliasDeclaration +variableDeclaration +typeAnnotation +type +unionType +intersectionType +arrayType +primaryType +primitiveType +objectType +propertySignature +propertyName +yorkieType +typeReference +parenthesizedType +typeParameters +typeParameter +typeArguments +expression +literal + + +atn: +[3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 3, 38, 175, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 3, 2, 7, 2, 48, 10, 2, 12, 2, 14, 2, 51, 11, 2, 3, 2, 3, 2, 3, 3, 3, 3, 5, 3, 57, 10, 3, 3, 4, 3, 4, 3, 4, 5, 4, 62, 10, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 5, 5, 71, 10, 5, 3, 5, 3, 5, 5, 5, 75, 10, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 7, 8, 87, 10, 8, 12, 8, 14, 8, 90, 11, 8, 3, 9, 3, 9, 3, 9, 7, 9, 95, 10, 9, 12, 9, 14, 9, 98, 11, 9, 3, 10, 3, 10, 3, 10, 7, 10, 103, 10, 10, 12, 10, 14, 10, 106, 11, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 5, 11, 113, 10, 11, 3, 12, 3, 12, 3, 13, 3, 13, 7, 13, 119, 10, 13, 12, 13, 14, 13, 122, 11, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 3, 17, 5, 17, 136, 10, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 7, 19, 146, 10, 19, 12, 19, 14, 19, 149, 11, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 5, 20, 156, 10, 20, 3, 21, 3, 21, 3, 21, 3, 21, 7, 21, 162, 10, 21, 12, 21, 14, 21, 165, 11, 21, 3, 21, 3, 21, 3, 22, 3, 22, 5, 22, 171, 10, 22, 3, 23, 3, 23, 3, 23, 2, 2, 2, 24, 2, 2, 4, 2, 6, 2, 8, 2, 10, 2, 12, 2, 14, 2, 16, 2, 18, 2, 20, 2, 22, 2, 24, 2, 26, 2, 28, 2, 30, 2, 32, 2, 34, 2, 36, 2, 38, 2, 40, 2, 42, 2, 44, 2, 2, 6, 3, 2, 12, 18, 3, 2, 32, 33, 3, 2, 21, 25, 3, 2, 33, 35, 2, 170, 2, 49, 3, 2, 2, 2, 4, 56, 3, 2, 2, 2, 6, 58, 3, 2, 2, 2, 8, 67, 3, 2, 2, 2, 10, 78, 3, 2, 2, 2, 12, 81, 3, 2, 2, 2, 14, 83, 3, 2, 2, 2, 16, 91, 3, 2, 2, 2, 18, 99, 3, 2, 2, 2, 20, 112, 3, 2, 2, 2, 22, 114, 3, 2, 2, 2, 24, 116, 3, 2, 2, 2, 26, 125, 3, 2, 2, 2, 28, 129, 3, 2, 2, 2, 30, 131, 3, 2, 2, 2, 32, 133, 3, 2, 2, 2, 34, 137, 3, 2, 2, 2, 36, 141, 3, 2, 2, 2, 38, 152, 3, 2, 2, 2, 40, 157, 3, 2, 2, 2, 42, 170, 3, 2, 2, 2, 44, 172, 3, 2, 2, 2, 46, 48, 5, 4, 3, 2, 47, 46, 3, 2, 2, 2, 48, 51, 3, 2, 2, 2, 49, 47, 3, 2, 2, 2, 49, 50, 3, 2, 2, 2, 50, 52, 3, 2, 2, 2, 51, 49, 3, 2, 2, 2, 52, 53, 7, 2, 2, 3, 53, 3, 3, 2, 2, 2, 54, 57, 5, 6, 4, 2, 55, 57, 5, 8, 5, 2, 56, 54, 3, 2, 2, 2, 56, 55, 3, 2, 2, 2, 57, 5, 3, 2, 2, 2, 58, 59, 7, 3, 2, 2, 59, 61, 7, 32, 2, 2, 60, 62, 5, 36, 19, 2, 61, 60, 3, 2, 2, 2, 61, 62, 3, 2, 2, 2, 62, 63, 3, 2, 2, 2, 63, 64, 7, 4, 2, 2, 64, 65, 5, 12, 7, 2, 65, 66, 7, 5, 2, 2, 66, 7, 3, 2, 2, 2, 67, 68, 7, 6, 2, 2, 68, 70, 7, 32, 2, 2, 69, 71, 5, 10, 6, 2, 70, 69, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 74, 3, 2, 2, 2, 72, 73, 7, 4, 2, 2, 73, 75, 5, 42, 22, 2, 74, 72, 3, 2, 2, 2, 74, 75, 3, 2, 2, 2, 75, 76, 3, 2, 2, 2, 76, 77, 7, 5, 2, 2, 77, 9, 3, 2, 2, 2, 78, 79, 7, 7, 2, 2, 79, 80, 5, 12, 7, 2, 80, 11, 3, 2, 2, 2, 81, 82, 5, 14, 8, 2, 82, 13, 3, 2, 2, 2, 83, 88, 5, 16, 9, 2, 84, 85, 7, 8, 2, 2, 85, 87, 5, 16, 9, 2, 86, 84, 3, 2, 2, 2, 87, 90, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 88, 89, 3, 2, 2, 2, 89, 15, 3, 2, 2, 2, 90, 88, 3, 2, 2, 2, 91, 96, 5, 18, 10, 2, 92, 93, 7, 9, 2, 2, 93, 95, 5, 18, 10, 2, 94, 92, 3, 2, 2, 2, 95, 98, 3, 2, 2, 2, 96, 94, 3, 2, 2, 2, 96, 97, 3, 2, 2, 2, 97, 17, 3, 2, 2, 2, 98, 96, 3, 2, 2, 2, 99, 104, 5, 20, 11, 2, 100, 101, 7, 10, 2, 2, 101, 103, 7, 11, 2, 2, 102, 100, 3, 2, 2, 2, 103, 106, 3, 2, 2, 2, 104, 102, 3, 2, 2, 2, 104, 105, 3, 2, 2, 2, 105, 19, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 107, 113, 5, 34, 18, 2, 108, 113, 5, 22, 12, 2, 109, 113, 5, 24, 13, 2, 110, 113, 5, 30, 16, 2, 111, 113, 5, 32, 17, 2, 112, 107, 3, 2, 2, 2, 112, 108, 3, 2, 2, 2, 112, 109, 3, 2, 2, 2, 112, 110, 3, 2, 2, 2, 112, 111, 3, 2, 2, 2, 113, 21, 3, 2, 2, 2, 114, 115, 9, 2, 2, 2, 115, 23, 3, 2, 2, 2, 116, 120, 7, 19, 2, 2, 117, 119, 5, 26, 14, 2, 118, 117, 3, 2, 2, 2, 119, 122, 3, 2, 2, 2, 120, 118, 3, 2, 2, 2, 120, 121, 3, 2, 2, 2, 121, 123, 3, 2, 2, 2, 122, 120, 3, 2, 2, 2, 123, 124, 7, 20, 2, 2, 124, 25, 3, 2, 2, 2, 125, 126, 5, 28, 15, 2, 126, 127, 5, 10, 6, 2, 127, 128, 7, 5, 2, 2, 128, 27, 3, 2, 2, 2, 129, 130, 9, 3, 2, 2, 130, 29, 3, 2, 2, 2, 131, 132, 9, 4, 2, 2, 132, 31, 3, 2, 2, 2, 133, 135, 7, 32, 2, 2, 134, 136, 5, 40, 21, 2, 135, 134, 3, 2, 2, 2, 135, 136, 3, 2, 2, 2, 136, 33, 3, 2, 2, 2, 137, 138, 7, 26, 2, 2, 138, 139, 5, 12, 7, 2, 139, 140, 7, 27, 2, 2, 140, 35, 3, 2, 2, 2, 141, 142, 7, 28, 2, 2, 142, 147, 5, 38, 20, 2, 143, 144, 7, 29, 2, 2, 144, 146, 5, 38, 20, 2, 145, 143, 3, 2, 2, 2, 146, 149, 3, 2, 2, 2, 147, 145, 3, 2, 2, 2, 147, 148, 3, 2, 2, 2, 148, 150, 3, 2, 2, 2, 149, 147, 3, 2, 2, 2, 150, 151, 7, 30, 2, 2, 151, 37, 3, 2, 2, 2, 152, 155, 7, 32, 2, 2, 153, 154, 7, 31, 2, 2, 154, 156, 5, 12, 7, 2, 155, 153, 3, 2, 2, 2, 155, 156, 3, 2, 2, 2, 156, 39, 3, 2, 2, 2, 157, 158, 7, 28, 2, 2, 158, 163, 5, 12, 7, 2, 159, 160, 7, 29, 2, 2, 160, 162, 5, 12, 7, 2, 161, 159, 3, 2, 2, 2, 162, 165, 3, 2, 2, 2, 163, 161, 3, 2, 2, 2, 163, 164, 3, 2, 2, 2, 164, 166, 3, 2, 2, 2, 165, 163, 3, 2, 2, 2, 166, 167, 7, 30, 2, 2, 167, 41, 3, 2, 2, 2, 168, 171, 7, 32, 2, 2, 169, 171, 5, 44, 23, 2, 170, 168, 3, 2, 2, 2, 170, 169, 3, 2, 2, 2, 171, 43, 3, 2, 2, 2, 172, 173, 9, 5, 2, 2, 173, 45, 3, 2, 2, 2, 17, 49, 56, 61, 70, 74, 88, 96, 104, 112, 120, 135, 147, 155, 163, 170] \ No newline at end of file diff --git a/antlr/YorkieSchema.tokens b/antlr/YorkieSchema.tokens new file mode 100644 index 0000000..2c8817c --- /dev/null +++ b/antlr/YorkieSchema.tokens @@ -0,0 +1,65 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +T__12=13 +T__13=14 +T__14=15 +T__15=16 +T__16=17 +T__17=18 +T__18=19 +T__19=20 +T__20=21 +T__21=22 +T__22=23 +T__23=24 +T__24=25 +T__25=26 +T__26=27 +T__27=28 +T__28=29 +Identifier=30 +StringLiteral=31 +NumberLiteral=32 +BooleanLiteral=33 +SingleLineComment=34 +MultiLineComment=35 +WS=36 +'type'=1 +'='=2 +';'=3 +'let'=4 +':'=5 +'|'=6 +'&'=7 +'['=8 +']'=9 +'number'=10 +'string'=11 +'boolean'=12 +'any'=13 +'void'=14 +'null'=15 +'undefined'=16 +'{'=17 +'}'=18 +'yorkie.Object'=19 +'yorkie.Array'=20 +'yorkie.Counter'=21 +'yorkie.Text'=22 +'yorkie.Tree'=23 +'('=24 +')'=25 +'<'=26 +','=27 +'>'=28 +'extends'=29 diff --git a/antlr/YorkieSchemaLexer.interp b/antlr/YorkieSchemaLexer.interp new file mode 100644 index 0000000..2c7af98 --- /dev/null +++ b/antlr/YorkieSchemaLexer.interp @@ -0,0 +1,125 @@ +token literal names: +null +'type' +'=' +';' +'let' +':' +'|' +'&' +'[' +']' +'number' +'string' +'boolean' +'any' +'void' +'null' +'undefined' +'{' +'}' +'yorkie.Object' +'yorkie.Array' +'yorkie.Counter' +'yorkie.Text' +'yorkie.Tree' +'(' +')' +'<' +',' +'>' +'extends' +null +null +null +null +null +null +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +null +Identifier +StringLiteral +NumberLiteral +BooleanLiteral +SingleLineComment +MultiLineComment +WS + +rule names: +T__0 +T__1 +T__2 +T__3 +T__4 +T__5 +T__6 +T__7 +T__8 +T__9 +T__10 +T__11 +T__12 +T__13 +T__14 +T__15 +T__16 +T__17 +T__18 +T__19 +T__20 +T__21 +T__22 +T__23 +T__24 +T__25 +T__26 +T__27 +T__28 +Identifier +StringLiteral +NumberLiteral +BooleanLiteral +SingleLineComment +MultiLineComment +WS + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[3, 51485, 51898, 1421, 44986, 20307, 1543, 60043, 49729, 2, 38, 304, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 4, 34, 9, 34, 4, 35, 9, 35, 4, 36, 9, 36, 4, 37, 9, 37, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 18, 3, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 25, 3, 25, 3, 26, 3, 26, 3, 27, 3, 27, 3, 28, 3, 28, 3, 29, 3, 29, 3, 30, 3, 30, 3, 30, 3, 30, 3, 30, 3, 30, 3, 30, 3, 30, 3, 31, 3, 31, 7, 31, 235, 10, 31, 12, 31, 14, 31, 238, 11, 31, 3, 32, 3, 32, 7, 32, 242, 10, 32, 12, 32, 14, 32, 245, 11, 32, 3, 32, 3, 32, 3, 33, 6, 33, 250, 10, 33, 13, 33, 14, 33, 251, 3, 33, 3, 33, 6, 33, 256, 10, 33, 13, 33, 14, 33, 257, 5, 33, 260, 10, 33, 3, 34, 3, 34, 3, 34, 3, 34, 3, 34, 3, 34, 3, 34, 3, 34, 3, 34, 5, 34, 271, 10, 34, 3, 35, 3, 35, 3, 35, 3, 35, 7, 35, 277, 10, 35, 12, 35, 14, 35, 280, 11, 35, 3, 35, 3, 35, 3, 36, 3, 36, 3, 36, 3, 36, 7, 36, 288, 10, 36, 12, 36, 14, 36, 291, 11, 36, 3, 36, 3, 36, 3, 36, 3, 36, 3, 36, 3, 37, 6, 37, 299, 10, 37, 13, 37, 14, 37, 300, 3, 37, 3, 37, 3, 289, 2, 2, 38, 3, 2, 3, 5, 2, 4, 7, 2, 5, 9, 2, 6, 11, 2, 7, 13, 2, 8, 15, 2, 9, 17, 2, 10, 19, 2, 11, 21, 2, 12, 23, 2, 13, 25, 2, 14, 27, 2, 15, 29, 2, 16, 31, 2, 17, 33, 2, 18, 35, 2, 19, 37, 2, 20, 39, 2, 21, 41, 2, 22, 43, 2, 23, 45, 2, 24, 47, 2, 25, 49, 2, 26, 51, 2, 27, 53, 2, 28, 55, 2, 29, 57, 2, 30, 59, 2, 31, 61, 2, 32, 63, 2, 33, 65, 2, 34, 67, 2, 35, 69, 2, 36, 71, 2, 37, 73, 2, 38, 3, 2, 8, 5, 2, 67, 92, 97, 97, 99, 124, 6, 2, 50, 59, 67, 92, 97, 97, 99, 124, 5, 2, 12, 12, 15, 15, 36, 36, 3, 2, 50, 59, 4, 2, 12, 12, 15, 15, 5, 2, 11, 12, 15, 15, 34, 34, 2, 312, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 45, 3, 2, 2, 2, 2, 47, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 2, 57, 3, 2, 2, 2, 2, 59, 3, 2, 2, 2, 2, 61, 3, 2, 2, 2, 2, 63, 3, 2, 2, 2, 2, 65, 3, 2, 2, 2, 2, 67, 3, 2, 2, 2, 2, 69, 3, 2, 2, 2, 2, 71, 3, 2, 2, 2, 2, 73, 3, 2, 2, 2, 3, 75, 3, 2, 2, 2, 5, 80, 3, 2, 2, 2, 7, 82, 3, 2, 2, 2, 9, 84, 3, 2, 2, 2, 11, 88, 3, 2, 2, 2, 13, 90, 3, 2, 2, 2, 15, 92, 3, 2, 2, 2, 17, 94, 3, 2, 2, 2, 19, 96, 3, 2, 2, 2, 21, 98, 3, 2, 2, 2, 23, 105, 3, 2, 2, 2, 25, 112, 3, 2, 2, 2, 27, 120, 3, 2, 2, 2, 29, 124, 3, 2, 2, 2, 31, 129, 3, 2, 2, 2, 33, 134, 3, 2, 2, 2, 35, 144, 3, 2, 2, 2, 37, 146, 3, 2, 2, 2, 39, 148, 3, 2, 2, 2, 41, 162, 3, 2, 2, 2, 43, 175, 3, 2, 2, 2, 45, 190, 3, 2, 2, 2, 47, 202, 3, 2, 2, 2, 49, 214, 3, 2, 2, 2, 51, 216, 3, 2, 2, 2, 53, 218, 3, 2, 2, 2, 55, 220, 3, 2, 2, 2, 57, 222, 3, 2, 2, 2, 59, 224, 3, 2, 2, 2, 61, 232, 3, 2, 2, 2, 63, 239, 3, 2, 2, 2, 65, 249, 3, 2, 2, 2, 67, 270, 3, 2, 2, 2, 69, 272, 3, 2, 2, 2, 71, 283, 3, 2, 2, 2, 73, 298, 3, 2, 2, 2, 75, 76, 7, 118, 2, 2, 76, 77, 7, 123, 2, 2, 77, 78, 7, 114, 2, 2, 78, 79, 7, 103, 2, 2, 79, 4, 3, 2, 2, 2, 80, 81, 7, 63, 2, 2, 81, 6, 3, 2, 2, 2, 82, 83, 7, 61, 2, 2, 83, 8, 3, 2, 2, 2, 84, 85, 7, 110, 2, 2, 85, 86, 7, 103, 2, 2, 86, 87, 7, 118, 2, 2, 87, 10, 3, 2, 2, 2, 88, 89, 7, 60, 2, 2, 89, 12, 3, 2, 2, 2, 90, 91, 7, 126, 2, 2, 91, 14, 3, 2, 2, 2, 92, 93, 7, 40, 2, 2, 93, 16, 3, 2, 2, 2, 94, 95, 7, 93, 2, 2, 95, 18, 3, 2, 2, 2, 96, 97, 7, 95, 2, 2, 97, 20, 3, 2, 2, 2, 98, 99, 7, 112, 2, 2, 99, 100, 7, 119, 2, 2, 100, 101, 7, 111, 2, 2, 101, 102, 7, 100, 2, 2, 102, 103, 7, 103, 2, 2, 103, 104, 7, 116, 2, 2, 104, 22, 3, 2, 2, 2, 105, 106, 7, 117, 2, 2, 106, 107, 7, 118, 2, 2, 107, 108, 7, 116, 2, 2, 108, 109, 7, 107, 2, 2, 109, 110, 7, 112, 2, 2, 110, 111, 7, 105, 2, 2, 111, 24, 3, 2, 2, 2, 112, 113, 7, 100, 2, 2, 113, 114, 7, 113, 2, 2, 114, 115, 7, 113, 2, 2, 115, 116, 7, 110, 2, 2, 116, 117, 7, 103, 2, 2, 117, 118, 7, 99, 2, 2, 118, 119, 7, 112, 2, 2, 119, 26, 3, 2, 2, 2, 120, 121, 7, 99, 2, 2, 121, 122, 7, 112, 2, 2, 122, 123, 7, 123, 2, 2, 123, 28, 3, 2, 2, 2, 124, 125, 7, 120, 2, 2, 125, 126, 7, 113, 2, 2, 126, 127, 7, 107, 2, 2, 127, 128, 7, 102, 2, 2, 128, 30, 3, 2, 2, 2, 129, 130, 7, 112, 2, 2, 130, 131, 7, 119, 2, 2, 131, 132, 7, 110, 2, 2, 132, 133, 7, 110, 2, 2, 133, 32, 3, 2, 2, 2, 134, 135, 7, 119, 2, 2, 135, 136, 7, 112, 2, 2, 136, 137, 7, 102, 2, 2, 137, 138, 7, 103, 2, 2, 138, 139, 7, 104, 2, 2, 139, 140, 7, 107, 2, 2, 140, 141, 7, 112, 2, 2, 141, 142, 7, 103, 2, 2, 142, 143, 7, 102, 2, 2, 143, 34, 3, 2, 2, 2, 144, 145, 7, 125, 2, 2, 145, 36, 3, 2, 2, 2, 146, 147, 7, 127, 2, 2, 147, 38, 3, 2, 2, 2, 148, 149, 7, 123, 2, 2, 149, 150, 7, 113, 2, 2, 150, 151, 7, 116, 2, 2, 151, 152, 7, 109, 2, 2, 152, 153, 7, 107, 2, 2, 153, 154, 7, 103, 2, 2, 154, 155, 7, 48, 2, 2, 155, 156, 7, 81, 2, 2, 156, 157, 7, 100, 2, 2, 157, 158, 7, 108, 2, 2, 158, 159, 7, 103, 2, 2, 159, 160, 7, 101, 2, 2, 160, 161, 7, 118, 2, 2, 161, 40, 3, 2, 2, 2, 162, 163, 7, 123, 2, 2, 163, 164, 7, 113, 2, 2, 164, 165, 7, 116, 2, 2, 165, 166, 7, 109, 2, 2, 166, 167, 7, 107, 2, 2, 167, 168, 7, 103, 2, 2, 168, 169, 7, 48, 2, 2, 169, 170, 7, 67, 2, 2, 170, 171, 7, 116, 2, 2, 171, 172, 7, 116, 2, 2, 172, 173, 7, 99, 2, 2, 173, 174, 7, 123, 2, 2, 174, 42, 3, 2, 2, 2, 175, 176, 7, 123, 2, 2, 176, 177, 7, 113, 2, 2, 177, 178, 7, 116, 2, 2, 178, 179, 7, 109, 2, 2, 179, 180, 7, 107, 2, 2, 180, 181, 7, 103, 2, 2, 181, 182, 7, 48, 2, 2, 182, 183, 7, 69, 2, 2, 183, 184, 7, 113, 2, 2, 184, 185, 7, 119, 2, 2, 185, 186, 7, 112, 2, 2, 186, 187, 7, 118, 2, 2, 187, 188, 7, 103, 2, 2, 188, 189, 7, 116, 2, 2, 189, 44, 3, 2, 2, 2, 190, 191, 7, 123, 2, 2, 191, 192, 7, 113, 2, 2, 192, 193, 7, 116, 2, 2, 193, 194, 7, 109, 2, 2, 194, 195, 7, 107, 2, 2, 195, 196, 7, 103, 2, 2, 196, 197, 7, 48, 2, 2, 197, 198, 7, 86, 2, 2, 198, 199, 7, 103, 2, 2, 199, 200, 7, 122, 2, 2, 200, 201, 7, 118, 2, 2, 201, 46, 3, 2, 2, 2, 202, 203, 7, 123, 2, 2, 203, 204, 7, 113, 2, 2, 204, 205, 7, 116, 2, 2, 205, 206, 7, 109, 2, 2, 206, 207, 7, 107, 2, 2, 207, 208, 7, 103, 2, 2, 208, 209, 7, 48, 2, 2, 209, 210, 7, 86, 2, 2, 210, 211, 7, 116, 2, 2, 211, 212, 7, 103, 2, 2, 212, 213, 7, 103, 2, 2, 213, 48, 3, 2, 2, 2, 214, 215, 7, 42, 2, 2, 215, 50, 3, 2, 2, 2, 216, 217, 7, 43, 2, 2, 217, 52, 3, 2, 2, 2, 218, 219, 7, 62, 2, 2, 219, 54, 3, 2, 2, 2, 220, 221, 7, 46, 2, 2, 221, 56, 3, 2, 2, 2, 222, 223, 7, 64, 2, 2, 223, 58, 3, 2, 2, 2, 224, 225, 7, 103, 2, 2, 225, 226, 7, 122, 2, 2, 226, 227, 7, 118, 2, 2, 227, 228, 7, 103, 2, 2, 228, 229, 7, 112, 2, 2, 229, 230, 7, 102, 2, 2, 230, 231, 7, 117, 2, 2, 231, 60, 3, 2, 2, 2, 232, 236, 9, 2, 2, 2, 233, 235, 9, 3, 2, 2, 234, 233, 3, 2, 2, 2, 235, 238, 3, 2, 2, 2, 236, 234, 3, 2, 2, 2, 236, 237, 3, 2, 2, 2, 237, 62, 3, 2, 2, 2, 238, 236, 3, 2, 2, 2, 239, 243, 7, 36, 2, 2, 240, 242, 10, 4, 2, 2, 241, 240, 3, 2, 2, 2, 242, 245, 3, 2, 2, 2, 243, 241, 3, 2, 2, 2, 243, 244, 3, 2, 2, 2, 244, 246, 3, 2, 2, 2, 245, 243, 3, 2, 2, 2, 246, 247, 7, 36, 2, 2, 247, 64, 3, 2, 2, 2, 248, 250, 9, 5, 2, 2, 249, 248, 3, 2, 2, 2, 250, 251, 3, 2, 2, 2, 251, 249, 3, 2, 2, 2, 251, 252, 3, 2, 2, 2, 252, 259, 3, 2, 2, 2, 253, 255, 7, 48, 2, 2, 254, 256, 9, 5, 2, 2, 255, 254, 3, 2, 2, 2, 256, 257, 3, 2, 2, 2, 257, 255, 3, 2, 2, 2, 257, 258, 3, 2, 2, 2, 258, 260, 3, 2, 2, 2, 259, 253, 3, 2, 2, 2, 259, 260, 3, 2, 2, 2, 260, 66, 3, 2, 2, 2, 261, 262, 7, 118, 2, 2, 262, 263, 7, 116, 2, 2, 263, 264, 7, 119, 2, 2, 264, 271, 7, 103, 2, 2, 265, 266, 7, 104, 2, 2, 266, 267, 7, 99, 2, 2, 267, 268, 7, 110, 2, 2, 268, 269, 7, 117, 2, 2, 269, 271, 7, 103, 2, 2, 270, 261, 3, 2, 2, 2, 270, 265, 3, 2, 2, 2, 271, 68, 3, 2, 2, 2, 272, 273, 7, 49, 2, 2, 273, 274, 7, 49, 2, 2, 274, 278, 3, 2, 2, 2, 275, 277, 10, 6, 2, 2, 276, 275, 3, 2, 2, 2, 277, 280, 3, 2, 2, 2, 278, 276, 3, 2, 2, 2, 278, 279, 3, 2, 2, 2, 279, 281, 3, 2, 2, 2, 280, 278, 3, 2, 2, 2, 281, 282, 8, 35, 2, 2, 282, 70, 3, 2, 2, 2, 283, 284, 7, 49, 2, 2, 284, 285, 7, 44, 2, 2, 285, 289, 3, 2, 2, 2, 286, 288, 11, 2, 2, 2, 287, 286, 3, 2, 2, 2, 288, 291, 3, 2, 2, 2, 289, 290, 3, 2, 2, 2, 289, 287, 3, 2, 2, 2, 290, 292, 3, 2, 2, 2, 291, 289, 3, 2, 2, 2, 292, 293, 7, 44, 2, 2, 293, 294, 7, 49, 2, 2, 294, 295, 3, 2, 2, 2, 295, 296, 8, 36, 2, 2, 296, 72, 3, 2, 2, 2, 297, 299, 9, 7, 2, 2, 298, 297, 3, 2, 2, 2, 299, 300, 3, 2, 2, 2, 300, 298, 3, 2, 2, 2, 300, 301, 3, 2, 2, 2, 301, 302, 3, 2, 2, 2, 302, 303, 8, 37, 3, 2, 303, 74, 3, 2, 2, 2, 12, 2, 236, 243, 251, 257, 259, 270, 278, 289, 300, 4, 2, 3, 2, 8, 2, 2] \ No newline at end of file diff --git a/antlr/YorkieSchemaLexer.tokens b/antlr/YorkieSchemaLexer.tokens new file mode 100644 index 0000000..2c8817c --- /dev/null +++ b/antlr/YorkieSchemaLexer.tokens @@ -0,0 +1,65 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +T__12=13 +T__13=14 +T__14=15 +T__15=16 +T__16=17 +T__17=18 +T__18=19 +T__19=20 +T__20=21 +T__21=22 +T__22=23 +T__23=24 +T__24=25 +T__25=26 +T__26=27 +T__27=28 +T__28=29 +Identifier=30 +StringLiteral=31 +NumberLiteral=32 +BooleanLiteral=33 +SingleLineComment=34 +MultiLineComment=35 +WS=36 +'type'=1 +'='=2 +';'=3 +'let'=4 +':'=5 +'|'=6 +'&'=7 +'['=8 +']'=9 +'number'=10 +'string'=11 +'boolean'=12 +'any'=13 +'void'=14 +'null'=15 +'undefined'=16 +'{'=17 +'}'=18 +'yorkie.Object'=19 +'yorkie.Array'=20 +'yorkie.Counter'=21 +'yorkie.Text'=22 +'yorkie.Tree'=23 +'('=24 +')'=25 +'<'=26 +','=27 +'>'=28 +'extends'=29 diff --git a/antlr/YorkieSchemaLexer.ts b/antlr/YorkieSchemaLexer.ts new file mode 100644 index 0000000..2938e9e --- /dev/null +++ b/antlr/YorkieSchemaLexer.ts @@ -0,0 +1,262 @@ +// Generated from antlr/YorkieSchema.g4 by ANTLR 4.9.0-SNAPSHOT + + +import { ATN } from "antlr4ts/atn/ATN"; +import { ATNDeserializer } from "antlr4ts/atn/ATNDeserializer"; +import { CharStream } from "antlr4ts/CharStream"; +import { Lexer } from "antlr4ts/Lexer"; +import { LexerATNSimulator } from "antlr4ts/atn/LexerATNSimulator"; +import { NotNull } from "antlr4ts/Decorators"; +import { Override } from "antlr4ts/Decorators"; +import { RuleContext } from "antlr4ts/RuleContext"; +import { Vocabulary } from "antlr4ts/Vocabulary"; +import { VocabularyImpl } from "antlr4ts/VocabularyImpl"; + +import * as Utils from "antlr4ts/misc/Utils"; + + +export class YorkieSchemaLexer extends Lexer { + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly T__10 = 11; + public static readonly T__11 = 12; + public static readonly T__12 = 13; + public static readonly T__13 = 14; + public static readonly T__14 = 15; + public static readonly T__15 = 16; + public static readonly T__16 = 17; + public static readonly T__17 = 18; + public static readonly T__18 = 19; + public static readonly T__19 = 20; + public static readonly T__20 = 21; + public static readonly T__21 = 22; + public static readonly T__22 = 23; + public static readonly T__23 = 24; + public static readonly T__24 = 25; + public static readonly T__25 = 26; + public static readonly T__26 = 27; + public static readonly T__27 = 28; + public static readonly T__28 = 29; + public static readonly Identifier = 30; + public static readonly StringLiteral = 31; + public static readonly NumberLiteral = 32; + public static readonly BooleanLiteral = 33; + public static readonly SingleLineComment = 34; + public static readonly MultiLineComment = 35; + public static readonly WS = 36; + + // tslint:disable:no-trailing-whitespace + public static readonly channelNames: string[] = [ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN", + ]; + + // tslint:disable:no-trailing-whitespace + public static readonly modeNames: string[] = [ + "DEFAULT_MODE", + ]; + + public static readonly ruleNames: string[] = [ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", + "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", + "T__25", "T__26", "T__27", "T__28", "Identifier", "StringLiteral", "NumberLiteral", + "BooleanLiteral", "SingleLineComment", "MultiLineComment", "WS", + ]; + + private static readonly _LITERAL_NAMES: Array = [ + undefined, "'type'", "'='", "';'", "'let'", "':'", "'|'", "'&'", "'['", + "']'", "'number'", "'string'", "'boolean'", "'any'", "'void'", "'null'", + "'undefined'", "'{'", "'}'", "'yorkie.Object'", "'yorkie.Array'", "'yorkie.Counter'", + "'yorkie.Text'", "'yorkie.Tree'", "'('", "')'", "'<'", "','", "'>'", "'extends'", + ]; + private static readonly _SYMBOLIC_NAMES: Array = [ + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, "Identifier", "StringLiteral", "NumberLiteral", + "BooleanLiteral", "SingleLineComment", "MultiLineComment", "WS", + ]; + public static readonly VOCABULARY: Vocabulary = new VocabularyImpl(YorkieSchemaLexer._LITERAL_NAMES, YorkieSchemaLexer._SYMBOLIC_NAMES, []); + + // @Override + // @NotNull + public get vocabulary(): Vocabulary { + return YorkieSchemaLexer.VOCABULARY; + } + // tslint:enable:no-trailing-whitespace + + + constructor(input: CharStream) { + super(input); + this._interp = new LexerATNSimulator(YorkieSchemaLexer._ATN, this); + } + + // @Override + public get grammarFileName(): string { return "YorkieSchema.g4"; } + + // @Override + public get ruleNames(): string[] { return YorkieSchemaLexer.ruleNames; } + + // @Override + public get serializedATN(): string { return YorkieSchemaLexer._serializedATN; } + + // @Override + public get channelNames(): string[] { return YorkieSchemaLexer.channelNames; } + + // @Override + public get modeNames(): string[] { return YorkieSchemaLexer.modeNames; } + + public static readonly _serializedATN: string = + "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x02&\u0130\b\x01" + + "\x04\x02\t\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06" + + "\x04\x07\t\x07\x04\b\t\b\x04\t\t\t\x04\n\t\n\x04\v\t\v\x04\f\t\f\x04\r" + + "\t\r\x04\x0E\t\x0E\x04\x0F\t\x0F\x04\x10\t\x10\x04\x11\t\x11\x04\x12\t" + + "\x12\x04\x13\t\x13\x04\x14\t\x14\x04\x15\t\x15\x04\x16\t\x16\x04\x17\t" + + "\x17\x04\x18\t\x18\x04\x19\t\x19\x04\x1A\t\x1A\x04\x1B\t\x1B\x04\x1C\t" + + "\x1C\x04\x1D\t\x1D\x04\x1E\t\x1E\x04\x1F\t\x1F\x04 \t \x04!\t!\x04\"\t" + + "\"\x04#\t#\x04$\t$\x04%\t%\x03\x02\x03\x02\x03\x02\x03\x02\x03\x02\x03" + + "\x03\x03\x03\x03\x04\x03\x04\x03\x05\x03\x05\x03\x05\x03\x05\x03\x06\x03" + + "\x06\x03\x07\x03\x07\x03\b\x03\b\x03\t\x03\t\x03\n\x03\n\x03\v\x03\v\x03" + + "\v\x03\v\x03\v\x03\v\x03\v\x03\f\x03\f\x03\f\x03\f\x03\f\x03\f\x03\f\x03" + + "\r\x03\r\x03\r\x03\r\x03\r\x03\r\x03\r\x03\r\x03\x0E\x03\x0E\x03\x0E\x03" + + "\x0E\x03\x0F\x03\x0F\x03\x0F\x03\x0F\x03\x0F\x03\x10\x03\x10\x03\x10\x03" + + "\x10\x03\x10\x03\x11\x03\x11\x03\x11\x03\x11\x03\x11\x03\x11\x03\x11\x03" + + "\x11\x03\x11\x03\x11\x03\x12\x03\x12\x03\x13\x03\x13\x03\x14\x03\x14\x03" + + "\x14\x03\x14\x03\x14\x03\x14\x03\x14\x03\x14\x03\x14\x03\x14\x03\x14\x03" + + "\x14\x03\x14\x03\x14\x03\x15\x03\x15\x03\x15\x03\x15\x03\x15\x03\x15\x03" + + "\x15\x03\x15\x03\x15\x03\x15\x03\x15\x03\x15\x03\x15\x03\x16\x03\x16\x03" + + "\x16\x03\x16\x03\x16\x03\x16\x03\x16\x03\x16\x03\x16\x03\x16\x03\x16\x03" + + "\x16\x03\x16\x03\x16\x03\x16\x03\x17\x03\x17\x03\x17\x03\x17\x03\x17\x03" + + "\x17\x03\x17\x03\x17\x03\x17\x03\x17\x03\x17\x03\x17\x03\x18\x03\x18\x03" + + "\x18\x03\x18\x03\x18\x03\x18\x03\x18\x03\x18\x03\x18\x03\x18\x03\x18\x03" + + "\x18\x03\x19\x03\x19\x03\x1A\x03\x1A\x03\x1B\x03\x1B\x03\x1C\x03\x1C\x03" + + "\x1D\x03\x1D\x03\x1E\x03\x1E\x03\x1E\x03\x1E\x03\x1E\x03\x1E\x03\x1E\x03" + + "\x1E\x03\x1F\x03\x1F\x07\x1F\xEB\n\x1F\f\x1F\x0E\x1F\xEE\v\x1F\x03 \x03" + + " \x07 \xF2\n \f \x0E \xF5\v \x03 \x03 \x03!\x06!\xFA\n!\r!\x0E!\xFB\x03" + + "!\x03!\x06!\u0100\n!\r!\x0E!\u0101\x05!\u0104\n!\x03\"\x03\"\x03\"\x03" + + "\"\x03\"\x03\"\x03\"\x03\"\x03\"\x05\"\u010F\n\"\x03#\x03#\x03#\x03#\x07" + + "#\u0115\n#\f#\x0E#\u0118\v#\x03#\x03#\x03$\x03$\x03$\x03$\x07$\u0120\n" + + "$\f$\x0E$\u0123\v$\x03$\x03$\x03$\x03$\x03$\x03%\x06%\u012B\n%\r%\x0E" + + "%\u012C\x03%\x03%\x03\u0121\x02\x02&\x03\x02\x03\x05\x02\x04\x07\x02\x05" + + "\t\x02\x06\v\x02\x07\r\x02\b\x0F\x02\t\x11\x02\n\x13\x02\v\x15\x02\f\x17" + + "\x02\r\x19\x02\x0E\x1B\x02\x0F\x1D\x02\x10\x1F\x02\x11!\x02\x12#\x02\x13" + + "%\x02\x14\'\x02\x15)\x02\x16+\x02\x17-\x02\x18/\x02\x191\x02\x1A3\x02" + + "\x1B5\x02\x1C7\x02\x1D9\x02\x1E;\x02\x1F=\x02 ?\x02!A\x02\"C\x02#E\x02" + + "$G\x02%I\x02&\x03\x02\b\x05\x02C\\aac|\x06\x022;C\\aac|\x05\x02\f\f\x0F" + + "\x0F$$\x03\x022;\x04\x02\f\f\x0F\x0F\x05\x02\v\f\x0F\x0F\"\"\x02\u0138" + + "\x02\x03\x03\x02\x02\x02\x02\x05\x03\x02\x02\x02\x02\x07\x03\x02\x02\x02" + + "\x02\t\x03\x02\x02\x02\x02\v\x03\x02\x02\x02\x02\r\x03\x02\x02\x02\x02" + + "\x0F\x03\x02\x02\x02\x02\x11\x03\x02\x02\x02\x02\x13\x03\x02\x02\x02\x02" + + "\x15\x03\x02\x02\x02\x02\x17\x03\x02\x02\x02\x02\x19\x03\x02\x02\x02\x02" + + "\x1B\x03\x02\x02\x02\x02\x1D\x03\x02\x02\x02\x02\x1F\x03\x02\x02\x02\x02" + + "!\x03\x02\x02\x02\x02#\x03\x02\x02\x02\x02%\x03\x02\x02\x02\x02\'\x03" + + "\x02\x02\x02\x02)\x03\x02\x02\x02\x02+\x03\x02\x02\x02\x02-\x03\x02\x02" + + "\x02\x02/\x03\x02\x02\x02\x021\x03\x02\x02\x02\x023\x03\x02\x02\x02\x02" + + "5\x03\x02\x02\x02\x027\x03\x02\x02\x02\x029\x03\x02\x02\x02\x02;\x03\x02" + + "\x02\x02\x02=\x03\x02\x02\x02\x02?\x03\x02\x02\x02\x02A\x03\x02\x02\x02" + + "\x02C\x03\x02\x02\x02\x02E\x03\x02\x02\x02\x02G\x03\x02\x02\x02\x02I\x03" + + "\x02\x02\x02\x03K\x03\x02\x02\x02\x05P\x03\x02\x02\x02\x07R\x03\x02\x02" + + "\x02\tT\x03\x02\x02\x02\vX\x03\x02\x02\x02\rZ\x03\x02\x02\x02\x0F\\\x03" + + "\x02\x02\x02\x11^\x03\x02\x02\x02\x13`\x03\x02\x02\x02\x15b\x03\x02\x02" + + "\x02\x17i\x03\x02\x02\x02\x19p\x03\x02\x02\x02\x1Bx\x03\x02\x02\x02\x1D" + + "|\x03\x02\x02\x02\x1F\x81\x03\x02\x02\x02!\x86\x03\x02\x02\x02#\x90\x03" + + "\x02\x02\x02%\x92\x03\x02\x02\x02\'\x94\x03\x02\x02\x02)\xA2\x03\x02\x02" + + "\x02+\xAF\x03\x02\x02\x02-\xBE\x03\x02\x02\x02/\xCA\x03\x02\x02\x021\xD6" + + "\x03\x02\x02\x023\xD8\x03\x02\x02\x025\xDA\x03\x02\x02\x027\xDC\x03\x02" + + "\x02\x029\xDE\x03\x02\x02\x02;\xE0\x03\x02\x02\x02=\xE8\x03\x02\x02\x02" + + "?\xEF\x03\x02\x02\x02A\xF9\x03\x02\x02\x02C\u010E\x03\x02\x02\x02E\u0110" + + "\x03\x02\x02\x02G\u011B\x03\x02\x02\x02I\u012A\x03\x02\x02\x02KL\x07v" + + "\x02\x02LM\x07{\x02\x02MN\x07r\x02\x02NO\x07g\x02\x02O\x04\x03\x02\x02" + + "\x02PQ\x07?\x02\x02Q\x06\x03\x02\x02\x02RS\x07=\x02\x02S\b\x03\x02\x02" + + "\x02TU\x07n\x02\x02UV\x07g\x02\x02VW\x07v\x02\x02W\n\x03\x02\x02\x02X" + + "Y\x07<\x02\x02Y\f\x03\x02\x02\x02Z[\x07~\x02\x02[\x0E\x03\x02\x02\x02" + + "\\]\x07(\x02\x02]\x10\x03\x02\x02\x02^_\x07]\x02\x02_\x12\x03\x02\x02" + + "\x02`a\x07_\x02\x02a\x14\x03\x02\x02\x02bc\x07p\x02\x02cd\x07w\x02\x02" + + "de\x07o\x02\x02ef\x07d\x02\x02fg\x07g\x02\x02gh\x07t\x02\x02h\x16\x03" + + "\x02\x02\x02ij\x07u\x02\x02jk\x07v\x02\x02kl\x07t\x02\x02lm\x07k\x02\x02" + + "mn\x07p\x02\x02no\x07i\x02\x02o\x18\x03\x02\x02\x02pq\x07d\x02\x02qr\x07" + + "q\x02\x02rs\x07q\x02\x02st\x07n\x02\x02tu\x07g\x02\x02uv\x07c\x02\x02" + + "vw\x07p\x02\x02w\x1A\x03\x02\x02\x02xy\x07c\x02\x02yz\x07p\x02\x02z{\x07" + + "{\x02\x02{\x1C\x03\x02\x02\x02|}\x07x\x02\x02}~\x07q\x02\x02~\x7F\x07" + + "k\x02\x02\x7F\x80\x07f\x02\x02\x80\x1E\x03\x02\x02\x02\x81\x82\x07p\x02" + + "\x02\x82\x83\x07w\x02\x02\x83\x84\x07n\x02\x02\x84\x85\x07n\x02\x02\x85" + + " \x03\x02\x02\x02\x86\x87\x07w\x02\x02\x87\x88\x07p\x02\x02\x88\x89\x07" + + "f\x02\x02\x89\x8A\x07g\x02\x02\x8A\x8B\x07h\x02\x02\x8B\x8C\x07k\x02\x02" + + "\x8C\x8D\x07p\x02\x02\x8D\x8E\x07g\x02\x02\x8E\x8F\x07f\x02\x02\x8F\"" + + "\x03\x02\x02\x02\x90\x91\x07}\x02\x02\x91$\x03\x02\x02\x02\x92\x93\x07" + + "\x7F\x02\x02\x93&\x03\x02\x02\x02\x94\x95\x07{\x02\x02\x95\x96\x07q\x02" + + "\x02\x96\x97\x07t\x02\x02\x97\x98\x07m\x02\x02\x98\x99\x07k\x02\x02\x99" + + "\x9A\x07g\x02\x02\x9A\x9B\x070\x02\x02\x9B\x9C\x07Q\x02\x02\x9C\x9D\x07" + + "d\x02\x02\x9D\x9E\x07l\x02\x02\x9E\x9F\x07g\x02\x02\x9F\xA0\x07e\x02\x02" + + "\xA0\xA1\x07v\x02\x02\xA1(\x03\x02\x02\x02\xA2\xA3\x07{\x02\x02\xA3\xA4" + + "\x07q\x02\x02\xA4\xA5\x07t\x02\x02\xA5\xA6\x07m\x02\x02\xA6\xA7\x07k\x02" + + "\x02\xA7\xA8\x07g\x02\x02\xA8\xA9\x070\x02\x02\xA9\xAA\x07C\x02\x02\xAA" + + "\xAB\x07t\x02\x02\xAB\xAC\x07t\x02\x02\xAC\xAD\x07c\x02\x02\xAD\xAE\x07" + + "{\x02\x02\xAE*\x03\x02\x02\x02\xAF\xB0\x07{\x02\x02\xB0\xB1\x07q\x02\x02" + + "\xB1\xB2\x07t\x02\x02\xB2\xB3\x07m\x02\x02\xB3\xB4\x07k\x02\x02\xB4\xB5" + + "\x07g\x02\x02\xB5\xB6\x070\x02\x02\xB6\xB7\x07E\x02\x02\xB7\xB8\x07q\x02" + + "\x02\xB8\xB9\x07w\x02\x02\xB9\xBA\x07p\x02\x02\xBA\xBB\x07v\x02\x02\xBB" + + "\xBC\x07g\x02\x02\xBC\xBD\x07t\x02\x02\xBD,\x03\x02\x02\x02\xBE\xBF\x07" + + "{\x02\x02\xBF\xC0\x07q\x02\x02\xC0\xC1\x07t\x02\x02\xC1\xC2\x07m\x02\x02" + + "\xC2\xC3\x07k\x02\x02\xC3\xC4\x07g\x02\x02\xC4\xC5\x070\x02\x02\xC5\xC6" + + "\x07V\x02\x02\xC6\xC7\x07g\x02\x02\xC7\xC8\x07z\x02\x02\xC8\xC9\x07v\x02" + + "\x02\xC9.\x03\x02\x02\x02\xCA\xCB\x07{\x02\x02\xCB\xCC\x07q\x02\x02\xCC" + + "\xCD\x07t\x02\x02\xCD\xCE\x07m\x02\x02\xCE\xCF\x07k\x02\x02\xCF\xD0\x07" + + "g\x02\x02\xD0\xD1\x070\x02\x02\xD1\xD2\x07V\x02\x02\xD2\xD3\x07t\x02\x02" + + "\xD3\xD4\x07g\x02\x02\xD4\xD5\x07g\x02\x02\xD50\x03\x02\x02\x02\xD6\xD7" + + "\x07*\x02\x02\xD72\x03\x02\x02\x02\xD8\xD9\x07+\x02\x02\xD94\x03\x02\x02" + + "\x02\xDA\xDB\x07>\x02\x02\xDB6\x03\x02\x02\x02\xDC\xDD\x07.\x02\x02\xDD" + + "8\x03\x02\x02\x02\xDE\xDF\x07@\x02\x02\xDF:\x03\x02\x02\x02\xE0\xE1\x07" + + "g\x02\x02\xE1\xE2\x07z\x02\x02\xE2\xE3\x07v\x02\x02\xE3\xE4\x07g\x02\x02" + + "\xE4\xE5\x07p\x02\x02\xE5\xE6\x07f\x02\x02\xE6\xE7\x07u\x02\x02\xE7<\x03" + + "\x02\x02\x02\xE8\xEC\t\x02\x02\x02\xE9\xEB\t\x03\x02\x02\xEA\xE9\x03\x02" + + "\x02\x02\xEB\xEE\x03\x02\x02\x02\xEC\xEA\x03\x02\x02\x02\xEC\xED\x03\x02" + + "\x02\x02\xED>\x03\x02\x02\x02\xEE\xEC\x03\x02\x02\x02\xEF\xF3\x07$\x02" + + "\x02\xF0\xF2\n\x04\x02\x02\xF1\xF0\x03\x02\x02\x02\xF2\xF5\x03\x02\x02" + + "\x02\xF3\xF1\x03\x02\x02\x02\xF3\xF4\x03\x02\x02\x02\xF4\xF6\x03\x02\x02" + + "\x02\xF5\xF3\x03\x02\x02\x02\xF6\xF7\x07$\x02\x02\xF7@\x03\x02\x02\x02" + + "\xF8\xFA\t\x05\x02\x02\xF9\xF8\x03\x02\x02\x02\xFA\xFB\x03\x02\x02\x02" + + "\xFB\xF9\x03\x02\x02\x02\xFB\xFC\x03\x02\x02\x02\xFC\u0103\x03\x02\x02" + + "\x02\xFD\xFF\x070\x02\x02\xFE\u0100\t\x05\x02\x02\xFF\xFE\x03\x02\x02" + + "\x02\u0100\u0101\x03\x02\x02\x02\u0101\xFF\x03\x02\x02\x02\u0101\u0102" + + "\x03\x02\x02\x02\u0102\u0104\x03\x02\x02\x02\u0103\xFD\x03\x02\x02\x02" + + "\u0103\u0104\x03\x02\x02\x02\u0104B\x03\x02\x02\x02\u0105\u0106\x07v\x02" + + "\x02\u0106\u0107\x07t\x02\x02\u0107\u0108\x07w\x02\x02\u0108\u010F\x07" + + "g\x02\x02\u0109\u010A\x07h\x02\x02\u010A\u010B\x07c\x02\x02\u010B\u010C" + + "\x07n\x02\x02\u010C\u010D\x07u\x02\x02\u010D\u010F\x07g\x02\x02\u010E" + + "\u0105\x03\x02\x02\x02\u010E\u0109\x03\x02\x02\x02\u010FD\x03\x02\x02" + + "\x02\u0110\u0111\x071\x02\x02\u0111\u0112\x071\x02\x02\u0112\u0116\x03" + + "\x02\x02\x02\u0113\u0115\n\x06\x02\x02\u0114\u0113\x03\x02\x02\x02\u0115" + + "\u0118\x03\x02\x02\x02\u0116\u0114\x03\x02\x02\x02\u0116\u0117\x03\x02" + + "\x02\x02\u0117\u0119\x03\x02\x02\x02\u0118\u0116\x03\x02\x02\x02\u0119" + + "\u011A\b#\x02\x02\u011AF\x03\x02\x02\x02\u011B\u011C\x071\x02\x02\u011C" + + "\u011D\x07,\x02\x02\u011D\u0121\x03\x02\x02\x02\u011E\u0120\v\x02\x02" + + "\x02\u011F\u011E\x03\x02\x02\x02\u0120\u0123\x03\x02\x02\x02\u0121\u0122" + + "\x03\x02\x02\x02\u0121\u011F\x03\x02\x02\x02\u0122\u0124\x03\x02\x02\x02" + + "\u0123\u0121\x03\x02\x02\x02\u0124\u0125\x07,\x02\x02\u0125\u0126\x07" + + "1\x02\x02\u0126\u0127\x03\x02\x02\x02\u0127\u0128\b$\x02\x02\u0128H\x03" + + "\x02\x02\x02\u0129\u012B\t\x07\x02\x02\u012A\u0129\x03\x02\x02\x02\u012B" + + "\u012C\x03\x02\x02\x02\u012C\u012A\x03\x02\x02\x02\u012C\u012D\x03\x02" + + "\x02\x02\u012D\u012E\x03\x02\x02\x02\u012E\u012F\b%\x03\x02\u012FJ\x03" + + "\x02\x02\x02\f\x02\xEC\xF3\xFB\u0101\u0103\u010E\u0116\u0121\u012C\x04" + + "\x02\x03\x02\b\x02\x02"; + public static __ATN: ATN; + public static get _ATN(): ATN { + if (!YorkieSchemaLexer.__ATN) { + YorkieSchemaLexer.__ATN = new ATNDeserializer().deserialize(Utils.toCharArray(YorkieSchemaLexer._serializedATN)); + } + + return YorkieSchemaLexer.__ATN; + } + +} + diff --git a/antlr/YorkieSchemaListener.ts b/antlr/YorkieSchemaListener.ts new file mode 100644 index 0000000..68894b1 --- /dev/null +++ b/antlr/YorkieSchemaListener.ts @@ -0,0 +1,277 @@ +// Generated from antlr/YorkieSchema.g4 by ANTLR 4.9.0-SNAPSHOT + + +import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; + +import { DocumentContext } from "./YorkieSchemaParser"; +import { DeclarationContext } from "./YorkieSchemaParser"; +import { TypeAliasDeclarationContext } from "./YorkieSchemaParser"; +import { VariableDeclarationContext } from "./YorkieSchemaParser"; +import { TypeAnnotationContext } from "./YorkieSchemaParser"; +import { TypeContext } from "./YorkieSchemaParser"; +import { UnionTypeContext } from "./YorkieSchemaParser"; +import { IntersectionTypeContext } from "./YorkieSchemaParser"; +import { ArrayTypeContext } from "./YorkieSchemaParser"; +import { PrimaryTypeContext } from "./YorkieSchemaParser"; +import { PrimitiveTypeContext } from "./YorkieSchemaParser"; +import { ObjectTypeContext } from "./YorkieSchemaParser"; +import { PropertySignatureContext } from "./YorkieSchemaParser"; +import { PropertyNameContext } from "./YorkieSchemaParser"; +import { YorkieTypeContext } from "./YorkieSchemaParser"; +import { TypeReferenceContext } from "./YorkieSchemaParser"; +import { ParenthesizedTypeContext } from "./YorkieSchemaParser"; +import { TypeParametersContext } from "./YorkieSchemaParser"; +import { TypeParameterContext } from "./YorkieSchemaParser"; +import { TypeArgumentsContext } from "./YorkieSchemaParser"; +import { ExpressionContext } from "./YorkieSchemaParser"; +import { LiteralContext } from "./YorkieSchemaParser"; + + +/** + * This interface defines a complete listener for a parse tree produced by + * `YorkieSchemaParser`. + */ +export interface YorkieSchemaListener extends ParseTreeListener { + /** + * Enter a parse tree produced by `YorkieSchemaParser.document`. + * @param ctx the parse tree + */ + enterDocument?: (ctx: DocumentContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.document`. + * @param ctx the parse tree + */ + exitDocument?: (ctx: DocumentContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.declaration`. + * @param ctx the parse tree + */ + enterDeclaration?: (ctx: DeclarationContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.declaration`. + * @param ctx the parse tree + */ + exitDeclaration?: (ctx: DeclarationContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeAliasDeclaration`. + * @param ctx the parse tree + */ + enterTypeAliasDeclaration?: (ctx: TypeAliasDeclarationContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeAliasDeclaration`. + * @param ctx the parse tree + */ + exitTypeAliasDeclaration?: (ctx: TypeAliasDeclarationContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.variableDeclaration`. + * @param ctx the parse tree + */ + enterVariableDeclaration?: (ctx: VariableDeclarationContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.variableDeclaration`. + * @param ctx the parse tree + */ + exitVariableDeclaration?: (ctx: VariableDeclarationContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeAnnotation`. + * @param ctx the parse tree + */ + enterTypeAnnotation?: (ctx: TypeAnnotationContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeAnnotation`. + * @param ctx the parse tree + */ + exitTypeAnnotation?: (ctx: TypeAnnotationContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.type`. + * @param ctx the parse tree + */ + enterType?: (ctx: TypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.type`. + * @param ctx the parse tree + */ + exitType?: (ctx: TypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.unionType`. + * @param ctx the parse tree + */ + enterUnionType?: (ctx: UnionTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.unionType`. + * @param ctx the parse tree + */ + exitUnionType?: (ctx: UnionTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.intersectionType`. + * @param ctx the parse tree + */ + enterIntersectionType?: (ctx: IntersectionTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.intersectionType`. + * @param ctx the parse tree + */ + exitIntersectionType?: (ctx: IntersectionTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.arrayType`. + * @param ctx the parse tree + */ + enterArrayType?: (ctx: ArrayTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.arrayType`. + * @param ctx the parse tree + */ + exitArrayType?: (ctx: ArrayTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.primaryType`. + * @param ctx the parse tree + */ + enterPrimaryType?: (ctx: PrimaryTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.primaryType`. + * @param ctx the parse tree + */ + exitPrimaryType?: (ctx: PrimaryTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.primitiveType`. + * @param ctx the parse tree + */ + enterPrimitiveType?: (ctx: PrimitiveTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.primitiveType`. + * @param ctx the parse tree + */ + exitPrimitiveType?: (ctx: PrimitiveTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.objectType`. + * @param ctx the parse tree + */ + enterObjectType?: (ctx: ObjectTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.objectType`. + * @param ctx the parse tree + */ + exitObjectType?: (ctx: ObjectTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.propertySignature`. + * @param ctx the parse tree + */ + enterPropertySignature?: (ctx: PropertySignatureContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.propertySignature`. + * @param ctx the parse tree + */ + exitPropertySignature?: (ctx: PropertySignatureContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.propertyName`. + * @param ctx the parse tree + */ + enterPropertyName?: (ctx: PropertyNameContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.propertyName`. + * @param ctx the parse tree + */ + exitPropertyName?: (ctx: PropertyNameContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.yorkieType`. + * @param ctx the parse tree + */ + enterYorkieType?: (ctx: YorkieTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.yorkieType`. + * @param ctx the parse tree + */ + exitYorkieType?: (ctx: YorkieTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeReference`. + * @param ctx the parse tree + */ + enterTypeReference?: (ctx: TypeReferenceContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeReference`. + * @param ctx the parse tree + */ + exitTypeReference?: (ctx: TypeReferenceContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.parenthesizedType`. + * @param ctx the parse tree + */ + enterParenthesizedType?: (ctx: ParenthesizedTypeContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.parenthesizedType`. + * @param ctx the parse tree + */ + exitParenthesizedType?: (ctx: ParenthesizedTypeContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeParameters`. + * @param ctx the parse tree + */ + enterTypeParameters?: (ctx: TypeParametersContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeParameters`. + * @param ctx the parse tree + */ + exitTypeParameters?: (ctx: TypeParametersContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeParameter`. + * @param ctx the parse tree + */ + enterTypeParameter?: (ctx: TypeParameterContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeParameter`. + * @param ctx the parse tree + */ + exitTypeParameter?: (ctx: TypeParameterContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.typeArguments`. + * @param ctx the parse tree + */ + enterTypeArguments?: (ctx: TypeArgumentsContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.typeArguments`. + * @param ctx the parse tree + */ + exitTypeArguments?: (ctx: TypeArgumentsContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.expression`. + * @param ctx the parse tree + */ + enterExpression?: (ctx: ExpressionContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.expression`. + * @param ctx the parse tree + */ + exitExpression?: (ctx: ExpressionContext) => void; + + /** + * Enter a parse tree produced by `YorkieSchemaParser.literal`. + * @param ctx the parse tree + */ + enterLiteral?: (ctx: LiteralContext) => void; + /** + * Exit a parse tree produced by `YorkieSchemaParser.literal`. + * @param ctx the parse tree + */ + exitLiteral?: (ctx: LiteralContext) => void; +} + diff --git a/antlr/YorkieSchemaParser.ts b/antlr/YorkieSchemaParser.ts new file mode 100644 index 0000000..cdb8d08 --- /dev/null +++ b/antlr/YorkieSchemaParser.ts @@ -0,0 +1,1860 @@ +// Generated from antlr/YorkieSchema.g4 by ANTLR 4.9.0-SNAPSHOT + + +import { ATN } from "antlr4ts/atn/ATN"; +import { ATNDeserializer } from "antlr4ts/atn/ATNDeserializer"; +import { FailedPredicateException } from "antlr4ts/FailedPredicateException"; +import { NotNull } from "antlr4ts/Decorators"; +import { NoViableAltException } from "antlr4ts/NoViableAltException"; +import { Override } from "antlr4ts/Decorators"; +import { Parser } from "antlr4ts/Parser"; +import { ParserRuleContext } from "antlr4ts/ParserRuleContext"; +import { ParserATNSimulator } from "antlr4ts/atn/ParserATNSimulator"; +import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; +import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; +import { RecognitionException } from "antlr4ts/RecognitionException"; +import { RuleContext } from "antlr4ts/RuleContext"; +//import { RuleVersion } from "antlr4ts/RuleVersion"; +import { TerminalNode } from "antlr4ts/tree/TerminalNode"; +import { Token } from "antlr4ts/Token"; +import { TokenStream } from "antlr4ts/TokenStream"; +import { Vocabulary } from "antlr4ts/Vocabulary"; +import { VocabularyImpl } from "antlr4ts/VocabularyImpl"; + +import * as Utils from "antlr4ts/misc/Utils"; + +import { YorkieSchemaListener } from "./YorkieSchemaListener"; +import { YorkieSchemaVisitor } from "./YorkieSchemaVisitor"; + + +export class YorkieSchemaParser extends Parser { + public static readonly T__0 = 1; + public static readonly T__1 = 2; + public static readonly T__2 = 3; + public static readonly T__3 = 4; + public static readonly T__4 = 5; + public static readonly T__5 = 6; + public static readonly T__6 = 7; + public static readonly T__7 = 8; + public static readonly T__8 = 9; + public static readonly T__9 = 10; + public static readonly T__10 = 11; + public static readonly T__11 = 12; + public static readonly T__12 = 13; + public static readonly T__13 = 14; + public static readonly T__14 = 15; + public static readonly T__15 = 16; + public static readonly T__16 = 17; + public static readonly T__17 = 18; + public static readonly T__18 = 19; + public static readonly T__19 = 20; + public static readonly T__20 = 21; + public static readonly T__21 = 22; + public static readonly T__22 = 23; + public static readonly T__23 = 24; + public static readonly T__24 = 25; + public static readonly T__25 = 26; + public static readonly T__26 = 27; + public static readonly T__27 = 28; + public static readonly T__28 = 29; + public static readonly Identifier = 30; + public static readonly StringLiteral = 31; + public static readonly NumberLiteral = 32; + public static readonly BooleanLiteral = 33; + public static readonly SingleLineComment = 34; + public static readonly MultiLineComment = 35; + public static readonly WS = 36; + public static readonly RULE_document = 0; + public static readonly RULE_declaration = 1; + public static readonly RULE_typeAliasDeclaration = 2; + public static readonly RULE_variableDeclaration = 3; + public static readonly RULE_typeAnnotation = 4; + public static readonly RULE_type = 5; + public static readonly RULE_unionType = 6; + public static readonly RULE_intersectionType = 7; + public static readonly RULE_arrayType = 8; + public static readonly RULE_primaryType = 9; + public static readonly RULE_primitiveType = 10; + public static readonly RULE_objectType = 11; + public static readonly RULE_propertySignature = 12; + public static readonly RULE_propertyName = 13; + public static readonly RULE_yorkieType = 14; + public static readonly RULE_typeReference = 15; + public static readonly RULE_parenthesizedType = 16; + public static readonly RULE_typeParameters = 17; + public static readonly RULE_typeParameter = 18; + public static readonly RULE_typeArguments = 19; + public static readonly RULE_expression = 20; + public static readonly RULE_literal = 21; + // tslint:disable:no-trailing-whitespace + public static readonly ruleNames: string[] = [ + "document", "declaration", "typeAliasDeclaration", "variableDeclaration", + "typeAnnotation", "type", "unionType", "intersectionType", "arrayType", + "primaryType", "primitiveType", "objectType", "propertySignature", "propertyName", + "yorkieType", "typeReference", "parenthesizedType", "typeParameters", + "typeParameter", "typeArguments", "expression", "literal", + ]; + + private static readonly _LITERAL_NAMES: Array = [ + undefined, "'type'", "'='", "';'", "'let'", "':'", "'|'", "'&'", "'['", + "']'", "'number'", "'string'", "'boolean'", "'any'", "'void'", "'null'", + "'undefined'", "'{'", "'}'", "'yorkie.Object'", "'yorkie.Array'", "'yorkie.Counter'", + "'yorkie.Text'", "'yorkie.Tree'", "'('", "')'", "'<'", "','", "'>'", "'extends'", + ]; + private static readonly _SYMBOLIC_NAMES: Array = [ + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, "Identifier", "StringLiteral", "NumberLiteral", + "BooleanLiteral", "SingleLineComment", "MultiLineComment", "WS", + ]; + public static readonly VOCABULARY: Vocabulary = new VocabularyImpl(YorkieSchemaParser._LITERAL_NAMES, YorkieSchemaParser._SYMBOLIC_NAMES, []); + + // @Override + // @NotNull + public get vocabulary(): Vocabulary { + return YorkieSchemaParser.VOCABULARY; + } + // tslint:enable:no-trailing-whitespace + + // @Override + public get grammarFileName(): string { return "YorkieSchema.g4"; } + + // @Override + public get ruleNames(): string[] { return YorkieSchemaParser.ruleNames; } + + // @Override + public get serializedATN(): string { return YorkieSchemaParser._serializedATN; } + + protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException { + return new FailedPredicateException(this, predicate, message); + } + + constructor(input: TokenStream) { + super(input); + this._interp = new ParserATNSimulator(YorkieSchemaParser._ATN, this); + } + // @RuleVersion(0) + public document(): DocumentContext { + let _localctx: DocumentContext = new DocumentContext(this._ctx, this.state); + this.enterRule(_localctx, 0, YorkieSchemaParser.RULE_document); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 47; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__0 || _la === YorkieSchemaParser.T__3) { + { + { + this.state = 44; + this.declaration(); + } + } + this.state = 49; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + this.state = 50; + this.match(YorkieSchemaParser.EOF); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public declaration(): DeclarationContext { + let _localctx: DeclarationContext = new DeclarationContext(this._ctx, this.state); + this.enterRule(_localctx, 2, YorkieSchemaParser.RULE_declaration); + try { + this.state = 54; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case YorkieSchemaParser.T__0: + this.enterOuterAlt(_localctx, 1); + { + this.state = 52; + this.typeAliasDeclaration(); + } + break; + case YorkieSchemaParser.T__3: + this.enterOuterAlt(_localctx, 2); + { + this.state = 53; + this.variableDeclaration(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeAliasDeclaration(): TypeAliasDeclarationContext { + let _localctx: TypeAliasDeclarationContext = new TypeAliasDeclarationContext(this._ctx, this.state); + this.enterRule(_localctx, 4, YorkieSchemaParser.RULE_typeAliasDeclaration); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 56; + this.match(YorkieSchemaParser.T__0); + this.state = 57; + this.match(YorkieSchemaParser.Identifier); + this.state = 59; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la === YorkieSchemaParser.T__25) { + { + this.state = 58; + this.typeParameters(); + } + } + + this.state = 61; + this.match(YorkieSchemaParser.T__1); + this.state = 62; + this.type(); + this.state = 63; + this.match(YorkieSchemaParser.T__2); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public variableDeclaration(): VariableDeclarationContext { + let _localctx: VariableDeclarationContext = new VariableDeclarationContext(this._ctx, this.state); + this.enterRule(_localctx, 6, YorkieSchemaParser.RULE_variableDeclaration); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 65; + this.match(YorkieSchemaParser.T__3); + this.state = 66; + this.match(YorkieSchemaParser.Identifier); + this.state = 68; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la === YorkieSchemaParser.T__4) { + { + this.state = 67; + this.typeAnnotation(); + } + } + + this.state = 72; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la === YorkieSchemaParser.T__1) { + { + this.state = 70; + this.match(YorkieSchemaParser.T__1); + this.state = 71; + this.expression(); + } + } + + this.state = 74; + this.match(YorkieSchemaParser.T__2); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeAnnotation(): TypeAnnotationContext { + let _localctx: TypeAnnotationContext = new TypeAnnotationContext(this._ctx, this.state); + this.enterRule(_localctx, 8, YorkieSchemaParser.RULE_typeAnnotation); + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 76; + this.match(YorkieSchemaParser.T__4); + this.state = 77; + this.type(); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public type(): TypeContext { + let _localctx: TypeContext = new TypeContext(this._ctx, this.state); + this.enterRule(_localctx, 10, YorkieSchemaParser.RULE_type); + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 79; + this.unionType(); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public unionType(): UnionTypeContext { + let _localctx: UnionTypeContext = new UnionTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 12, YorkieSchemaParser.RULE_unionType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 81; + this.intersectionType(); + this.state = 86; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__5) { + { + { + this.state = 82; + this.match(YorkieSchemaParser.T__5); + this.state = 83; + this.intersectionType(); + } + } + this.state = 88; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public intersectionType(): IntersectionTypeContext { + let _localctx: IntersectionTypeContext = new IntersectionTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 14, YorkieSchemaParser.RULE_intersectionType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 89; + this.arrayType(); + this.state = 94; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__6) { + { + { + this.state = 90; + this.match(YorkieSchemaParser.T__6); + this.state = 91; + this.arrayType(); + } + } + this.state = 96; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public arrayType(): ArrayTypeContext { + let _localctx: ArrayTypeContext = new ArrayTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 16, YorkieSchemaParser.RULE_arrayType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 97; + this.primaryType(); + this.state = 102; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__7) { + { + { + this.state = 98; + this.match(YorkieSchemaParser.T__7); + this.state = 99; + this.match(YorkieSchemaParser.T__8); + } + } + this.state = 104; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public primaryType(): PrimaryTypeContext { + let _localctx: PrimaryTypeContext = new PrimaryTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 18, YorkieSchemaParser.RULE_primaryType); + try { + this.state = 110; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case YorkieSchemaParser.T__23: + this.enterOuterAlt(_localctx, 1); + { + this.state = 105; + this.parenthesizedType(); + } + break; + case YorkieSchemaParser.T__9: + case YorkieSchemaParser.T__10: + case YorkieSchemaParser.T__11: + case YorkieSchemaParser.T__12: + case YorkieSchemaParser.T__13: + case YorkieSchemaParser.T__14: + case YorkieSchemaParser.T__15: + this.enterOuterAlt(_localctx, 2); + { + this.state = 106; + this.primitiveType(); + } + break; + case YorkieSchemaParser.T__16: + this.enterOuterAlt(_localctx, 3); + { + this.state = 107; + this.objectType(); + } + break; + case YorkieSchemaParser.T__18: + case YorkieSchemaParser.T__19: + case YorkieSchemaParser.T__20: + case YorkieSchemaParser.T__21: + case YorkieSchemaParser.T__22: + this.enterOuterAlt(_localctx, 4); + { + this.state = 108; + this.yorkieType(); + } + break; + case YorkieSchemaParser.Identifier: + this.enterOuterAlt(_localctx, 5); + { + this.state = 109; + this.typeReference(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public primitiveType(): PrimitiveTypeContext { + let _localctx: PrimitiveTypeContext = new PrimitiveTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 20, YorkieSchemaParser.RULE_primitiveType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 112; + _la = this._input.LA(1); + if (!((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << YorkieSchemaParser.T__9) | (1 << YorkieSchemaParser.T__10) | (1 << YorkieSchemaParser.T__11) | (1 << YorkieSchemaParser.T__12) | (1 << YorkieSchemaParser.T__13) | (1 << YorkieSchemaParser.T__14) | (1 << YorkieSchemaParser.T__15))) !== 0))) { + this._errHandler.recoverInline(this); + } else { + if (this._input.LA(1) === Token.EOF) { + this.matchedEOF = true; + } + + this._errHandler.reportMatch(this); + this.consume(); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public objectType(): ObjectTypeContext { + let _localctx: ObjectTypeContext = new ObjectTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 22, YorkieSchemaParser.RULE_objectType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 114; + this.match(YorkieSchemaParser.T__16); + this.state = 118; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.Identifier || _la === YorkieSchemaParser.StringLiteral) { + { + { + this.state = 115; + this.propertySignature(); + } + } + this.state = 120; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + this.state = 121; + this.match(YorkieSchemaParser.T__17); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public propertySignature(): PropertySignatureContext { + let _localctx: PropertySignatureContext = new PropertySignatureContext(this._ctx, this.state); + this.enterRule(_localctx, 24, YorkieSchemaParser.RULE_propertySignature); + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 123; + this.propertyName(); + this.state = 124; + this.typeAnnotation(); + this.state = 125; + this.match(YorkieSchemaParser.T__2); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public propertyName(): PropertyNameContext { + let _localctx: PropertyNameContext = new PropertyNameContext(this._ctx, this.state); + this.enterRule(_localctx, 26, YorkieSchemaParser.RULE_propertyName); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 127; + _la = this._input.LA(1); + if (!(_la === YorkieSchemaParser.Identifier || _la === YorkieSchemaParser.StringLiteral)) { + this._errHandler.recoverInline(this); + } else { + if (this._input.LA(1) === Token.EOF) { + this.matchedEOF = true; + } + + this._errHandler.reportMatch(this); + this.consume(); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public yorkieType(): YorkieTypeContext { + let _localctx: YorkieTypeContext = new YorkieTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 28, YorkieSchemaParser.RULE_yorkieType); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 129; + _la = this._input.LA(1); + if (!((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << YorkieSchemaParser.T__18) | (1 << YorkieSchemaParser.T__19) | (1 << YorkieSchemaParser.T__20) | (1 << YorkieSchemaParser.T__21) | (1 << YorkieSchemaParser.T__22))) !== 0))) { + this._errHandler.recoverInline(this); + } else { + if (this._input.LA(1) === Token.EOF) { + this.matchedEOF = true; + } + + this._errHandler.reportMatch(this); + this.consume(); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeReference(): TypeReferenceContext { + let _localctx: TypeReferenceContext = new TypeReferenceContext(this._ctx, this.state); + this.enterRule(_localctx, 30, YorkieSchemaParser.RULE_typeReference); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 131; + this.match(YorkieSchemaParser.Identifier); + this.state = 133; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la === YorkieSchemaParser.T__25) { + { + this.state = 132; + this.typeArguments(); + } + } + + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public parenthesizedType(): ParenthesizedTypeContext { + let _localctx: ParenthesizedTypeContext = new ParenthesizedTypeContext(this._ctx, this.state); + this.enterRule(_localctx, 32, YorkieSchemaParser.RULE_parenthesizedType); + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 135; + this.match(YorkieSchemaParser.T__23); + this.state = 136; + this.type(); + this.state = 137; + this.match(YorkieSchemaParser.T__24); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeParameters(): TypeParametersContext { + let _localctx: TypeParametersContext = new TypeParametersContext(this._ctx, this.state); + this.enterRule(_localctx, 34, YorkieSchemaParser.RULE_typeParameters); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 139; + this.match(YorkieSchemaParser.T__25); + this.state = 140; + this.typeParameter(); + this.state = 145; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__26) { + { + { + this.state = 141; + this.match(YorkieSchemaParser.T__26); + this.state = 142; + this.typeParameter(); + } + } + this.state = 147; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + this.state = 148; + this.match(YorkieSchemaParser.T__27); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeParameter(): TypeParameterContext { + let _localctx: TypeParameterContext = new TypeParameterContext(this._ctx, this.state); + this.enterRule(_localctx, 36, YorkieSchemaParser.RULE_typeParameter); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 150; + this.match(YorkieSchemaParser.Identifier); + this.state = 153; + this._errHandler.sync(this); + _la = this._input.LA(1); + if (_la === YorkieSchemaParser.T__28) { + { + this.state = 151; + this.match(YorkieSchemaParser.T__28); + this.state = 152; + this.type(); + } + } + + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public typeArguments(): TypeArgumentsContext { + let _localctx: TypeArgumentsContext = new TypeArgumentsContext(this._ctx, this.state); + this.enterRule(_localctx, 38, YorkieSchemaParser.RULE_typeArguments); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 155; + this.match(YorkieSchemaParser.T__25); + this.state = 156; + this.type(); + this.state = 161; + this._errHandler.sync(this); + _la = this._input.LA(1); + while (_la === YorkieSchemaParser.T__26) { + { + { + this.state = 157; + this.match(YorkieSchemaParser.T__26); + this.state = 158; + this.type(); + } + } + this.state = 163; + this._errHandler.sync(this); + _la = this._input.LA(1); + } + this.state = 164; + this.match(YorkieSchemaParser.T__27); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public expression(): ExpressionContext { + let _localctx: ExpressionContext = new ExpressionContext(this._ctx, this.state); + this.enterRule(_localctx, 40, YorkieSchemaParser.RULE_expression); + try { + this.state = 168; + this._errHandler.sync(this); + switch (this._input.LA(1)) { + case YorkieSchemaParser.Identifier: + this.enterOuterAlt(_localctx, 1); + { + this.state = 166; + this.match(YorkieSchemaParser.Identifier); + } + break; + case YorkieSchemaParser.StringLiteral: + case YorkieSchemaParser.NumberLiteral: + case YorkieSchemaParser.BooleanLiteral: + this.enterOuterAlt(_localctx, 2); + { + this.state = 167; + this.literal(); + } + break; + default: + throw new NoViableAltException(this); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) + public literal(): LiteralContext { + let _localctx: LiteralContext = new LiteralContext(this._ctx, this.state); + this.enterRule(_localctx, 42, YorkieSchemaParser.RULE_literal); + let _la: number; + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 170; + _la = this._input.LA(1); + if (!(((((_la - 31)) & ~0x1F) === 0 && ((1 << (_la - 31)) & ((1 << (YorkieSchemaParser.StringLiteral - 31)) | (1 << (YorkieSchemaParser.NumberLiteral - 31)) | (1 << (YorkieSchemaParser.BooleanLiteral - 31)))) !== 0))) { + this._errHandler.recoverInline(this); + } else { + if (this._input.LA(1) === Token.EOF) { + this.matchedEOF = true; + } + + this._errHandler.reportMatch(this); + this.consume(); + } + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + + public static readonly _serializedATN: string = + "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x03&\xAF\x04\x02" + + "\t\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06\x04\x07" + + "\t\x07\x04\b\t\b\x04\t\t\t\x04\n\t\n\x04\v\t\v\x04\f\t\f\x04\r\t\r\x04" + + "\x0E\t\x0E\x04\x0F\t\x0F\x04\x10\t\x10\x04\x11\t\x11\x04\x12\t\x12\x04" + + "\x13\t\x13\x04\x14\t\x14\x04\x15\t\x15\x04\x16\t\x16\x04\x17\t\x17\x03" + + "\x02\x07\x020\n\x02\f\x02\x0E\x023\v\x02\x03\x02\x03\x02\x03\x03\x03\x03" + + "\x05\x039\n\x03\x03\x04\x03\x04\x03\x04\x05\x04>\n\x04\x03\x04\x03\x04" + + "\x03\x04\x03\x04\x03\x05\x03\x05\x03\x05\x05\x05G\n\x05\x03\x05\x03\x05" + + "\x05\x05K\n\x05\x03\x05\x03\x05\x03\x06\x03\x06\x03\x06\x03\x07\x03\x07" + + "\x03\b\x03\b\x03\b\x07\bW\n\b\f\b\x0E\bZ\v\b\x03\t\x03\t\x03\t\x07\t_" + + "\n\t\f\t\x0E\tb\v\t\x03\n\x03\n\x03\n\x07\ng\n\n\f\n\x0E\nj\v\n\x03\v" + + "\x03\v\x03\v\x03\v\x03\v\x05\vq\n\v\x03\f\x03\f\x03\r\x03\r\x07\rw\n\r" + + "\f\r\x0E\rz\v\r\x03\r\x03\r\x03\x0E\x03\x0E\x03\x0E\x03\x0E\x03\x0F\x03" + + "\x0F\x03\x10\x03\x10\x03\x11\x03\x11\x05\x11\x88\n\x11\x03\x12\x03\x12" + + "\x03\x12\x03\x12\x03\x13\x03\x13\x03\x13\x03\x13\x07\x13\x92\n\x13\f\x13" + + "\x0E\x13\x95\v\x13\x03\x13\x03\x13\x03\x14\x03\x14\x03\x14\x05\x14\x9C" + + "\n\x14\x03\x15\x03\x15\x03\x15\x03\x15\x07\x15\xA2\n\x15\f\x15\x0E\x15" + + "\xA5\v\x15\x03\x15\x03\x15\x03\x16\x03\x16\x05\x16\xAB\n\x16\x03\x17\x03" + + "\x17\x03\x17\x02\x02\x02\x18\x02\x02\x04\x02\x06\x02\b\x02\n\x02\f\x02" + + "\x0E\x02\x10\x02\x12\x02\x14\x02\x16\x02\x18\x02\x1A\x02\x1C\x02\x1E\x02" + + " \x02\"\x02$\x02&\x02(\x02*\x02,\x02\x02\x06\x03\x02\f\x12\x03\x02 !\x03" + + "\x02\x15\x19\x03\x02!#\x02\xAA\x021\x03\x02\x02\x02\x048\x03\x02\x02\x02" + + "\x06:\x03\x02\x02\x02\bC\x03\x02\x02\x02\nN\x03\x02\x02\x02\fQ\x03\x02" + + "\x02\x02\x0ES\x03\x02\x02\x02\x10[\x03\x02\x02\x02\x12c\x03\x02\x02\x02" + + "\x14p\x03\x02\x02\x02\x16r\x03\x02\x02\x02\x18t\x03\x02\x02\x02\x1A}\x03" + + "\x02\x02\x02\x1C\x81\x03\x02\x02\x02\x1E\x83\x03\x02\x02\x02 \x85\x03" + + "\x02\x02\x02\"\x89\x03\x02\x02\x02$\x8D\x03\x02\x02\x02&\x98\x03\x02\x02" + + "\x02(\x9D\x03\x02\x02\x02*\xAA\x03\x02\x02\x02,\xAC\x03\x02\x02\x02.0" + + "\x05\x04\x03\x02/.\x03\x02\x02\x0203\x03\x02\x02\x021/\x03\x02\x02\x02" + + "12\x03\x02\x02\x0224\x03\x02\x02\x0231\x03\x02\x02\x0245\x07\x02\x02\x03" + + "5\x03\x03\x02\x02\x0269\x05\x06\x04\x0279\x05\b\x05\x0286\x03\x02\x02" + + "\x0287\x03\x02\x02\x029\x05\x03\x02\x02\x02:;\x07\x03\x02\x02;=\x07 \x02" + + "\x02<>\x05$\x13\x02=<\x03\x02\x02\x02=>\x03\x02\x02\x02>?\x03\x02\x02" + + "\x02?@\x07\x04\x02\x02@A\x05\f\x07\x02AB\x07\x05\x02\x02B\x07\x03\x02" + + "\x02\x02CD\x07\x06\x02\x02DF\x07 \x02\x02EG\x05\n\x06\x02FE\x03\x02\x02" + + "\x02FG\x03\x02\x02\x02GJ\x03\x02\x02\x02HI\x07\x04\x02\x02IK\x05*\x16" + + "\x02JH\x03\x02\x02\x02JK\x03\x02\x02\x02KL\x03\x02\x02\x02LM\x07\x05\x02" + + "\x02M\t\x03\x02\x02\x02NO\x07\x07\x02\x02OP\x05\f\x07\x02P\v\x03\x02\x02" + + "\x02QR\x05\x0E\b\x02R\r\x03\x02\x02\x02SX\x05\x10\t\x02TU\x07\b\x02\x02" + + "UW\x05\x10\t\x02VT\x03\x02\x02\x02WZ\x03\x02\x02\x02XV\x03\x02\x02\x02" + + "XY\x03\x02\x02\x02Y\x0F\x03\x02\x02\x02ZX\x03\x02\x02\x02[`\x05\x12\n" + + "\x02\\]\x07\t\x02\x02]_\x05\x12\n\x02^\\\x03\x02\x02\x02_b\x03\x02\x02" + + "\x02`^\x03\x02\x02\x02`a\x03\x02\x02\x02a\x11\x03\x02\x02\x02b`\x03\x02" + + "\x02\x02ch\x05\x14\v\x02de\x07\n\x02\x02eg\x07\v\x02\x02fd\x03\x02\x02" + + "\x02gj\x03\x02\x02\x02hf\x03\x02\x02\x02hi\x03\x02\x02\x02i\x13\x03\x02" + + "\x02\x02jh\x03\x02\x02\x02kq\x05\"\x12\x02lq\x05\x16\f\x02mq\x05\x18\r" + + "\x02nq\x05\x1E\x10\x02oq\x05 \x11\x02pk\x03\x02\x02\x02pl\x03\x02\x02" + + "\x02pm\x03\x02\x02\x02pn\x03\x02\x02\x02po\x03\x02\x02\x02q\x15\x03\x02" + + "\x02\x02rs\t\x02\x02\x02s\x17\x03\x02\x02\x02tx\x07\x13\x02\x02uw\x05" + + "\x1A\x0E\x02vu\x03\x02\x02\x02wz\x03\x02\x02\x02xv\x03\x02\x02\x02xy\x03" + + "\x02\x02\x02y{\x03\x02\x02\x02zx\x03\x02\x02\x02{|\x07\x14\x02\x02|\x19" + + "\x03\x02\x02\x02}~\x05\x1C\x0F\x02~\x7F\x05\n\x06\x02\x7F\x80\x07\x05" + + "\x02\x02\x80\x1B\x03\x02\x02\x02\x81\x82\t\x03\x02\x02\x82\x1D\x03\x02" + + "\x02\x02\x83\x84\t\x04\x02\x02\x84\x1F\x03\x02\x02\x02\x85\x87\x07 \x02" + + "\x02\x86\x88\x05(\x15\x02\x87\x86\x03\x02\x02\x02\x87\x88\x03\x02\x02" + + "\x02\x88!\x03\x02\x02\x02\x89\x8A\x07\x1A\x02\x02\x8A\x8B\x05\f\x07\x02" + + "\x8B\x8C\x07\x1B\x02\x02\x8C#\x03\x02\x02\x02\x8D\x8E\x07\x1C\x02\x02" + + "\x8E\x93\x05&\x14\x02\x8F\x90\x07\x1D\x02\x02\x90\x92\x05&\x14\x02\x91" + + "\x8F\x03\x02\x02\x02\x92\x95\x03\x02\x02\x02\x93\x91\x03\x02\x02\x02\x93" + + "\x94\x03\x02\x02\x02\x94\x96\x03\x02\x02\x02\x95\x93\x03\x02\x02\x02\x96" + + "\x97\x07\x1E\x02\x02\x97%\x03\x02\x02\x02\x98\x9B\x07 \x02\x02\x99\x9A" + + "\x07\x1F\x02\x02\x9A\x9C\x05\f\x07\x02\x9B\x99\x03\x02\x02\x02\x9B\x9C" + + "\x03\x02\x02\x02\x9C\'\x03\x02\x02\x02\x9D\x9E\x07\x1C\x02\x02\x9E\xA3" + + "\x05\f\x07\x02\x9F\xA0\x07\x1D\x02\x02\xA0\xA2\x05\f\x07\x02\xA1\x9F\x03" + + "\x02\x02\x02\xA2\xA5\x03\x02\x02\x02\xA3\xA1\x03\x02\x02\x02\xA3\xA4\x03" + + "\x02\x02\x02\xA4\xA6\x03\x02\x02\x02\xA5\xA3\x03\x02\x02\x02\xA6\xA7\x07" + + "\x1E\x02\x02\xA7)\x03\x02\x02\x02\xA8\xAB\x07 \x02\x02\xA9\xAB\x05,\x17" + + "\x02\xAA\xA8\x03\x02\x02\x02\xAA\xA9\x03\x02\x02\x02\xAB+\x03\x02\x02" + + "\x02\xAC\xAD\t\x05\x02\x02\xAD-\x03\x02\x02\x02\x1118=FJX`hpx\x87\x93" + + "\x9B\xA3\xAA"; + public static __ATN: ATN; + public static get _ATN(): ATN { + if (!YorkieSchemaParser.__ATN) { + YorkieSchemaParser.__ATN = new ATNDeserializer().deserialize(Utils.toCharArray(YorkieSchemaParser._serializedATN)); + } + + return YorkieSchemaParser.__ATN; + } + +} + +export class DocumentContext extends ParserRuleContext { + public EOF(): TerminalNode { return this.getToken(YorkieSchemaParser.EOF, 0); } + public declaration(): DeclarationContext[]; + public declaration(i: number): DeclarationContext; + public declaration(i?: number): DeclarationContext | DeclarationContext[] { + if (i === undefined) { + return this.getRuleContexts(DeclarationContext); + } else { + return this.getRuleContext(i, DeclarationContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_document; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterDocument) { + listener.enterDocument(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitDocument) { + listener.exitDocument(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitDocument) { + return visitor.visitDocument(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class DeclarationContext extends ParserRuleContext { + public typeAliasDeclaration(): TypeAliasDeclarationContext | undefined { + return this.tryGetRuleContext(0, TypeAliasDeclarationContext); + } + public variableDeclaration(): VariableDeclarationContext | undefined { + return this.tryGetRuleContext(0, VariableDeclarationContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_declaration; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterDeclaration) { + listener.enterDeclaration(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitDeclaration) { + listener.exitDeclaration(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitDeclaration) { + return visitor.visitDeclaration(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeAliasDeclarationContext extends ParserRuleContext { + public Identifier(): TerminalNode { return this.getToken(YorkieSchemaParser.Identifier, 0); } + public type(): TypeContext { + return this.getRuleContext(0, TypeContext); + } + public typeParameters(): TypeParametersContext | undefined { + return this.tryGetRuleContext(0, TypeParametersContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeAliasDeclaration; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeAliasDeclaration) { + listener.enterTypeAliasDeclaration(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeAliasDeclaration) { + listener.exitTypeAliasDeclaration(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeAliasDeclaration) { + return visitor.visitTypeAliasDeclaration(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class VariableDeclarationContext extends ParserRuleContext { + public Identifier(): TerminalNode { return this.getToken(YorkieSchemaParser.Identifier, 0); } + public typeAnnotation(): TypeAnnotationContext | undefined { + return this.tryGetRuleContext(0, TypeAnnotationContext); + } + public expression(): ExpressionContext | undefined { + return this.tryGetRuleContext(0, ExpressionContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_variableDeclaration; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterVariableDeclaration) { + listener.enterVariableDeclaration(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitVariableDeclaration) { + listener.exitVariableDeclaration(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitVariableDeclaration) { + return visitor.visitVariableDeclaration(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeAnnotationContext extends ParserRuleContext { + public type(): TypeContext { + return this.getRuleContext(0, TypeContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeAnnotation; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeAnnotation) { + listener.enterTypeAnnotation(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeAnnotation) { + listener.exitTypeAnnotation(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeAnnotation) { + return visitor.visitTypeAnnotation(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeContext extends ParserRuleContext { + public unionType(): UnionTypeContext { + return this.getRuleContext(0, UnionTypeContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_type; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterType) { + listener.enterType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitType) { + listener.exitType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitType) { + return visitor.visitType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class UnionTypeContext extends ParserRuleContext { + public intersectionType(): IntersectionTypeContext[]; + public intersectionType(i: number): IntersectionTypeContext; + public intersectionType(i?: number): IntersectionTypeContext | IntersectionTypeContext[] { + if (i === undefined) { + return this.getRuleContexts(IntersectionTypeContext); + } else { + return this.getRuleContext(i, IntersectionTypeContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_unionType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterUnionType) { + listener.enterUnionType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitUnionType) { + listener.exitUnionType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitUnionType) { + return visitor.visitUnionType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class IntersectionTypeContext extends ParserRuleContext { + public arrayType(): ArrayTypeContext[]; + public arrayType(i: number): ArrayTypeContext; + public arrayType(i?: number): ArrayTypeContext | ArrayTypeContext[] { + if (i === undefined) { + return this.getRuleContexts(ArrayTypeContext); + } else { + return this.getRuleContext(i, ArrayTypeContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_intersectionType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterIntersectionType) { + listener.enterIntersectionType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitIntersectionType) { + listener.exitIntersectionType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitIntersectionType) { + return visitor.visitIntersectionType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class ArrayTypeContext extends ParserRuleContext { + public primaryType(): PrimaryTypeContext { + return this.getRuleContext(0, PrimaryTypeContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_arrayType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterArrayType) { + listener.enterArrayType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitArrayType) { + listener.exitArrayType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitArrayType) { + return visitor.visitArrayType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class PrimaryTypeContext extends ParserRuleContext { + public parenthesizedType(): ParenthesizedTypeContext | undefined { + return this.tryGetRuleContext(0, ParenthesizedTypeContext); + } + public primitiveType(): PrimitiveTypeContext | undefined { + return this.tryGetRuleContext(0, PrimitiveTypeContext); + } + public objectType(): ObjectTypeContext | undefined { + return this.tryGetRuleContext(0, ObjectTypeContext); + } + public yorkieType(): YorkieTypeContext | undefined { + return this.tryGetRuleContext(0, YorkieTypeContext); + } + public typeReference(): TypeReferenceContext | undefined { + return this.tryGetRuleContext(0, TypeReferenceContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_primaryType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterPrimaryType) { + listener.enterPrimaryType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitPrimaryType) { + listener.exitPrimaryType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitPrimaryType) { + return visitor.visitPrimaryType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class PrimitiveTypeContext extends ParserRuleContext { + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_primitiveType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterPrimitiveType) { + listener.enterPrimitiveType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitPrimitiveType) { + listener.exitPrimitiveType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitPrimitiveType) { + return visitor.visitPrimitiveType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class ObjectTypeContext extends ParserRuleContext { + public propertySignature(): PropertySignatureContext[]; + public propertySignature(i: number): PropertySignatureContext; + public propertySignature(i?: number): PropertySignatureContext | PropertySignatureContext[] { + if (i === undefined) { + return this.getRuleContexts(PropertySignatureContext); + } else { + return this.getRuleContext(i, PropertySignatureContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_objectType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterObjectType) { + listener.enterObjectType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitObjectType) { + listener.exitObjectType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitObjectType) { + return visitor.visitObjectType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class PropertySignatureContext extends ParserRuleContext { + public propertyName(): PropertyNameContext { + return this.getRuleContext(0, PropertyNameContext); + } + public typeAnnotation(): TypeAnnotationContext { + return this.getRuleContext(0, TypeAnnotationContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_propertySignature; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterPropertySignature) { + listener.enterPropertySignature(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitPropertySignature) { + listener.exitPropertySignature(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitPropertySignature) { + return visitor.visitPropertySignature(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class PropertyNameContext extends ParserRuleContext { + public Identifier(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.Identifier, 0); } + public StringLiteral(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.StringLiteral, 0); } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_propertyName; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterPropertyName) { + listener.enterPropertyName(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitPropertyName) { + listener.exitPropertyName(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitPropertyName) { + return visitor.visitPropertyName(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class YorkieTypeContext extends ParserRuleContext { + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_yorkieType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterYorkieType) { + listener.enterYorkieType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitYorkieType) { + listener.exitYorkieType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitYorkieType) { + return visitor.visitYorkieType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeReferenceContext extends ParserRuleContext { + public Identifier(): TerminalNode { return this.getToken(YorkieSchemaParser.Identifier, 0); } + public typeArguments(): TypeArgumentsContext | undefined { + return this.tryGetRuleContext(0, TypeArgumentsContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeReference; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeReference) { + listener.enterTypeReference(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeReference) { + listener.exitTypeReference(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeReference) { + return visitor.visitTypeReference(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class ParenthesizedTypeContext extends ParserRuleContext { + public type(): TypeContext { + return this.getRuleContext(0, TypeContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_parenthesizedType; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterParenthesizedType) { + listener.enterParenthesizedType(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitParenthesizedType) { + listener.exitParenthesizedType(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitParenthesizedType) { + return visitor.visitParenthesizedType(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeParametersContext extends ParserRuleContext { + public typeParameter(): TypeParameterContext[]; + public typeParameter(i: number): TypeParameterContext; + public typeParameter(i?: number): TypeParameterContext | TypeParameterContext[] { + if (i === undefined) { + return this.getRuleContexts(TypeParameterContext); + } else { + return this.getRuleContext(i, TypeParameterContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeParameters; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeParameters) { + listener.enterTypeParameters(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeParameters) { + listener.exitTypeParameters(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeParameters) { + return visitor.visitTypeParameters(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeParameterContext extends ParserRuleContext { + public Identifier(): TerminalNode { return this.getToken(YorkieSchemaParser.Identifier, 0); } + public type(): TypeContext | undefined { + return this.tryGetRuleContext(0, TypeContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeParameter; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeParameter) { + listener.enterTypeParameter(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeParameter) { + listener.exitTypeParameter(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeParameter) { + return visitor.visitTypeParameter(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class TypeArgumentsContext extends ParserRuleContext { + public type(): TypeContext[]; + public type(i: number): TypeContext; + public type(i?: number): TypeContext | TypeContext[] { + if (i === undefined) { + return this.getRuleContexts(TypeContext); + } else { + return this.getRuleContext(i, TypeContext); + } + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_typeArguments; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterTypeArguments) { + listener.enterTypeArguments(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitTypeArguments) { + listener.exitTypeArguments(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitTypeArguments) { + return visitor.visitTypeArguments(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class ExpressionContext extends ParserRuleContext { + public Identifier(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.Identifier, 0); } + public literal(): LiteralContext | undefined { + return this.tryGetRuleContext(0, LiteralContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_expression; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterExpression) { + listener.enterExpression(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitExpression) { + listener.exitExpression(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitExpression) { + return visitor.visitExpression(this); + } else { + return visitor.visitChildren(this); + } + } +} + + +export class LiteralContext extends ParserRuleContext { + public StringLiteral(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.StringLiteral, 0); } + public NumberLiteral(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.NumberLiteral, 0); } + public BooleanLiteral(): TerminalNode | undefined { return this.tryGetToken(YorkieSchemaParser.BooleanLiteral, 0); } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return YorkieSchemaParser.RULE_literal; } + // @Override + public enterRule(listener: YorkieSchemaListener): void { + if (listener.enterLiteral) { + listener.enterLiteral(this); + } + } + // @Override + public exitRule(listener: YorkieSchemaListener): void { + if (listener.exitLiteral) { + listener.exitLiteral(this); + } + } + // @Override + public accept(visitor: YorkieSchemaVisitor): Result { + if (visitor.visitLiteral) { + return visitor.visitLiteral(this); + } else { + return visitor.visitChildren(this); + } + } +} + + diff --git a/antlr/YorkieSchemaVisitor.ts b/antlr/YorkieSchemaVisitor.ts new file mode 100644 index 0000000..5bc0ea5 --- /dev/null +++ b/antlr/YorkieSchemaVisitor.ts @@ -0,0 +1,192 @@ +// Generated from antlr/YorkieSchema.g4 by ANTLR 4.9.0-SNAPSHOT + + +import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; + +import { DocumentContext } from "./YorkieSchemaParser"; +import { DeclarationContext } from "./YorkieSchemaParser"; +import { TypeAliasDeclarationContext } from "./YorkieSchemaParser"; +import { VariableDeclarationContext } from "./YorkieSchemaParser"; +import { TypeAnnotationContext } from "./YorkieSchemaParser"; +import { TypeContext } from "./YorkieSchemaParser"; +import { UnionTypeContext } from "./YorkieSchemaParser"; +import { IntersectionTypeContext } from "./YorkieSchemaParser"; +import { ArrayTypeContext } from "./YorkieSchemaParser"; +import { PrimaryTypeContext } from "./YorkieSchemaParser"; +import { PrimitiveTypeContext } from "./YorkieSchemaParser"; +import { ObjectTypeContext } from "./YorkieSchemaParser"; +import { PropertySignatureContext } from "./YorkieSchemaParser"; +import { PropertyNameContext } from "./YorkieSchemaParser"; +import { YorkieTypeContext } from "./YorkieSchemaParser"; +import { TypeReferenceContext } from "./YorkieSchemaParser"; +import { ParenthesizedTypeContext } from "./YorkieSchemaParser"; +import { TypeParametersContext } from "./YorkieSchemaParser"; +import { TypeParameterContext } from "./YorkieSchemaParser"; +import { TypeArgumentsContext } from "./YorkieSchemaParser"; +import { ExpressionContext } from "./YorkieSchemaParser"; +import { LiteralContext } from "./YorkieSchemaParser"; + + +/** + * This interface defines a complete generic visitor for a parse tree produced + * by `YorkieSchemaParser`. + * + * @param The return type of the visit operation. Use `void` for + * operations with no return type. + */ +export interface YorkieSchemaVisitor extends ParseTreeVisitor { + /** + * Visit a parse tree produced by `YorkieSchemaParser.document`. + * @param ctx the parse tree + * @return the visitor result + */ + visitDocument?: (ctx: DocumentContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.declaration`. + * @param ctx the parse tree + * @return the visitor result + */ + visitDeclaration?: (ctx: DeclarationContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeAliasDeclaration`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeAliasDeclaration?: (ctx: TypeAliasDeclarationContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.variableDeclaration`. + * @param ctx the parse tree + * @return the visitor result + */ + visitVariableDeclaration?: (ctx: VariableDeclarationContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeAnnotation`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeAnnotation?: (ctx: TypeAnnotationContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.type`. + * @param ctx the parse tree + * @return the visitor result + */ + visitType?: (ctx: TypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.unionType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitUnionType?: (ctx: UnionTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.intersectionType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitIntersectionType?: (ctx: IntersectionTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.arrayType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitArrayType?: (ctx: ArrayTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.primaryType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitPrimaryType?: (ctx: PrimaryTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.primitiveType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitPrimitiveType?: (ctx: PrimitiveTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.objectType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitObjectType?: (ctx: ObjectTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.propertySignature`. + * @param ctx the parse tree + * @return the visitor result + */ + visitPropertySignature?: (ctx: PropertySignatureContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.propertyName`. + * @param ctx the parse tree + * @return the visitor result + */ + visitPropertyName?: (ctx: PropertyNameContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.yorkieType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitYorkieType?: (ctx: YorkieTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeReference`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeReference?: (ctx: TypeReferenceContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.parenthesizedType`. + * @param ctx the parse tree + * @return the visitor result + */ + visitParenthesizedType?: (ctx: ParenthesizedTypeContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeParameters`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeParameters?: (ctx: TypeParametersContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeParameter`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeParameter?: (ctx: TypeParameterContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.typeArguments`. + * @param ctx the parse tree + * @return the visitor result + */ + visitTypeArguments?: (ctx: TypeArgumentsContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.expression`. + * @param ctx the parse tree + * @return the visitor result + */ + visitExpression?: (ctx: ExpressionContext) => Result; + + /** + * Visit a parse tree produced by `YorkieSchemaParser.literal`. + * @param ctx the parse tree + * @return the visitor result + */ + visitLiteral?: (ctx: LiteralContext) => Result; +} + diff --git a/index.html b/index.html index 44a9335..bf33ff7 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,19 @@ - Vite + TS + CodeMirror Linter Example + +

CodeMirror Linter

+
diff --git a/package-lock.json b/package-lock.json index 0f05644..4b8a271 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,10 @@ "": { "name": "yorkie-schema", "version": "0.0.0", + "dependencies": { + "@codemirror/lint": "^6.8.2", + "codemirror": "^6.0.1" + }, "devDependencies": { "antlr4ts": "^0.5.0-alpha.4", "antlr4ts-cli": "^0.5.0-alpha.4", @@ -17,6 +21,82 @@ "vitest": "^2.1.1" } }, + "node_modules/@codemirror/autocomplete": { + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.18.1.tgz", + "integrity": "sha512-iWHdj/B1ethnHRTwZj+C1obmmuCzquH29EbcKr0qIjA9NfDeBDJ7vs+WOHsFeLeflE4o+dHfYndJloMKHUkWUA==", + "dependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.17.0", + "@lezer/common": "^1.0.0" + }, + "peerDependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@codemirror/commands": { + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.6.2.tgz", + "integrity": "sha512-Fq7eWOl1Rcbrfn6jD8FPCj9Auaxdm5nIK5RYOeW7ughnd/rY5AmPg6b+CfsG39ZHdwiwe8lde3q8uR7CF5S0yQ==", + "dependencies": { + "@codemirror/language": "^6.0.0", + "@codemirror/state": "^6.4.0", + "@codemirror/view": "^6.27.0", + "@lezer/common": "^1.1.0" + } + }, + "node_modules/@codemirror/language": { + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.10.3.tgz", + "integrity": "sha512-kDqEU5sCP55Oabl6E7m5N+vZRoc0iWqgDVhEKifcHzPzjqCegcO4amfrYVL9PmPZpl4G0yjkpTpUO/Ui8CzO8A==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.23.0", + "@lezer/common": "^1.1.0", + "@lezer/highlight": "^1.0.0", + "@lezer/lr": "^1.0.0", + "style-mod": "^4.0.0" + } + }, + "node_modules/@codemirror/lint": { + "version": "6.8.2", + "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.8.2.tgz", + "integrity": "sha512-PDFG5DjHxSEjOXk9TQYYVjZDqlZTFaDBfhQixHnQOEVDDNHUbEh/hstAjcQJaA6FQdZTD1hquXTK0rVBLADR1g==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "crelt": "^1.0.5" + } + }, + "node_modules/@codemirror/search": { + "version": "6.5.6", + "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.5.6.tgz", + "integrity": "sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "crelt": "^1.0.5" + } + }, + "node_modules/@codemirror/state": { + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.4.1.tgz", + "integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==" + }, + "node_modules/@codemirror/view": { + "version": "6.34.1", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.34.1.tgz", + "integrity": "sha512-t1zK/l9UiRqwUNPm+pdIT0qzJlzuVckbTEMVNFhfWkGiBQClstzg+78vedCvLSX0xJEZ6lwZbPpnljL7L6iwMQ==", + "dependencies": { + "@codemirror/state": "^6.4.0", + "style-mod": "^4.1.0", + "w3c-keyname": "^2.2.4" + } + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -391,6 +471,27 @@ "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", "dev": true }, + "node_modules/@lezer/common": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.2.2.tgz", + "integrity": "sha512-Z+R3hN6kXbgBWAuejUNPihylAL1Z5CaFqnIe0nTX8Ej+XlIy3EGtXxn6WtLMO+os2hRkQvm2yvaGMYliUzlJaw==" + }, + "node_modules/@lezer/highlight": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.1.tgz", + "integrity": "sha512-Z5duk4RN/3zuVO7Jq0pGLJ3qynpxUVsh7IbUbGj88+uV2ApSAn6kWg2au3iJb+0Zi7kKtqffIESgNcRXWZWmSA==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, + "node_modules/@lezer/lr": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.2.tgz", + "integrity": "sha512-pu0K1jCIdnQ12aWNaAVU5bzi7Bd1w54J3ECgANPmYLtQKP0HBj2cE/5coBD66MT10xbtIuUr7tg0Shbsvk0mDA==", + "dependencies": { + "@lezer/common": "^1.0.0" + } + }, "node_modules/@rollup/plugin-inject": { "version": "5.0.5", "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.5.tgz", @@ -1094,6 +1195,20 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/codemirror": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-6.0.1.tgz", + "integrity": "sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==", + "dependencies": { + "@codemirror/autocomplete": "^6.0.0", + "@codemirror/commands": "^6.0.0", + "@codemirror/language": "^6.0.0", + "@codemirror/lint": "^6.0.0", + "@codemirror/search": "^6.0.0", + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0" + } + }, "node_modules/console-browserify": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", @@ -1161,6 +1276,11 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/crelt": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz", + "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==" + }, "node_modules/crypto-browserify": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", @@ -2388,6 +2508,11 @@ "safe-buffer": "~5.2.0" } }, + "node_modules/style-mod": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.2.tgz", + "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==" + }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -2668,6 +2793,11 @@ "integrity": "sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==", "dev": true }, + "node_modules/w3c-keyname": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==" + }, "node_modules/which-typed-array": { "version": "1.1.15", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", diff --git a/package.json b/package.json index 24d4912..cf97057 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", - "build:schema": "antlr4ts -visitor antlr/Schema.g4", + "build:schema": "antlr4ts -visitor antlr/YorkieSchema.g4", "test": "vitest", "preview": "vite preview" }, @@ -18,5 +18,9 @@ "vite": "^5.4.1", "vite-plugin-node-polyfills": "^0.22.0", "vitest": "^2.1.1" + }, + "dependencies": { + "@codemirror/lint": "^6.8.2", + "codemirror": "^6.0.1" } } diff --git a/src/counter.ts b/src/counter.ts deleted file mode 100644 index da18bde..0000000 --- a/src/counter.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function setupCounter(element: HTMLButtonElement) { - let counter = 0; - const setCounter = (count: number) => { - counter = count; - element.innerHTML = `count is ${counter}`; - }; - element.addEventListener('click', () => setCounter(counter + 1)); - setCounter(0); -} diff --git a/src/main.ts b/src/main.ts index 113c7c8..e81f779 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,24 +1,41 @@ -import './style.css'; -import typescriptLogo from './typescript.svg'; -import viteLogo from '/vite.svg'; -import { setupCounter } from './counter.ts'; +import { EditorState } from '@codemirror/state'; +import { linter, lintGutter, Diagnostic } from '@codemirror/lint'; +import { basicSetup, EditorView } from 'codemirror'; +import { getDiagnostics } from './validator'; -document.querySelector('#app')!.innerHTML = ` -
- - - - - - -

Vite + TypeScript

-
- -
-

- Click on the Vite and TypeScript logos to learn more -

-
-`; +const yorkieLinter = linter((view) => { + const code = view.state.doc.toString(); + const diagnostics: Diagnostic[] = getDiagnostics(code).map((data) => { + return { + from: + view.state.doc.line(data.range.start.line).from + + data.range.start.column, + to: view.state.doc.line(data.range.end.line).from + data.range.end.column, + message: data.message, + severity: data.severity, + }; + }); + return diagnostics; +}); -setupCounter(document.querySelector('#counter')!); +new EditorView({ + state: EditorState.create({ + doc: `// 🐾 Yorkie Schema Example + +// This is the root of your document +// Every schema must define a Document type +type Document = { + // theme: "light" | "dark"; + history: Event[]; + text: yorkie.Text; +}; + +type Event = { + statusCode: 200 | 400; + info: string; +}; + `, + extensions: [basicSetup, yorkieLinter, lintGutter()], + }), + parent: document.getElementById('editor')!, +}); diff --git a/src/style.css b/src/style.css deleted file mode 100644 index f9c7350..0000000 --- a/src/style.css +++ /dev/null @@ -1,96 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; -} - -body { - margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -#app { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: filter 300ms; -} -.logo:hover { - filter: drop-shadow(0 0 2em #646cffaa); -} -.logo.vanilla:hover { - filter: drop-shadow(0 0 2em #3178c6aa); -} - -.card { - padding: 2em; -} - -.read-the-docs { - color: #888; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } -} diff --git a/src/typescript.svg b/src/typescript.svg deleted file mode 100644 index d91c910..0000000 --- a/src/typescript.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/validator.ts b/src/validator.ts index 5e86f01..b540da8 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -1,48 +1,38 @@ -import { CharStreams, CommonTokenStream } from 'antlr4ts'; -import { ParseTree } from 'antlr4ts/tree/ParseTree'; -import { SchemaLexer } from '../antlr/SchemaLexer'; -import { SchemaVisitor } from '../antlr/SchemaVisitor'; import { - ArraySuffixContext, - FieldContext, - FieldListContext, - FieldTypeContext, - PrimitiveTypeContext, - SchemaParser, - SimpleTypeContext, - StartContext, - TypeDefinitionContext, - TypeDefinitionsContext, - TypeExpressionContext, - UnionTypeContext, - UnionTypeInnerContext, -} from '../antlr/SchemaParser'; + CharStreams, + CommonTokenStream, + ANTLRErrorListener, + Recognizer, + Token, + CommonToken, + RecognitionException, +} from 'antlr4ts'; +import { ParseTree } from 'antlr4ts/tree/ParseTree'; +import { YorkieSchemaLexer } from '../antlr/YorkieSchemaLexer'; +import { YorkieSchemaVisitor } from '../antlr/YorkieSchemaVisitor'; +import { YorkieSchemaParser } from '../antlr/YorkieSchemaParser'; import { ErrorNode } from 'antlr4ts/tree/ErrorNode'; import { RuleNode } from 'antlr4ts/tree/RuleNode'; import { TerminalNode } from 'antlr4ts/tree/TerminalNode'; +export type Diagnostic = { + severity: 'error' | 'warning' | 'info'; + message: string; + range: { + start: { column: number; line: number }; + end: { column: number; line: number }; + }; +}; + class Node { constructor(public name: string) {} } -class Visitor implements SchemaVisitor { - visitStart?: ((ctx: StartContext) => Node) | undefined; - visitTypeDefinitions?: ((ctx: TypeDefinitionsContext) => Node) | undefined; - visitTypeDefinition?: ((ctx: TypeDefinitionContext) => Node) | undefined; - visitFieldList?: ((ctx: FieldListContext) => Node) | undefined; - visitField?: ((ctx: FieldContext) => Node) | undefined; - visitFieldType?: ((ctx: FieldTypeContext) => Node) | undefined; - visitTypeExpression?: ((ctx: TypeExpressionContext) => Node) | undefined; - visitSimpleType?: ((ctx: SimpleTypeContext) => Node) | undefined; - visitArraySuffix?: ((ctx: ArraySuffixContext) => Node) | undefined; - visitUnionType?: ((ctx: UnionTypeContext) => Node) | undefined; - visitUnionTypeInner?: ((ctx: UnionTypeInnerContext) => Node) | undefined; - visitPrimitiveType?: ((ctx: PrimitiveTypeContext) => Node) | undefined; +class Visitor implements YorkieSchemaVisitor { visit(tree: ParseTree): Node { return tree.accept(this); } visitChildren(node: RuleNode): Node { - console.log(node.text); for (let i = 0; i < node.childCount; i++) { const child = node.getChild(i); this.visit(child); @@ -52,19 +42,103 @@ class Visitor implements SchemaVisitor { visitTerminal(node: TerminalNode): Node { return new Node(node.text); } - visitErrorNode(_: ErrorNode): Node { - throw new Error('Method not implemented.'); + visitErrorNode(node: ErrorNode): Node { + return new Node(node.text); + } +} + +class LexerErrorListener implements ANTLRErrorListener { + constructor(private errorList: Diagnostic[]) {} + + syntaxError( + _recognizer: Recognizer, + _offendingSymbol: T | undefined, + line: number, + charPositionInLine: number, + msg: string, + _e: RecognitionException | undefined, + ): void { + let error: Diagnostic = { + severity: 'error', + message: msg, + range: { + start: { column: charPositionInLine, line }, + end: { column: charPositionInLine + 1, line }, + }, + }; + + this.errorList.push(error); + } +} + +class ParserErrorListener implements ANTLRErrorListener { + constructor(private errorList: Diagnostic[]) {} + + syntaxError( + _recognizer: Recognizer, + offendingSymbol: T | undefined, + line: number, + charPositionInLine: number, + msg: string, + _e: RecognitionException | undefined, + ): void { + const error: Diagnostic = { + severity: 'error', + message: msg, + range: { + start: { column: charPositionInLine, line }, + end: { column: charPositionInLine + 1, line }, + }, + }; + + if (offendingSymbol) { + error.range.end.column = + charPositionInLine + + offendingSymbol.stopIndex - + offendingSymbol.startIndex + + 1; + } + this.errorList.push(error); } } export function validate(data: string): boolean { + const diagnostics: Diagnostic[] = []; const stream = CharStreams.fromString(data); - const lexer = new SchemaLexer(stream); + const lexer = new YorkieSchemaLexer(stream); + lexer.removeErrorListeners(); + lexer.addErrorListener(new LexerErrorListener(diagnostics)); + const tokens = new CommonTokenStream(lexer); - const parser = new SchemaParser(tokens); - const ast = parser.start(); + const parser = new YorkieSchemaParser(tokens); + parser.removeErrorListeners(); + parser.addErrorListener(new ParserErrorListener(diagnostics)); + + const ast = parser.declaration(); const visitor = new Visitor(); visitor.visit(ast); + if (diagnostics.length > 0) { + console.error(diagnostics.map((d) => d.message).join('\n')); + return false; + } + return true; } + +export function getDiagnostics(data: string): Diagnostic[] { + const diagnostics: Diagnostic[] = []; + + const stream = CharStreams.fromString(data); + const lexer = new YorkieSchemaLexer(stream); + lexer.removeErrorListeners(); + lexer.addErrorListener(new LexerErrorListener(diagnostics)); + + const tokens = new CommonTokenStream(lexer); + const parser = new YorkieSchemaParser(tokens); + parser.removeErrorListeners(); + parser.addErrorListener(new ParserErrorListener(diagnostics)); + parser.declaration(); + + return diagnostics; +} diff --git a/test/schema.test.ts b/test/schema.test.ts index e7430ab..99551cd 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -1,28 +1,264 @@ -import { describe, it, assert } from 'vitest'; +import { describe, it, expect } from 'vitest'; import { validate } from '../src/validator'; -describe('Schema', () => { - it('should be able to parse the valid schema', () => { - // μš°λ¦¬κ°€ μƒκ°ν•˜λŠ” Schema의 μŠ€νŒ©μ€? - // - TypeScript와 μœ μ‚¬ν•œ νƒ€μž… μ •μ˜ 문법을 μ‚¬μš©ν•œλ‹€. - // - Yorkieκ°€ κ°–κ³  μžˆλŠ” κΈ°λ³Έ νƒ€μž…μ„ μ‚¬μš©ν•  수 μžˆλ‹€. - // - yorkie.JSONArray, yorkie.JSONObject - // - yorkie.Counter, yorkie.Text, yorkie.Tree - // - 이외에 μ‚¬μš©μžκ°€ μ •μ˜ν•œ νƒ€μž…μ„ μ‚¬μš©ν•  수 μžˆλ‹€. - // - ν•˜μ§€λ§Œ μ •μ˜ν•˜μ§€ μ•Šμ€ νƒ€μž…μ„ μ‚¬μš©ν•  수 μ—†λ‹€. - // - Yorkieκ°€ κ°–κ³  μžˆλŠ” Primitive νƒ€μž…μ„ μ‚¬μš©ν•  수 μžˆλ‹€. - // - null, boolean, number(integer, double), long(bigint), string, bytes(Uint8Array), Date - - assert.isTrue( - validate(` - type Storage { - todos: Todo[] - } - type Todo { - title: string - completed: boolean - } - `), - ); +describe('Schema:TypeScript', () => { + it.skip('should validate value restriction with literal types', () => { + const schema = ` + type Document = { + theme: "light" | "dark"; + history: Event[]; + }; + + type Event = { + statusCode: 200 | 400; + info: string; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should validate array with anonymous type definition', () => { + const schema = ` + type Document = { + objectArray: { name: string; age: number; }[]; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should validate union types', () => { + const schema = ` + type Document = { + title: string; + author: string | null; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should detect invalid syntax: empty type definition', () => { + const schema = ` + type Document = { + invalidField: + }; + `; + expect(validate(schema)).toBe(false); + }); + + it('should detect invalid syntax: no semicolon', () => { + const schema = ` + type Document = { + invalidField: number + } + `; + expect(validate(schema)).toBe(false); + }); + + it('should validate anonymous type definition', () => { + const schema = ` + type Document = { + scientist: { + name: string; + age: number; + }; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it.skip('should validate optional properties', () => { + const schema = ` + type Document = { + title: string; + version?: number; + author?: string; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it.skip('should detect unsupported types in TypeScript', () => { + const schema = ` + type Document = { + title: float; + version?: longlong; + author?: long; + }; + `; + expect(validate(schema)).toBe(false); + }); + + it('should validate schema with comments', () => { + const schema = ` + // This is comment. + type Document = { + field: string; + }; + `; + expect(validate(schema)).toBe(true); + }); +}); + +describe('Schema:Yorkie', () => { + it('should parse a schema with Yorkie Primitives', () => { + const schema = ` + type Document = { + field1: null; + field2: boolean; + field3: number; + field4: bigint; + field5: Uint8Array; + field6: Date; + field7: string; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should parse a schema with Yorkie Types', () => { + const schema = ` + type Document = { + counter: yorkie.Counter; + tree: yorkie.Tree; + text: yorkie.Text; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it.skip('should validate Yorkie types with user-defined attributes', () => { + const schema = ` + type Document = { + text1: yorkie.Text<{}>; + text2: yorkie.Text<{bold: boolean}>; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it.skip('should detect incorrect usage of Yorkie type', () => { + const schema = ` + type Document = { + object: yorkie.Object; + array: yorkie.Array; + }; + `; + // TODO(hackerwins): We need to figure out the intention of this test. + expect(validate(schema)).toBe(false); + }); + + it.skip("should parse a schema using Yorkie's complex types", () => { + const schema = ` + type Todo = { + title: string; + completed: boolean; + } + type Document = { + object: yorkie.Object<{}>; + array: yorkie.Array; + array2: yorkie.Array>; + array3: yorkie.Array; + }; + `; + expect(validate(schema)).toBe(true); + }); +}); + +describe('Schema:User-Defined', () => { + it('should support type[] syntax for user-defined types', () => { + const schema = ` + type Document = { + todos: Todo[]; + }; + type Todo = { + title: string; + completed: boolean; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should support Array syntax for user-defined types', () => { + const schema = ` + type Document = { + todos: Array; + }; + type Todo = { + title: string; + completed: boolean; + }; + `; + expect(validate(schema)).toBe(true); + }); + + it('should validate multiple user-defined types', () => { + const schema = ` + type Document = { + name: string; + detail: UserDetail; + mytypes: MyTypeName[]; + }; + type MyTypeName = { + apple: string; + banana: number; + cookie: boolean; + dog: number[]; + string_or_number: string | number; + array_of_string_or_number: (string | number)[]; + complex: string | number | boolean[]; + array_of_complex: (string | number | boolean)[]; + }; + type UserDetail = { + address: string; + age: number; + foo: string | number | boolean; + bar: string[]; + }; + `; + expect(validate(schema)).toBe(true); + }); +}); + +describe.skip('Schema:Exception', () => { + it('should not parse a schema with undefined types', () => { + const schema = ` + type Document = { + unknownType: Hello; + }; + `; + expect(validate(schema)).toBe(false); + }); + + it('should restrict the use of reserved words', () => { + const schema = ` + type string = { + field1: string; + } + `; + expect(validate(schema)).toBe(false); + }); + + it('shoud restrict unused type definition', () => { + const schema = ` + type UserType = { + field1: string; + } + `; + expect(validate(schema)).toBe(false); + }); + + it('should detect type cycle', () => { + const schema = ` + type Hello = { + field1: string; + field2: World; + } + + type World = { + field1: string; + field2: Hello; + } + `; + expect(validate(schema)).toBe(false); }); });