Is there a formal (ideally BNF) typescript js language grammar (or only typescript subset)? [closed]
Asked Answered
A

4

16

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 analyzing as plugin to one simple linux IDE for GNOME.

Anemography answered 4/10, 2012 at 5:44 Comment(1)
Why can't you just use the compiler itself to build the AST? It's open source after all...Pfister
N
8

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

Narration answered 27/12, 2017 at 21:30 Comment(1)
There was actually a fun to read holiwar with devs on that matter in a ticket of typescript repo. The conclusion was to drop the specification because they have no resources to keep it up to date I take it.Preposterous
P
3

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

Praetor answered 25/1, 2013 at 19:30 Comment(0)
N
2

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

Necrophilia answered 15/10, 2020 at 9:15 Comment(0)
V
0

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

Valediction answered 4/10, 2012 at 6:21 Comment(3)
He is asking for a grammar definition like coffeescript.org/documentation/docs/grammar.html .Runge
It helps to find out which tokens are used and how tey are defined, but it is only lexer part.I need a set of rules in some formal notation to create parser and to be able to build AST from the given typescript text.Anemography
Chrome warns about that link: "The site ahead contains harmful programs"Accent

© 2022 - 2024 — McMap. All rights reserved.