├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── README.md ├── jest.config.js ├── package-lock.json ├── package.json ├── scripts └── gen-grammar.sh ├── src ├── grammar │ ├── tslexer.g4 │ └── tsparser.g4 └── main.ts └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | src/grammar/antlr/ 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "node": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:@typescript-eslint/eslint-recommended" 9 | ], 10 | "globals": { 11 | "Atomics": "readonly", 12 | "SharedArrayBuffer": "readonly" 13 | }, 14 | "parser": "@typescript-eslint/parser", 15 | "parserOptions": { 16 | "ecmaVersion": 11, 17 | "sourceType": "module" 18 | }, 19 | "plugins": ["@typescript-eslint"], 20 | "rules": { 21 | "no-unused-vars": "off", 22 | "@typescript-eslint/no-unused-vars": [ 23 | "error", 24 | { 25 | "vars": "all", 26 | "args": "after-used", 27 | "ignoreRestSiblings": false 28 | } 29 | ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # Snowpack dependency directory (https://snowpack.dev/) 45 | web_modules/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | .parcel-cache 78 | 79 | # Next.js build output 80 | .next 81 | out 82 | 83 | # Nuxt.js build / generate output 84 | .nuxt 85 | dist 86 | 87 | # Gatsby files 88 | .cache/ 89 | # Comment in the public line in if your project uses Gatsby and not Next.js 90 | # https://nextjs.org/blog/next-9-1#public-directory-support 91 | # public 92 | 93 | # vuepress build output 94 | .vuepress/dist 95 | 96 | # Serverless directories 97 | .serverless/ 98 | 99 | # FuseBox cache 100 | .fusebox/ 101 | 102 | # DynamoDB Local files 103 | .dynamodb/ 104 | 105 | # TernJS port file 106 | .tern-port 107 | 108 | # Stores VSCode versions used for testing VSCode extensions 109 | .vscode-test 110 | 111 | # yarn v2 112 | .yarn/cache 113 | .yarn/unplugged 114 | .yarn/build-state.yml 115 | .yarn/install-state.gz 116 | .pnp.* 117 | 118 | # auto generated lexer and parser by antlr 119 | src/grammar/antlr 120 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | src/grammar/antlr/ 3 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": true, 6 | "arrowParens": "always" 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TS Native 🔥 2 | 3 | Build native and performant native application using a TypeScript subset 4 | 5 | 🚨🚨🚨 This repo is on active development 🚨🚨🚨 6 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/src'], 3 | transform: { 4 | '^.+\\.ts$': 'ts-jest', 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-native", 3 | "version": "0.0.1", 4 | "description": "Build performant native apps using TypeScript subset", 5 | "main": "src/main.ts", 6 | "scripts": { 7 | "start": "ts-node src/main.ts", 8 | "test": "jest", 9 | "prettify": "prettier --write", 10 | "lint-staged": "eslint --fix", 11 | "lint": "eslint --fix src/** --ext .ts", 12 | "gen-grammar": "sh ./scripts/gen-grammar.sh" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/ameerthehacker/ts-native.git" 17 | }, 18 | "keywords": [ 19 | "native", 20 | "typescript" 21 | ], 22 | "author": "Ameer Jhan", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/ameerthehacker/ts-native/issues" 26 | }, 27 | "homepage": "https://github.com/ameerthehacker/ts-native#readme", 28 | "dependencies": { 29 | "ts-node": "^8.10.2", 30 | "typescript": "^3.9.3" 31 | }, 32 | "devDependencies": { 33 | "@typescript-eslint/eslint-plugin": "^2.34.0", 34 | "@typescript-eslint/parser": "^2.34.0", 35 | "eslint": "^7.1.0", 36 | "husky": "^4.2.5", 37 | "jest": "^26.0.1", 38 | "lint-staged": "^10.2.7", 39 | "prettier": "^2.0.5", 40 | "ts-jest": "^26.0.0" 41 | }, 42 | "lint-staged": { 43 | "*.{js,ts,tsx,html,json,scss,css,md,yml}": [ 44 | "npm run prettify" 45 | ], 46 | "*.{spec,js,ts,tsx}": [ 47 | "npm run lint-staged" 48 | ] 49 | }, 50 | "husky": { 51 | "hooks": { 52 | "pre-commit": "lint-staged" 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /scripts/gen-grammar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -rf src/grammar/antlr 3 | cd src/grammar 4 | antlr tslexer.g4 tsparser.g4 -Dlanguage=JavaScript -o antlr 5 | -------------------------------------------------------------------------------- /src/grammar/tslexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar tslexer; 2 | 3 | channels { ERROR } 4 | 5 | options { 6 | superClass=TypeScriptLexerBase; 7 | } 8 | 9 | 10 | MultiLineComment: '/*' .*? '*/' -> channel(HIDDEN); 11 | SingleLineComment: '//' ~[\r\n\u2028\u2029]* -> channel(HIDDEN); 12 | RegularExpressionLiteral: '/' RegularExpressionFirstChar RegularExpressionChar* {this.IsRegexPossible()}? '/' IdentifierPart*; 13 | 14 | OpenBracket: '['; 15 | CloseBracket: ']'; 16 | OpenParen: '('; 17 | CloseParen: ')'; 18 | OpenBrace: '{' {this.ProcessOpenBrace();}; 19 | CloseBrace: '}' {this.ProcessCloseBrace();}; 20 | SemiColon: ';'; 21 | Comma: ','; 22 | Assign: '='; 23 | QuestionMark: '?'; 24 | Colon: ':'; 25 | Ellipsis: '...'; 26 | Dot: '.'; 27 | PlusPlus: '++'; 28 | MinusMinus: '--'; 29 | Plus: '+'; 30 | Minus: '-'; 31 | BitNot: '~'; 32 | Not: '!'; 33 | Multiply: '*'; 34 | Divide: '/'; 35 | Modulus: '%'; 36 | RightShiftArithmetic: '>>'; 37 | LeftShiftArithmetic: '<<'; 38 | RightShiftLogical: '>>>'; 39 | LessThan: '<'; 40 | MoreThan: '>'; 41 | LessThanEquals: '<='; 42 | GreaterThanEquals: '>='; 43 | Equals_: '=='; 44 | NotEquals: '!='; 45 | IdentityEquals: '==='; 46 | IdentityNotEquals: '!=='; 47 | BitAnd: '&'; 48 | BitXOr: '^'; 49 | BitOr: '|'; 50 | And: '&&'; 51 | Or: '||'; 52 | MultiplyAssign: '*='; 53 | DivideAssign: '/='; 54 | ModulusAssign: '%='; 55 | PlusAssign: '+='; 56 | MinusAssign: '-='; 57 | LeftShiftArithmeticAssign: '<<='; 58 | RightShiftArithmeticAssign: '>>='; 59 | RightShiftLogicalAssign: '>>>='; 60 | BitAndAssign: '&='; 61 | BitXorAssign: '^='; 62 | BitOrAssign: '|='; 63 | ARROW: '=>'; 64 | 65 | /// Null Literals 66 | 67 | NullLiteral: 'null'; 68 | 69 | /// Boolean Literals 70 | 71 | BooleanLiteral: 'true' 72 | | 'false'; 73 | 74 | /// Numeric Literals 75 | 76 | DecimalLiteral: DecimalIntegerLiteral '.' [0-9]* ExponentPart? 77 | | '.' [0-9]+ ExponentPart? 78 | | DecimalIntegerLiteral ExponentPart? 79 | ; 80 | 81 | /// Numeric Literals 82 | 83 | HexIntegerLiteral: '0' [xX] HexDigit+; 84 | OctalIntegerLiteral: '0' [0-7]+ {!this.IsStrictMode()}?; 85 | OctalIntegerLiteral2: '0' [oO] [0-7]+; 86 | BinaryIntegerLiteral: '0' [bB] [01]+; 87 | 88 | /// Keywords 89 | 90 | Break: 'break'; 91 | Do: 'do'; 92 | Instanceof: 'instanceof'; 93 | Typeof: 'typeof'; 94 | Case: 'case'; 95 | Else: 'else'; 96 | New: 'new'; 97 | Var: 'var'; 98 | Catch: 'catch'; 99 | Finally: 'finally'; 100 | Return: 'return'; 101 | Void: 'void'; 102 | Continue: 'continue'; 103 | For: 'for'; 104 | Switch: 'switch'; 105 | While: 'while'; 106 | Debugger: 'debugger'; 107 | Function: 'function'; 108 | This: 'this'; 109 | With: 'with'; 110 | Default: 'default'; 111 | If: 'if'; 112 | Throw: 'throw'; 113 | Delete: 'delete'; 114 | In: 'in'; 115 | Try: 'try'; 116 | As: 'as'; 117 | From: 'from'; 118 | ReadOnly: 'readonly'; 119 | Async: 'async'; 120 | 121 | /// Future Reserved Words 122 | 123 | Class: 'class'; 124 | Enum: 'enum'; 125 | Extends: 'extends'; 126 | Super: 'super'; 127 | Const: 'const'; 128 | Export: 'export'; 129 | Import: 'import'; 130 | 131 | /// The following tokens are also considered to be FutureReservedWords 132 | /// when parsing strict mode 133 | 134 | Implements: 'implements' ; 135 | Let: 'let' ; 136 | Private: 'private' ; 137 | Public: 'public' ; 138 | Interface: 'interface' ; 139 | Package: 'package' ; 140 | Protected: 'protected' ; 141 | Static: 'static' ; 142 | Yield: 'yield' ; 143 | 144 | //keywords: 145 | Number: 'number'; 146 | Boolean: 'boolean'; 147 | String: 'string'; 148 | Symbol: 'symbol'; 149 | 150 | 151 | TypeAlias : 'type'; 152 | 153 | Get: 'get'; 154 | Set: 'set'; 155 | 156 | Constructor: 'constructor'; 157 | Namespace: 'namespace'; 158 | Require: 'require'; 159 | Module: 'module'; 160 | Declare: 'declare'; 161 | 162 | Abstract: 'abstract'; 163 | 164 | Is: 'is'; 165 | 166 | // 167 | // Ext.2 Additions to 1.8: Decorators 168 | // 169 | At: '@'; 170 | 171 | /// Identifier Names and Identifiers 172 | 173 | Identifier: IdentifierStart IdentifierPart*; 174 | 175 | /// String Literals 176 | StringLiteral: ('"' DoubleStringCharacter* '"' 177 | | '\'' SingleStringCharacter* '\'') {this.ProcessStringLiteral();} 178 | ; 179 | 180 | TemplateStringLiteral: '`' ('\\`' | ~'`')* '`'; 181 | 182 | WhiteSpaces: [\t\u000B\u000C\u0020\u00A0]+ -> channel(HIDDEN); 183 | 184 | LineTerminator: [\r\n\u2028\u2029] -> channel(HIDDEN); 185 | 186 | /// Comments 187 | 188 | 189 | HtmlComment: '' -> channel(HIDDEN); 190 | CDataComment: '' -> channel(HIDDEN); 191 | UnexpectedCharacter: . -> channel(ERROR); 192 | 193 | // Fragment rules 194 | 195 | fragment DoubleStringCharacter 196 | : ~["\\\r\n] 197 | | '\\' EscapeSequence 198 | | LineContinuation 199 | ; 200 | 201 | fragment SingleStringCharacter 202 | : ~['\\\r\n] 203 | | '\\' EscapeSequence 204 | | LineContinuation 205 | ; 206 | 207 | fragment EscapeSequence 208 | : CharacterEscapeSequence 209 | | '0' // no digit ahead! TODO 210 | | HexEscapeSequence 211 | | UnicodeEscapeSequence 212 | | ExtendedUnicodeEscapeSequence 213 | ; 214 | 215 | fragment CharacterEscapeSequence 216 | : SingleEscapeCharacter 217 | | NonEscapeCharacter 218 | ; 219 | 220 | fragment HexEscapeSequence 221 | : 'x' HexDigit HexDigit 222 | ; 223 | 224 | fragment UnicodeEscapeSequence 225 | : 'u' HexDigit HexDigit HexDigit HexDigit 226 | ; 227 | 228 | fragment ExtendedUnicodeEscapeSequence 229 | : 'u' '{' HexDigit+ '}' 230 | ; 231 | 232 | fragment SingleEscapeCharacter 233 | : ['"\\bfnrtv] 234 | ; 235 | 236 | fragment NonEscapeCharacter 237 | : ~['"\\bfnrtv0-9xu\r\n] 238 | ; 239 | 240 | fragment EscapeCharacter 241 | : SingleEscapeCharacter 242 | | [0-9] 243 | | [xu] 244 | ; 245 | 246 | fragment LineContinuation 247 | : '\\' [\r\n\u2028\u2029] 248 | ; 249 | 250 | fragment HexDigit 251 | : [0-9a-fA-F] 252 | ; 253 | 254 | fragment DecimalIntegerLiteral 255 | : '0' 256 | | [1-9] [0-9]* 257 | ; 258 | 259 | fragment ExponentPart 260 | : [eE] [+-]? [0-9]+ 261 | ; 262 | 263 | fragment IdentifierPart 264 | : IdentifierStart 265 | | UnicodeCombiningMark 266 | | UnicodeDigit 267 | | UnicodeConnectorPunctuation 268 | | '\u200C' 269 | | '\u200D' 270 | ; 271 | 272 | fragment IdentifierStart 273 | : UnicodeLetter 274 | | [$_] 275 | | '\\' UnicodeEscapeSequence 276 | ; 277 | 278 | fragment UnicodeLetter 279 | : [\u0041-\u005A] 280 | | [\u0061-\u007A] 281 | | [\u00AA] 282 | | [\u00B5] 283 | | [\u00BA] 284 | | [\u00C0-\u00D6] 285 | | [\u00D8-\u00F6] 286 | | [\u00F8-\u021F] 287 | | [\u0222-\u0233] 288 | | [\u0250-\u02AD] 289 | | [\u02B0-\u02B8] 290 | | [\u02BB-\u02C1] 291 | | [\u02D0-\u02D1] 292 | | [\u02E0-\u02E4] 293 | | [\u02EE] 294 | | [\u037A] 295 | | [\u0386] 296 | | [\u0388-\u038A] 297 | | [\u038C] 298 | | [\u038E-\u03A1] 299 | | [\u03A3-\u03CE] 300 | | [\u03D0-\u03D7] 301 | | [\u03DA-\u03F3] 302 | | [\u0400-\u0481] 303 | | [\u048C-\u04C4] 304 | | [\u04C7-\u04C8] 305 | | [\u04CB-\u04CC] 306 | | [\u04D0-\u04F5] 307 | | [\u04F8-\u04F9] 308 | | [\u0531-\u0556] 309 | | [\u0559] 310 | | [\u0561-\u0587] 311 | | [\u05D0-\u05EA] 312 | | [\u05F0-\u05F2] 313 | | [\u0621-\u063A] 314 | | [\u0640-\u064A] 315 | | [\u0671-\u06D3] 316 | | [\u06D5] 317 | | [\u06E5-\u06E6] 318 | | [\u06FA-\u06FC] 319 | | [\u0710] 320 | | [\u0712-\u072C] 321 | | [\u0780-\u07A5] 322 | | [\u0905-\u0939] 323 | | [\u093D] 324 | | [\u0950] 325 | | [\u0958-\u0961] 326 | | [\u0985-\u098C] 327 | | [\u098F-\u0990] 328 | | [\u0993-\u09A8] 329 | | [\u09AA-\u09B0] 330 | | [\u09B2] 331 | | [\u09B6-\u09B9] 332 | | [\u09DC-\u09DD] 333 | | [\u09DF-\u09E1] 334 | | [\u09F0-\u09F1] 335 | | [\u0A05-\u0A0A] 336 | | [\u0A0F-\u0A10] 337 | | [\u0A13-\u0A28] 338 | | [\u0A2A-\u0A30] 339 | | [\u0A32-\u0A33] 340 | | [\u0A35-\u0A36] 341 | | [\u0A38-\u0A39] 342 | | [\u0A59-\u0A5C] 343 | | [\u0A5E] 344 | | [\u0A72-\u0A74] 345 | | [\u0A85-\u0A8B] 346 | | [\u0A8D] 347 | | [\u0A8F-\u0A91] 348 | | [\u0A93-\u0AA8] 349 | | [\u0AAA-\u0AB0] 350 | | [\u0AB2-\u0AB3] 351 | | [\u0AB5-\u0AB9] 352 | | [\u0ABD] 353 | | [\u0AD0] 354 | | [\u0AE0] 355 | | [\u0B05-\u0B0C] 356 | | [\u0B0F-\u0B10] 357 | | [\u0B13-\u0B28] 358 | | [\u0B2A-\u0B30] 359 | | [\u0B32-\u0B33] 360 | | [\u0B36-\u0B39] 361 | | [\u0B3D] 362 | | [\u0B5C-\u0B5D] 363 | | [\u0B5F-\u0B61] 364 | | [\u0B85-\u0B8A] 365 | | [\u0B8E-\u0B90] 366 | | [\u0B92-\u0B95] 367 | | [\u0B99-\u0B9A] 368 | | [\u0B9C] 369 | | [\u0B9E-\u0B9F] 370 | | [\u0BA3-\u0BA4] 371 | | [\u0BA8-\u0BAA] 372 | | [\u0BAE-\u0BB5] 373 | | [\u0BB7-\u0BB9] 374 | | [\u0C05-\u0C0C] 375 | | [\u0C0E-\u0C10] 376 | | [\u0C12-\u0C28] 377 | | [\u0C2A-\u0C33] 378 | | [\u0C35-\u0C39] 379 | | [\u0C60-\u0C61] 380 | | [\u0C85-\u0C8C] 381 | | [\u0C8E-\u0C90] 382 | | [\u0C92-\u0CA8] 383 | | [\u0CAA-\u0CB3] 384 | | [\u0CB5-\u0CB9] 385 | | [\u0CDE] 386 | | [\u0CE0-\u0CE1] 387 | | [\u0D05-\u0D0C] 388 | | [\u0D0E-\u0D10] 389 | | [\u0D12-\u0D28] 390 | | [\u0D2A-\u0D39] 391 | | [\u0D60-\u0D61] 392 | | [\u0D85-\u0D96] 393 | | [\u0D9A-\u0DB1] 394 | | [\u0DB3-\u0DBB] 395 | | [\u0DBD] 396 | | [\u0DC0-\u0DC6] 397 | | [\u0E01-\u0E30] 398 | | [\u0E32-\u0E33] 399 | | [\u0E40-\u0E46] 400 | | [\u0E81-\u0E82] 401 | | [\u0E84] 402 | | [\u0E87-\u0E88] 403 | | [\u0E8A] 404 | | [\u0E8D] 405 | | [\u0E94-\u0E97] 406 | | [\u0E99-\u0E9F] 407 | | [\u0EA1-\u0EA3] 408 | | [\u0EA5] 409 | | [\u0EA7] 410 | | [\u0EAA-\u0EAB] 411 | | [\u0EAD-\u0EB0] 412 | | [\u0EB2-\u0EB3] 413 | | [\u0EBD-\u0EC4] 414 | | [\u0EC6] 415 | | [\u0EDC-\u0EDD] 416 | | [\u0F00] 417 | | [\u0F40-\u0F6A] 418 | | [\u0F88-\u0F8B] 419 | | [\u1000-\u1021] 420 | | [\u1023-\u1027] 421 | | [\u1029-\u102A] 422 | | [\u1050-\u1055] 423 | | [\u10A0-\u10C5] 424 | | [\u10D0-\u10F6] 425 | | [\u1100-\u1159] 426 | | [\u115F-\u11A2] 427 | | [\u11A8-\u11F9] 428 | | [\u1200-\u1206] 429 | | [\u1208-\u1246] 430 | | [\u1248] 431 | | [\u124A-\u124D] 432 | | [\u1250-\u1256] 433 | | [\u1258] 434 | | [\u125A-\u125D] 435 | | [\u1260-\u1286] 436 | | [\u1288] 437 | | [\u128A-\u128D] 438 | | [\u1290-\u12AE] 439 | | [\u12B0] 440 | | [\u12B2-\u12B5] 441 | | [\u12B8-\u12BE] 442 | | [\u12C0] 443 | | [\u12C2-\u12C5] 444 | | [\u12C8-\u12CE] 445 | | [\u12D0-\u12D6] 446 | | [\u12D8-\u12EE] 447 | | [\u12F0-\u130E] 448 | | [\u1310] 449 | | [\u1312-\u1315] 450 | | [\u1318-\u131E] 451 | | [\u1320-\u1346] 452 | | [\u1348-\u135A] 453 | | [\u13A0-\u13B0] 454 | | [\u13B1-\u13F4] 455 | | [\u1401-\u1676] 456 | | [\u1681-\u169A] 457 | | [\u16A0-\u16EA] 458 | | [\u1780-\u17B3] 459 | | [\u1820-\u1877] 460 | | [\u1880-\u18A8] 461 | | [\u1E00-\u1E9B] 462 | | [\u1EA0-\u1EE0] 463 | | [\u1EE1-\u1EF9] 464 | | [\u1F00-\u1F15] 465 | | [\u1F18-\u1F1D] 466 | | [\u1F20-\u1F39] 467 | | [\u1F3A-\u1F45] 468 | | [\u1F48-\u1F4D] 469 | | [\u1F50-\u1F57] 470 | | [\u1F59] 471 | | [\u1F5B] 472 | | [\u1F5D] 473 | | [\u1F5F-\u1F7D] 474 | | [\u1F80-\u1FB4] 475 | | [\u1FB6-\u1FBC] 476 | | [\u1FBE] 477 | | [\u1FC2-\u1FC4] 478 | | [\u1FC6-\u1FCC] 479 | | [\u1FD0-\u1FD3] 480 | | [\u1FD6-\u1FDB] 481 | | [\u1FE0-\u1FEC] 482 | | [\u1FF2-\u1FF4] 483 | | [\u1FF6-\u1FFC] 484 | | [\u207F] 485 | | [\u2102] 486 | | [\u2107] 487 | | [\u210A-\u2113] 488 | | [\u2115] 489 | | [\u2119-\u211D] 490 | | [\u2124] 491 | | [\u2126] 492 | | [\u2128] 493 | | [\u212A-\u212D] 494 | | [\u212F-\u2131] 495 | | [\u2133-\u2139] 496 | | [\u2160-\u2183] 497 | | [\u3005-\u3007] 498 | | [\u3021-\u3029] 499 | | [\u3031-\u3035] 500 | | [\u3038-\u303A] 501 | | [\u3041-\u3094] 502 | | [\u309D-\u309E] 503 | | [\u30A1-\u30FA] 504 | | [\u30FC-\u30FE] 505 | | [\u3105-\u312C] 506 | | [\u3131-\u318E] 507 | | [\u31A0-\u31B7] 508 | | [\u3400-\u4DBF] 509 | | [\u4E00-\u9FFF] 510 | | [\uA000-\uA48C] 511 | | [\uAC00] 512 | | [\uD7A3] 513 | | [\uF900-\uFA2D] 514 | | [\uFB00-\uFB06] 515 | | [\uFB13-\uFB17] 516 | | [\uFB1D] 517 | | [\uFB1F-\uFB28] 518 | | [\uFB2A-\uFB36] 519 | | [\uFB38-\uFB3C] 520 | | [\uFB3E] 521 | | [\uFB40-\uFB41] 522 | | [\uFB43-\uFB44] 523 | | [\uFB46-\uFBB1] 524 | | [\uFBD3-\uFD3D] 525 | | [\uFD50-\uFD8F] 526 | | [\uFD92-\uFDC7] 527 | | [\uFDF0-\uFDFB] 528 | | [\uFE70-\uFE72] 529 | | [\uFE74] 530 | | [\uFE76-\uFEFC] 531 | | [\uFF21-\uFF3A] 532 | | [\uFF41-\uFF5A] 533 | | [\uFF66-\uFFBE] 534 | | [\uFFC2-\uFFC7] 535 | | [\uFFCA-\uFFCF] 536 | | [\uFFD2-\uFFD7] 537 | | [\uFFDA-\uFFDC] 538 | ; 539 | 540 | fragment UnicodeCombiningMark 541 | : [\u0300-\u034E] 542 | | [\u0360-\u0362] 543 | | [\u0483-\u0486] 544 | | [\u0591-\u05A1] 545 | | [\u05A3-\u05B9] 546 | | [\u05BB-\u05BD] 547 | | [\u05BF] 548 | | [\u05C1-\u05C2] 549 | | [\u05C4] 550 | | [\u064B-\u0655] 551 | | [\u0670] 552 | | [\u06D6-\u06DC] 553 | | [\u06DF-\u06E4] 554 | | [\u06E7-\u06E8] 555 | | [\u06EA-\u06ED] 556 | | [\u0711] 557 | | [\u0730-\u074A] 558 | | [\u07A6-\u07B0] 559 | | [\u0901-\u0903] 560 | | [\u093C] 561 | | [\u093E-\u094D] 562 | | [\u0951-\u0954] 563 | | [\u0962-\u0963] 564 | | [\u0981-\u0983] 565 | | [\u09BC-\u09C4] 566 | | [\u09C7-\u09C8] 567 | | [\u09CB-\u09CD] 568 | | [\u09D7] 569 | | [\u09E2-\u09E3] 570 | | [\u0A02] 571 | | [\u0A3C] 572 | | [\u0A3E-\u0A42] 573 | | [\u0A47-\u0A48] 574 | | [\u0A4B-\u0A4D] 575 | | [\u0A70-\u0A71] 576 | | [\u0A81-\u0A83] 577 | | [\u0ABC] 578 | | [\u0ABE-\u0AC5] 579 | | [\u0AC7-\u0AC9] 580 | | [\u0ACB-\u0ACD] 581 | | [\u0B01-\u0B03] 582 | | [\u0B3C] 583 | | [\u0B3E-\u0B43] 584 | | [\u0B47-\u0B48] 585 | | [\u0B4B-\u0B4D] 586 | | [\u0B56-\u0B57] 587 | | [\u0B82-\u0B83] 588 | | [\u0BBE-\u0BC2] 589 | | [\u0BC6-\u0BC8] 590 | | [\u0BCA-\u0BCD] 591 | | [\u0BD7] 592 | | [\u0C01-\u0C03] 593 | | [\u0C3E-\u0C44] 594 | | [\u0C46-\u0C48] 595 | | [\u0C4A-\u0C4D] 596 | | [\u0C55-\u0C56] 597 | | [\u0C82-\u0C83] 598 | | [\u0CBE-\u0CC4] 599 | | [\u0CC6-\u0CC8] 600 | | [\u0CCA-\u0CCD] 601 | | [\u0CD5-\u0CD6] 602 | | [\u0D02-\u0D03] 603 | | [\u0D3E-\u0D43] 604 | | [\u0D46-\u0D48] 605 | | [\u0D4A-\u0D4D] 606 | | [\u0D57] 607 | | [\u0D82-\u0D83] 608 | | [\u0DCA] 609 | | [\u0DCF-\u0DD4] 610 | | [\u0DD6] 611 | | [\u0DD8-\u0DDF] 612 | | [\u0DF2-\u0DF3] 613 | | [\u0E31] 614 | | [\u0E34-\u0E3A] 615 | | [\u0E47-\u0E4E] 616 | | [\u0EB1] 617 | | [\u0EB4-\u0EB9] 618 | | [\u0EBB-\u0EBC] 619 | | [\u0EC8-\u0ECD] 620 | | [\u0F18-\u0F19] 621 | | [\u0F35] 622 | | [\u0F37] 623 | | [\u0F39] 624 | | [\u0F3E-\u0F3F] 625 | | [\u0F71-\u0F84] 626 | | [\u0F86-\u0F87] 627 | | [\u0F90-\u0F97] 628 | | [\u0F99-\u0FBC] 629 | | [\u0FC6] 630 | | [\u102C-\u1032] 631 | | [\u1036-\u1039] 632 | | [\u1056-\u1059] 633 | | [\u17B4-\u17D3] 634 | | [\u18A9] 635 | | [\u20D0-\u20DC] 636 | | [\u20E1] 637 | | [\u302A-\u302F] 638 | | [\u3099-\u309A] 639 | | [\uFB1E] 640 | | [\uFE20-\uFE23] 641 | ; 642 | 643 | fragment UnicodeDigit 644 | : [\u0030-\u0039] 645 | | [\u0660-\u0669] 646 | | [\u06F0-\u06F9] 647 | | [\u0966-\u096F] 648 | | [\u09E6-\u09EF] 649 | | [\u0A66-\u0A6F] 650 | | [\u0AE6-\u0AEF] 651 | | [\u0B66-\u0B6F] 652 | | [\u0BE7-\u0BEF] 653 | | [\u0C66-\u0C6F] 654 | | [\u0CE6-\u0CEF] 655 | | [\u0D66-\u0D6F] 656 | | [\u0E50-\u0E59] 657 | | [\u0ED0-\u0ED9] 658 | | [\u0F20-\u0F29] 659 | | [\u1040-\u1049] 660 | | [\u1369-\u1371] 661 | | [\u17E0-\u17E9] 662 | | [\u1810-\u1819] 663 | | [\uFF10-\uFF19] 664 | ; 665 | 666 | fragment UnicodeConnectorPunctuation 667 | : [\u005F] 668 | | [\u203F-\u2040] 669 | | [\u30FB] 670 | | [\uFE33-\uFE34] 671 | | [\uFE4D-\uFE4F] 672 | | [\uFF3F] 673 | | [\uFF65] 674 | ; 675 | 676 | fragment RegularExpressionFirstChar 677 | : ~[*\r\n\u2028\u2029\\/[] 678 | | RegularExpressionBackslashSequence 679 | | '[' RegularExpressionClassChar* ']' 680 | ; 681 | 682 | fragment RegularExpressionChar 683 | : ~[\r\n\u2028\u2029\\/[] 684 | | RegularExpressionBackslashSequence 685 | | '[' RegularExpressionClassChar* ']' 686 | ; 687 | 688 | fragment RegularExpressionClassChar 689 | : ~[\r\n\u2028\u2029\]\\] 690 | | RegularExpressionBackslashSequence 691 | ; 692 | 693 | fragment RegularExpressionBackslashSequence 694 | : '\\' ~[\r\n\u2028\u2029] 695 | ; 696 | -------------------------------------------------------------------------------- /src/grammar/tsparser.g4: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 by Bart Kiers (original author) and Alexandre Vitorelli (contributor -> ported to CSharp) 5 | * Copyright (c) 2017 by Ivan Kochurkin (Positive Technologies): 6 | added ECMAScript 6 support, cleared and transformed to the universal grammar. 7 | * Copyright (c) 2018 by Juan Alvarez (contributor -> ported to Go) 8 | * Copyright (c) 2019 by Andrii Artiushok (contributor -> added TypeScript support) 9 | * 10 | * Permission is hereby granted, free of charge, to any person 11 | * obtaining a copy of this software and associated documentation 12 | * files (the "Software"), to deal in the Software without 13 | * restriction, including without limitation the rights to use, 14 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the 16 | * Software is furnished to do so, subject to the following 17 | * conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 24 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 26 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 27 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 29 | * OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | parser grammar tsparser; 32 | 33 | options { 34 | tokenVocab=tslexer; 35 | superClass=TypeScriptParserBase; 36 | } 37 | 38 | // SupportSyntax 39 | 40 | initializer 41 | : '=' singleExpression 42 | ; 43 | 44 | bindingPattern 45 | : (arrayLiteral | objectLiteral) 46 | ; 47 | 48 | // TypeScript SPart 49 | // A.1 Types 50 | 51 | typeParameters 52 | : '<' typeParameterList? '>' 53 | ; 54 | 55 | typeParameterList 56 | : typeParameter (',' typeParameter)* 57 | ; 58 | 59 | typeParameter 60 | : Identifier constraint? 61 | | typeParameters 62 | ; 63 | 64 | constraint 65 | : 'extends' type_ 66 | ; 67 | 68 | typeArguments 69 | : '<' typeArgumentList? '>' 70 | ; 71 | 72 | typeArgumentList 73 | : typeArgument (',' typeArgument)* 74 | ; 75 | 76 | typeArgument 77 | : type_ 78 | ; 79 | 80 | type_ 81 | : unionOrIntersectionOrPrimaryType 82 | | functionType 83 | | constructorType 84 | | typeGeneric 85 | | StringLiteral 86 | ; 87 | 88 | unionOrIntersectionOrPrimaryType 89 | : unionOrIntersectionOrPrimaryType '|' unionOrIntersectionOrPrimaryType #Union 90 | | unionOrIntersectionOrPrimaryType '&' unionOrIntersectionOrPrimaryType #Intersection 91 | | primaryType #Primary 92 | ; 93 | 94 | primaryType 95 | : '(' type_ ')' #ParenthesizedPrimType 96 | | predefinedType #PredefinedPrimType 97 | | typeReference #ReferencePrimType 98 | | objectType #ObjectPrimType 99 | | primaryType {notLineTerminator()}? '[' ']' #ArrayPrimType 100 | | '[' tupleElementTypes ']' #TuplePrimType 101 | | typeQuery #QueryPrimType 102 | | This #ThisPrimType 103 | | typeReference Is primaryType #RedefinitionOfType 104 | ; 105 | 106 | predefinedType 107 | : Number 108 | | Boolean 109 | | String 110 | | Symbol 111 | | Void 112 | ; 113 | 114 | typeReference 115 | : typeName nestedTypeGeneric? 116 | ; 117 | 118 | nestedTypeGeneric 119 | : typeIncludeGeneric 120 | | typeGeneric 121 | ; 122 | 123 | // I tried recursive include, but it's not working. 124 | // typeGeneric 125 | // : '<' typeArgumentList typeGeneric?'>' 126 | // ; 127 | // 128 | // TODO: Fix recursive 129 | // 130 | typeGeneric 131 | : '<' typeArgumentList '>' 132 | ; 133 | 134 | typeIncludeGeneric 135 | :'<' typeArgumentList '<' typeArgumentList ('>' bindingPattern '>' | '>>') 136 | ; 137 | 138 | typeName 139 | : Identifier 140 | | namespaceName 141 | ; 142 | 143 | objectType 144 | : '{' typeBody? '}' 145 | ; 146 | 147 | typeBody 148 | : typeMemberList (SemiColon | ',')? 149 | ; 150 | 151 | typeMemberList 152 | : typeMember ((SemiColon | ',') typeMember)* 153 | ; 154 | 155 | typeMember 156 | : propertySignatur 157 | | callSignature 158 | | constructSignature 159 | | indexSignature 160 | | methodSignature ('=>' type_)? 161 | ; 162 | 163 | arrayType 164 | : primaryType {notLineTerminator()}? '[' ']' 165 | ; 166 | 167 | tupleType 168 | : '[' tupleElementTypes ']' 169 | ; 170 | 171 | tupleElementTypes 172 | : type_ (',' type_)* 173 | ; 174 | 175 | functionType 176 | : typeParameters? '(' parameterList? ')' '=>' type_ 177 | ; 178 | 179 | constructorType 180 | : 'new' typeParameters? '(' parameterList? ')' '=>' type_ 181 | ; 182 | 183 | typeQuery 184 | : 'typeof' typeQueryExpression 185 | ; 186 | 187 | typeQueryExpression 188 | : Identifier 189 | | (identifierName '.')+ identifierName 190 | ; 191 | 192 | propertySignatur 193 | : ReadOnly? propertyName '?'? typeAnnotation? ('=>' type_)? 194 | ; 195 | 196 | typeAnnotation 197 | : ':' type_ 198 | ; 199 | 200 | callSignature 201 | : typeParameters? '(' parameterList? ')' typeAnnotation? 202 | ; 203 | 204 | parameterList 205 | : restParameter 206 | | parameter (',' parameter)* (',' restParameter)? 207 | ; 208 | 209 | requiredParameterList 210 | : requiredParameter (',' requiredParameter)* 211 | ; 212 | 213 | parameter 214 | : requiredParameter 215 | | optionalParameter 216 | ; 217 | 218 | optionalParameter 219 | : decoratorList? ( accessibilityModifier? identifierOrPattern ('?' typeAnnotation? | typeAnnotation? initializer)) 220 | ; 221 | 222 | restParameter 223 | : '...' singleExpression typeAnnotation? 224 | ; 225 | 226 | requiredParameter 227 | : decoratorList? accessibilityModifier? identifierOrPattern typeAnnotation? 228 | ; 229 | 230 | accessibilityModifier 231 | : Public 232 | | Private 233 | | Protected 234 | ; 235 | 236 | identifierOrPattern 237 | : identifierName 238 | | bindingPattern 239 | ; 240 | 241 | constructSignature 242 | : 'new' typeParameters? '(' parameterList? ')' typeAnnotation? 243 | ; 244 | 245 | indexSignature 246 | : '[' Identifier ':' (Number|String) ']' typeAnnotation 247 | ; 248 | 249 | methodSignature 250 | : propertyName '?'? callSignature 251 | ; 252 | 253 | typeAliasDeclaration 254 | : 'type' Identifier typeParameters? '=' type_ SemiColon 255 | ; 256 | 257 | constructorDeclaration 258 | : accessibilityModifier? Constructor '(' formalParameterList? ')' ( ('{' functionBody '}') | SemiColon)? 259 | ; 260 | 261 | // A.5 Interface 262 | 263 | interfaceDeclaration 264 | : Export? Declare? Interface Identifier typeParameters? interfaceExtendsClause? objectType SemiColon? 265 | ; 266 | 267 | interfaceExtendsClause 268 | : Extends classOrInterfaceTypeList 269 | ; 270 | 271 | classOrInterfaceTypeList 272 | : typeReference (',' typeReference)* 273 | ; 274 | 275 | // A.7 Interface 276 | 277 | enumDeclaration 278 | : Const? Enum Identifier '{' enumBody? '}' 279 | ; 280 | 281 | enumBody 282 | : enumMemberList ','? 283 | ; 284 | 285 | enumMemberList 286 | : enumMember (',' enumMember)* 287 | ; 288 | 289 | enumMember 290 | : propertyName ('=' singleExpression)? 291 | ; 292 | 293 | // A.8 Namespaces 294 | 295 | namespaceDeclaration 296 | : Namespace namespaceName '{' statementList? '}' 297 | ; 298 | 299 | namespaceName 300 | : Identifier ('.'+ Identifier)* 301 | ; 302 | 303 | importAliasDeclaration 304 | : Identifier '=' namespaceName SemiColon 305 | ; 306 | 307 | // Ext.2 Additions to 1.8: Decorators 308 | 309 | decoratorList 310 | : decorator+ ; 311 | 312 | decorator 313 | : '@' (decoratorMemberExpression | decoratorCallExpression) 314 | ; 315 | 316 | decoratorMemberExpression 317 | : Identifier 318 | | decoratorMemberExpression '.' identifierName 319 | | '(' singleExpression ')' 320 | ; 321 | 322 | decoratorCallExpression 323 | : decoratorMemberExpression arguments; 324 | 325 | // ECMAPart 326 | program 327 | : sourceElements? EOF 328 | ; 329 | 330 | sourceElement 331 | : Export? statement 332 | ; 333 | 334 | statement 335 | : block 336 | | variableStatement 337 | | importStatement 338 | | exportStatement 339 | | emptyStatement 340 | | abstractDeclaration //ADDED 341 | | decoratorList 342 | | classDeclaration 343 | | interfaceDeclaration //ADDED 344 | | namespaceDeclaration //ADDED 345 | | ifStatement 346 | | iterationStatement 347 | | continueStatement 348 | | breakStatement 349 | | returnStatement 350 | | yieldStatement 351 | | withStatement 352 | | labelledStatement 353 | | switchStatement 354 | | throwStatement 355 | | tryStatement 356 | | debuggerStatement 357 | | functionDeclaration 358 | | arrowFunctionDeclaration 359 | | generatorFunctionDeclaration 360 | | typeAliasDeclaration //ADDED 361 | | enumDeclaration //ADDED 362 | | expressionStatement 363 | | Export statement 364 | ; 365 | 366 | block 367 | : '{' statementList? '}' 368 | ; 369 | 370 | statementList 371 | : statement+ 372 | ; 373 | 374 | abstractDeclaration 375 | : Abstract (Identifier callSignature | variableStatement) eos 376 | ; 377 | 378 | importStatement 379 | : Import (fromBlock | importAliasDeclaration) 380 | ; 381 | 382 | fromBlock 383 | : (Multiply | multipleImportStatement) (As identifierName)? From StringLiteral eos 384 | ; 385 | 386 | multipleImportStatement 387 | : (identifierName ',')? '{' identifierName (',' identifierName)* '}' 388 | ; 389 | 390 | exportStatement 391 | : Export Default? (fromBlock | statement) 392 | ; 393 | 394 | variableStatement 395 | : bindingPattern typeAnnotation? initializer SemiColon? 396 | | accessibilityModifier? varModifier? ReadOnly? variableDeclarationList SemiColon? 397 | | Declare varModifier? variableDeclarationList SemiColon? 398 | ; 399 | 400 | variableDeclarationList 401 | : variableDeclaration (',' variableDeclaration)* 402 | ; 403 | 404 | variableDeclaration 405 | : ( identifierOrKeyWord | arrayLiteral | objectLiteral) typeAnnotation? singleExpression? ('=' typeParameters? singleExpression)? // ECMAScript 6: Array & Object Matching 406 | ; 407 | 408 | emptyStatement 409 | : SemiColon 410 | ; 411 | 412 | expressionStatement 413 | : {this.notOpenBraceAndNotFunction()}? expressionSequence SemiColon? 414 | ; 415 | 416 | ifStatement 417 | : If '(' expressionSequence ')' statement (Else statement)? 418 | ; 419 | 420 | 421 | iterationStatement 422 | : Do statement While '(' expressionSequence ')' eos # DoStatement 423 | | While '(' expressionSequence ')' statement # WhileStatement 424 | | For '(' expressionSequence? SemiColon expressionSequence? SemiColon expressionSequence? ')' statement # ForStatement 425 | | For '(' varModifier variableDeclarationList SemiColon expressionSequence? SemiColon expressionSequence? ')' 426 | statement # ForVarStatement 427 | | For '(' singleExpression (In | Identifier{this.p("of")}?) expressionSequence ')' statement # ForInStatement 428 | | For '(' varModifier variableDeclaration (In | Identifier{this.p("of")}?) expressionSequence ')' statement # ForVarInStatement 429 | ; 430 | 431 | varModifier 432 | : Var 433 | | Let 434 | | Const 435 | ; 436 | 437 | continueStatement 438 | : Continue ({this.notLineTerminator()}? Identifier)? eos 439 | ; 440 | 441 | breakStatement 442 | : Break ({this.notLineTerminator()}? Identifier)? eos 443 | ; 444 | 445 | returnStatement 446 | : Return ({this.notLineTerminator()}? expressionSequence)? eos 447 | ; 448 | 449 | yieldStatement 450 | : Yield ({this.notLineTerminator()}? expressionSequence)? eos 451 | ; 452 | 453 | withStatement 454 | : With '(' expressionSequence ')' statement 455 | ; 456 | 457 | switchStatement 458 | : Switch '(' expressionSequence ')' caseBlock 459 | ; 460 | 461 | caseBlock 462 | : '{' caseClauses? (defaultClause caseClauses?)? '}' 463 | ; 464 | 465 | caseClauses 466 | : caseClause+ 467 | ; 468 | 469 | caseClause 470 | : Case expressionSequence ':' statementList? 471 | ; 472 | 473 | defaultClause 474 | : Default ':' statementList? 475 | ; 476 | 477 | labelledStatement 478 | : Identifier ':' statement 479 | ; 480 | 481 | throwStatement 482 | : Throw {this.notLineTerminator()}? expressionSequence eos 483 | ; 484 | 485 | tryStatement 486 | : Try block (catchProduction finallyProduction? | finallyProduction) 487 | ; 488 | 489 | catchProduction 490 | : Catch '(' Identifier ')' block 491 | ; 492 | 493 | finallyProduction 494 | : Finally block 495 | ; 496 | 497 | debuggerStatement 498 | : Debugger eos 499 | ; 500 | 501 | functionDeclaration 502 | : Function Identifier callSignature ( ('{' functionBody '}') | SemiColon) 503 | ; 504 | 505 | //Ovveride ECMA 506 | classDeclaration 507 | : Abstract? Class Identifier typeParameters? classHeritage classTail 508 | ; 509 | 510 | classHeritage 511 | : classExtendsClause? implementsClause? 512 | ; 513 | 514 | classTail 515 | : '{' classElement* '}' 516 | ; 517 | 518 | classExtendsClause 519 | : Extends typeReference 520 | ; 521 | 522 | implementsClause 523 | : Implements classOrInterfaceTypeList 524 | ; 525 | 526 | // Classes modified 527 | classElement 528 | : constructorDeclaration 529 | | decoratorList? propertyMemberDeclaration 530 | | indexMemberDeclaration 531 | | statement 532 | ; 533 | 534 | propertyMemberDeclaration 535 | : propertyMemberBase propertyName '?'? typeAnnotation? initializer? SemiColon # PropertyDeclarationExpression 536 | | propertyMemberBase propertyName callSignature ( ('{' functionBody '}') | SemiColon) # MethodDeclarationExpression 537 | | propertyMemberBase (getAccessor | setAccessor) # GetterSetterDeclarationExpression 538 | | abstractDeclaration # AbstractMemberDeclaration 539 | ; 540 | 541 | propertyMemberBase 542 | : Async? accessibilityModifier? Static? ReadOnly? 543 | ; 544 | 545 | indexMemberDeclaration 546 | : indexSignature SemiColon 547 | ; 548 | 549 | generatorMethod 550 | : '*'? Identifier '(' formalParameterList? ')' '{' functionBody '}' 551 | ; 552 | 553 | generatorFunctionDeclaration 554 | : Function '*' Identifier? '(' formalParameterList? ')' '{' functionBody '}' 555 | ; 556 | 557 | generatorBlock 558 | : '{' generatorDefinition (',' generatorDefinition)* ','? '}' 559 | ; 560 | 561 | generatorDefinition 562 | : '*' iteratorDefinition 563 | ; 564 | 565 | iteratorBlock 566 | : '{' iteratorDefinition (',' iteratorDefinition)* ','? '}' 567 | ; 568 | 569 | iteratorDefinition 570 | : '[' singleExpression ']' '(' formalParameterList? ')' '{' functionBody '}' 571 | ; 572 | 573 | formalParameterList 574 | : formalParameterArg (',' formalParameterArg)* (',' lastFormalParameterArg)? 575 | | lastFormalParameterArg 576 | | arrayLiteral // ECMAScript 6: Parameter Context Matching 577 | | objectLiteral (':' formalParameterList)? // ECMAScript 6: Parameter Context Matching 578 | ; 579 | 580 | formalParameterArg 581 | : decorator? accessibilityModifier? identifierOrKeyWord '?'? typeAnnotation? ('=' singleExpression)? // ECMAScript 6: Initialization 582 | ; 583 | 584 | lastFormalParameterArg // ECMAScript 6: Rest Parameter 585 | : Ellipsis Identifier 586 | ; 587 | 588 | functionBody 589 | : sourceElements? 590 | ; 591 | 592 | sourceElements 593 | : sourceElement+ 594 | ; 595 | 596 | arrayLiteral 597 | : ('[' elementList? ']') 598 | ; 599 | 600 | elementList 601 | : arrayElement (','+ arrayElement)* 602 | ; 603 | 604 | arrayElement // ECMAScript 6: Spread Operator 605 | : Ellipsis? (singleExpression | Identifier) ','? 606 | ; 607 | 608 | objectLiteral 609 | : '{' (propertyAssignment (',' propertyAssignment)*)? ','? '}' 610 | ; 611 | 612 | // MODIFIED 613 | propertyAssignment 614 | : propertyName (':' |'=') singleExpression # PropertyExpressionAssignment 615 | | '[' singleExpression ']' ':' singleExpression # ComputedPropertyExpressionAssignment 616 | | getAccessor # PropertyGetter 617 | | setAccessor # PropertySetter 618 | | generatorMethod # MethodProperty 619 | | identifierOrKeyWord # PropertyShorthand 620 | | restParameter # RestParameterInObject 621 | ; 622 | 623 | getAccessor 624 | : getter '(' ')' typeAnnotation? '{' functionBody '}' 625 | ; 626 | 627 | setAccessor 628 | : setter '(' ( Identifier | bindingPattern) typeAnnotation? ')' '{' functionBody '}' 629 | ; 630 | 631 | propertyName 632 | : identifierName 633 | | StringLiteral 634 | | numericLiteral 635 | ; 636 | 637 | arguments 638 | : '(' (argumentList ','?)? ')' 639 | ; 640 | 641 | argumentList 642 | : argument (',' argument)* 643 | ; 644 | 645 | argument // ECMAScript 6: Spread Operator 646 | : Ellipsis? (singleExpression | Identifier) 647 | ; 648 | 649 | expressionSequence 650 | : singleExpression (',' singleExpression)* 651 | ; 652 | 653 | functionExpressionDeclaration 654 | : Function Identifier? '(' formalParameterList? ')' typeAnnotation? '{' functionBody '}' 655 | ; 656 | 657 | singleExpression 658 | : functionExpressionDeclaration # FunctionExpression 659 | | arrowFunctionDeclaration # ArrowFunctionExpression // ECMAScript 6 660 | | Class Identifier? classTail # ClassExpression 661 | | singleExpression '[' expressionSequence ']' # MemberIndexExpression 662 | | singleExpression '.' identifierName nestedTypeGeneric? # MemberDotExpression 663 | | singleExpression arguments # ArgumentsExpression 664 | | New singleExpression typeArguments? arguments? # NewExpression 665 | | singleExpression {this.notLineTerminator()}? '++' # PostIncrementExpression 666 | | singleExpression {this.notLineTerminator()}? '--' # PostDecreaseExpression 667 | | Delete singleExpression # DeleteExpression 668 | | Void singleExpression # VoidExpression 669 | | Typeof singleExpression # TypeofExpression 670 | | '++' singleExpression # PreIncrementExpression 671 | | '--' singleExpression # PreDecreaseExpression 672 | | '+' singleExpression # UnaryPlusExpression 673 | | '-' singleExpression # UnaryMinusExpression 674 | | '~' singleExpression # BitNotExpression 675 | | '!' singleExpression # NotExpression 676 | | singleExpression ('*' | '/' | '%') singleExpression # MultiplicativeExpression 677 | | singleExpression ('+' | '-') singleExpression # AdditiveExpression 678 | | singleExpression ('<<' | '>>' | '>>>') singleExpression # BitShiftExpression 679 | | singleExpression ('<' | '>' | '<=' | '>=') singleExpression # RelationalExpression 680 | | singleExpression Instanceof singleExpression # InstanceofExpression 681 | | singleExpression In singleExpression # InExpression 682 | | singleExpression ('==' | '!=' | '===' | '!==') singleExpression # EqualityExpression 683 | | singleExpression '&' singleExpression # BitAndExpression 684 | | singleExpression '^' singleExpression # BitXOrExpression 685 | | singleExpression '|' singleExpression # BitOrExpression 686 | | singleExpression '&&' singleExpression # LogicalAndExpression 687 | | singleExpression '||' singleExpression # LogicalOrExpression 688 | | singleExpression '?' singleExpression ':' singleExpression # TernaryExpression 689 | | singleExpression '=' singleExpression # AssignmentExpression 690 | | singleExpression assignmentOperator singleExpression # AssignmentOperatorExpression 691 | | singleExpression TemplateStringLiteral # TemplateStringExpression // ECMAScript 6 692 | | iteratorBlock # IteratorsExpression // ECMAScript 6 693 | | generatorBlock # GeneratorsExpression // ECMAScript 6 694 | | generatorFunctionDeclaration # GeneratorsFunctionExpression // ECMAScript 6 695 | | yieldStatement # YieldExpression // ECMAScript 6 696 | | This # ThisExpression 697 | | identifierName singleExpression? # IdentifierExpression 698 | | Super # SuperExpression 699 | | literal # LiteralExpression 700 | | arrayLiteral # ArrayLiteralExpression 701 | | objectLiteral # ObjectLiteralExpression 702 | | '(' expressionSequence ')' # ParenthesizedExpression 703 | | typeArguments expressionSequence? # GenericTypes 704 | | singleExpression As asExpression # CastAsExpression 705 | ; 706 | 707 | asExpression 708 | : predefinedType ('[' ']')? 709 | | singleExpression 710 | ; 711 | 712 | arrowFunctionDeclaration 713 | : Async? arrowFunctionParameters typeAnnotation? '=>' arrowFunctionBody 714 | ; 715 | 716 | arrowFunctionParameters 717 | : Identifier 718 | | '(' formalParameterList? ')' 719 | ; 720 | 721 | arrowFunctionBody 722 | : singleExpression 723 | | '{' functionBody '}' 724 | ; 725 | 726 | assignmentOperator 727 | : '*=' 728 | | '/=' 729 | | '%=' 730 | | '+=' 731 | | '-=' 732 | | '<<=' 733 | | '>>=' 734 | | '>>>=' 735 | | '&=' 736 | | '^=' 737 | | '|=' 738 | ; 739 | 740 | literal 741 | : NullLiteral 742 | | BooleanLiteral 743 | | StringLiteral 744 | | TemplateStringLiteral 745 | | RegularExpressionLiteral 746 | | numericLiteral 747 | ; 748 | 749 | numericLiteral 750 | : DecimalLiteral 751 | | HexIntegerLiteral 752 | | OctalIntegerLiteral 753 | | OctalIntegerLiteral2 754 | | BinaryIntegerLiteral 755 | ; 756 | 757 | identifierName 758 | : Identifier 759 | | reservedWord 760 | ; 761 | 762 | identifierOrKeyWord 763 | : Identifier 764 | | TypeAlias 765 | | Require 766 | ; 767 | 768 | reservedWord 769 | : keyword 770 | | NullLiteral 771 | | BooleanLiteral 772 | ; 773 | 774 | keyword 775 | : Break 776 | | Do 777 | | Instanceof 778 | | Typeof 779 | | Case 780 | | Else 781 | | New 782 | | Var 783 | | Catch 784 | | Finally 785 | | Return 786 | | Void 787 | | Continue 788 | | For 789 | | Switch 790 | | While 791 | | Debugger 792 | | Function 793 | | This 794 | | With 795 | | Default 796 | | If 797 | | Throw 798 | | Delete 799 | | In 800 | | Try 801 | | ReadOnly 802 | | Async 803 | | From 804 | | Class 805 | | Enum 806 | | Extends 807 | | Super 808 | | Const 809 | | Export 810 | | Import 811 | | Implements 812 | | Let 813 | | Private 814 | | Public 815 | | Interface 816 | | Package 817 | | Protected 818 | | Static 819 | | Yield 820 | | Get 821 | | Set 822 | | Require 823 | | TypeAlias 824 | | String 825 | ; 826 | 827 | getter 828 | : Get propertyName 829 | ; 830 | 831 | setter 832 | : Set propertyName 833 | ; 834 | 835 | eos 836 | : SemiColon 837 | | EOF 838 | | {this.lineTerminatorAhead()}? 839 | | {this.closeBrace()}? 840 | ; -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { tsparser } from './grammar/antlr/tsparser'; 2 | 3 | tsparser; 4 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "allowJs": true, 8 | "skipLibCheck": true, 9 | "forceConsistentCasingInFileNames": true 10 | }, 11 | "exclude": ["./jest.config.js", "src/grammar/antlr"] 12 | } 13 | --------------------------------------------------------------------------------