diff --git a/scripts/compile-testcases.ts b/scripts/compile-testcases.ts deleted file mode 100644 index 7f02c02..0000000 --- a/scripts/compile-testcases.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { compile } from 'node-elm-compiler'; - -// - Compile examples in `testcases/*` folder as js -// Run whatever transformations we want on them, saving steps as `elm.{transformation}.js` -compile(['Main.elm'], { - output: 'output/elm.js', - cwd: 'testcases/simple', -}); -compile(['Main.elm'], { - output: 'output/elm.opt.js', - cwd: 'testcases/simple', - optimize: true, -}); diff --git a/src/compile-testcases.ts b/src/compile-testcases.ts new file mode 100644 index 0000000..f8e10de --- /dev/null +++ b/src/compile-testcases.ts @@ -0,0 +1,30 @@ +import { compile } from 'node-elm-compiler'; +import Parser from 'tree-sitter'; +import Elm from 'tree-sitter-elm'; +import * as fs from 'fs'; +// Compile examples in `testcases/*` folder as js +// Run whatever transformations we want on them, saving steps as `elm.{transformation}.js` +compile(['Main.elm'], { + output: 'output/elm.js', + cwd: 'testcases/simple', +}); +compile(['Main.elm'], { + output: 'output/elm.opt.js', + cwd: 'testcases/simple', + optimize: true, +}); + +// Parse the elm file using tree sitter +const elmParser = new Parser(); +elmParser.setLanguage(Elm); + +const parseElm = (filename: string) => { + const source = fs.readFileSync(filename, 'utf8'); + console.log(source); + const tree = elmParser.parse(source); + console.log(tree); +}; + +const result = parseElm('./testcases/simple/Main.elm'); + +console.log(result);