-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(parser): prep to generate static parser
Sorry for the commented out code; as you can see, I copied the lexer generator and will drop in code to generate the static parser there. Added some comments noting stuff I want to do. Renamed `parser/src/parse.ts` to `parser/src/definition.ts` so that I can write the static parser to `parser/src/parse.ts`. Also changed `parseWithTable` to take an augmented grammar.
- Loading branch information
Showing
17 changed files
with
113 additions
and
43 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
File renamed without changes.
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Generates the parser implementation and writes it to src/parse.ts. | ||
* | ||
* Run this with `make parser`. | ||
*/ | ||
|
||
// import {print} from '@masochist/codegen'; | ||
// import path from 'path'; | ||
// import {promises as fs} from 'fs'; | ||
|
||
// import definition from '../definition'; | ||
// import build from '../build'; | ||
// | ||
// import type {Stats} from '../build'; | ||
|
||
async function main() { | ||
// const stats: Stats = {}; | ||
// const ast = build(definition, stats); | ||
// const source = print(ast); | ||
// const file = path.join(__dirname, '..', '..', 'src', 'parse.ts'); | ||
// | ||
// // We write only if different, for the sake of Make... | ||
// let current; | ||
// try { | ||
// current = await fs.readFile(file, 'utf8'); | ||
// } catch { | ||
// // Doesn't exist. | ||
// } | ||
// if (current !== source) { | ||
// await fs.writeFile(file, source, 'utf8'); | ||
// } | ||
// | ||
// console.table(stats); | ||
} | ||
|
||
main().catch((error) => { | ||
console.log(error); | ||
process.exit(1); | ||
}); |
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,28 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import getAugmentedGrammar from './getAugmentedGrammar'; | ||
import getItemSets from './getItemSets'; | ||
import getParseTable from './getParseTable'; | ||
import itemSetsToTransitionTable from './itemSetsToTransitionTable'; | ||
import parseDSL from './parseDSL'; | ||
|
||
const grammarDeclaration = fs.readFileSync( | ||
path.join(__dirname, '..', 'src', 'graphql.grammar'), | ||
'utf8', | ||
); | ||
|
||
// Numerous tests rely on the unaugmented grammar. | ||
export const unaugmentedGrammar = parseDSL(grammarDeclaration); | ||
|
||
export const grammar = getAugmentedGrammar(unaugmentedGrammar); | ||
export const itemSets = getItemSets(unaugmentedGrammar); | ||
export const transitionTable = itemSetsToTransitionTable( | ||
itemSets, | ||
unaugmentedGrammar, | ||
); | ||
export const table = getParseTable( | ||
itemSets, | ||
transitionTable, | ||
unaugmentedGrammar, | ||
); |
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,3 +1,3 @@ | ||
export {grammar, itemSets, transitionTable, table} from './parse'; | ||
export {grammar, itemSets, transitionTable, table} from './definition'; | ||
|
||
export {default as parseWithTable, makeNode} from './parseWithTable'; |
This file was deleted.
Oops, something went wrong.
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