Is there a formal (ideally BNF) typescript js language grammar (or only typescript subset)?

后端 未结 4 1674
说谎
说谎 2020-12-29 09:23

I\'m looking for the Typescript grammar. Not the parser-lexer, but only the formal grammar description. I want to implement ts it\'s code folding and basic static code analy

相关标签:
4条回答
  • 2020-12-29 10:00

    Maybe you can find references in the source code, e.g. compiler/tokens.js

    0 讨论(0)
  • 2020-12-29 10:15

    The formal grammar is in Appendix A of the TypeScript Language Reference, version 1.8 if which is found here or here (for current version)

    0 讨论(0)
  • 2020-12-29 10:20

    Since typescript is a strict superset of Ecmascript 5 (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf/), you could exend any ecmascript bnf with syntax definitions from the Typescript spec.

    A starting point could be: http://www.antlr3.org/grammar/1153976512034/ecmascriptA3.g

    0 讨论(0)
  • 2020-12-29 10:21

    An ANTLR4 grammar, but admittedly "not exactly ... to TypeScript standard" (it's a pain there are so few official grammars for existing programming languages):

    https://github.com/antlr/grammars-v4/tree/master/typescript

    0 讨论(0)
提交回复
热议问题