-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript] Fix #3314 -- base classes out of date, using obsolete an…
…tlr4ts fork. (#4264) * Fix #3314 * Update readme * Add TypeScript port. * Move "not working" example(s) to examples/ and fix desc.xml to parse only .ts files in examples/ not recursively. * Update README.md * Undoing "example_not_work" because Interface.ts parses..
- Loading branch information
Showing
6 changed files
with
30 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,27 @@ | ||
# TypeScript grammar | ||
|
||
This TypeScript grammar does not exactly correspond to the TypeScript standard. | ||
The main goal during developing was practical usage, performance, and clarity | ||
(getting rid of duplicates). | ||
|
||
## Universal Actions & Semantic Predicates | ||
|
||
Some modern TypeScript syntax can not be handled with standard context-free | ||
grammars, for example detection of the `get` keyword in getters and `get` identifiers | ||
in other cases. Moreover, some parser options can be defined externally (`use strict`) | ||
and should be considered during the parsing process. | ||
|
||
For such complex syntax, [actions](https://github.com/antlr/antlr4/blob/master/doc/actions.md) and | ||
[predicates](https://github.com/antlr/antlr4/blob/master/doc/predicates.md) are | ||
used. This is a second grammar in repository that attempts to use **universal** | ||
actions and predicates. At least, it works for **C#** and **Java** runtimes. | ||
|
||
Consider the `getter` rule in grammar: | ||
|
||
```ANTLR | ||
getter | ||
: Identifier{p("get")}? propertyName | ||
; | ||
``` | ||
|
||
Instruction `p("get")` stands for *get the previous token value and return a boolean | ||
value as a result of comparison to "get" string*. | ||
|
||
The **Java** runtime is described by the following code in [Java/TypeScriptLexerBase.java](Java/TypeScriptLexerBase.java) | ||
|
||
```Java | ||
protected boolean prev(String str) { | ||
return _input.LT(-1).getText().equals(str); | ||
} | ||
``` | ||
|
||
The **C#** runtime, by Sam Harwell, is described by | ||
[CSharp/TypeScriptParserBase.cs](CSharp/TypeScriptParserBase.cs) | ||
## Authors | ||
|
||
```CSharp | ||
protected bool prev(string str) | ||
{ | ||
return _input.LT(-1).Text.Equals(str); | ||
} | ||
``` | ||
|
||
Furthermore, the [`superClass`](https://github.com/antlr/antlr4/blob/master/doc/options.md) | ||
lexer and parser grammar files options should be defined in the following manner: | ||
|
||
```ANTLR | ||
options { | ||
tokenVocab=TypeScriptLexer; | ||
superClass=TypeScriptBaseParser; | ||
} | ||
``` | ||
|
||
Runtimes super class names (`TypeScriptLexer`, `TypeScriptParser`) should be | ||
the same, for correct parser generation. | ||
|
||
## Syntax support | ||
|
||
Based on [JavaScript grammar](https://github.com/loonydev/grammars-v4/tree/master/javascript) by [Positive Technologies](https://github.com/PositiveTechnologies) | ||
* Andrii Artiushok (2019) - initial version | ||
|
||
### TypeScript | ||
## Description | ||
|
||
See the [examples](examples) directory for test data files. | ||
This TypeScript grammar does not exactly correspond to the TypeScript standard. | ||
The main goal during developing was practical usage, performance, and clarity | ||
(getting rid of duplicates). | ||
|
||
## Main contributors | ||
The syntax is based on [JavaScript grammar](https://github.com/loonydev/grammars-v4/tree/master/javascript) | ||
by [Positive Technologies](https://github.com/PositiveTechnologies). | ||
|
||
* Andrii Artiushok (2019) - initial version | ||
## Links | ||
|
||
* https://www.typescriptlang.org/ | ||
* https://github.com/Microsoft/TypeScript/blob/730f18955dc17068be33691f0fb0e0285ebbf9f5/doc/spec.md -- the abandoned specification. | ||
|
||
## License | ||
|
||
[MIT](https://opensource.org/licenses/MIT) | ||
|
||
## Issues | ||
|
||
* The grammar is very old and there are many ambiguities: primaryType Decision 11; singleExpression Decision 236; etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd"> | ||
<antlr-version>^4.7</antlr-version> | ||
<targets>CSharp;Java</targets> | ||
<targets>CSharp;Java;TypeScript</targets> | ||
<inputs>examples/*.ts</inputs> | ||
</desc> |
File renamed without changes.