-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose cts-dts-gen on root chevrotain package (#1713)
- Loading branch information
Showing
51 changed files
with
1,146 additions
and
353 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
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
69 changes: 69 additions & 0 deletions
69
examples/implementation_languages/typescript/json_cst.d.ts
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { CstNode, ICstVisitor, IToken } from "chevrotain"; | ||
|
||
export interface JsonCstNode extends CstNode { | ||
name: "json"; | ||
children: JsonCstChildren; | ||
} | ||
|
||
export type JsonCstChildren = { | ||
object?: ObjectCstNode[]; | ||
array?: ArrayCstNode[]; | ||
}; | ||
|
||
export interface ObjectCstNode extends CstNode { | ||
name: "object"; | ||
children: ObjectCstChildren; | ||
} | ||
|
||
export type ObjectCstChildren = { | ||
LCurly: IToken[]; | ||
objectItem?: ObjectItemCstNode[]; | ||
Comma?: IToken[]; | ||
RCurly: IToken[]; | ||
}; | ||
|
||
export interface ObjectItemCstNode extends CstNode { | ||
name: "objectItem"; | ||
children: ObjectItemCstChildren; | ||
} | ||
|
||
export type ObjectItemCstChildren = { | ||
StringLiteral: IToken[]; | ||
Colon: IToken[]; | ||
value: ValueCstNode[]; | ||
}; | ||
|
||
export interface ArrayCstNode extends CstNode { | ||
name: "array"; | ||
children: ArrayCstChildren; | ||
} | ||
|
||
export type ArrayCstChildren = { | ||
LSquare: IToken[]; | ||
value?: ValueCstNode[]; | ||
Comma?: IToken[]; | ||
RSquare: IToken[]; | ||
}; | ||
|
||
export interface ValueCstNode extends CstNode { | ||
name: "value"; | ||
children: ValueCstChildren; | ||
} | ||
|
||
export type ValueCstChildren = { | ||
StringLiteral?: IToken[]; | ||
NumberLiteral?: IToken[]; | ||
object?: ObjectCstNode[]; | ||
array?: ArrayCstNode[]; | ||
True?: IToken[]; | ||
False?: IToken[]; | ||
Null?: IToken[]; | ||
}; | ||
|
||
export interface ICstNodeVisitor<IN, OUT> extends ICstVisitor<IN, OUT> { | ||
json(children: JsonCstChildren, param?: IN): OUT; | ||
object(children: ObjectCstChildren, param?: IN): OUT; | ||
objectItem(children: ObjectItemCstChildren, param?: IN): OUT; | ||
array(children: ArrayCstChildren, param?: IN): OUT; | ||
value(children: ValueCstChildren, param?: IN): OUT; | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/implementation_languages/typescript/scripts/gen_dts_signatures.js
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* This is a minimal script that generates TypeScript definitions | ||
* from a Chevrotain parser. | ||
*/ | ||
const { writeFileSync } = require("fs") | ||
const { resolve } = require("path") | ||
const { generateCstDts } = require("chevrotain") | ||
const { productions } = require("../typescript_json") | ||
|
||
const dtsString = generateCstDts(productions) | ||
const dtsPath = resolve(__dirname, "..", "json_cst.d.ts") | ||
writeFileSync(dtsPath, dtsString) |
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
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
Oops, something went wrong.