From 9f1633e15e0347046d0023d75fba82b7dd74f94d Mon Sep 17 00:00:00 2001 From: mdgriffith Date: Sat, 25 Jul 2020 11:20:59 -0400 Subject: [PATCH] move compile-testcases to src folder --- scripts/compile-testcases.ts | 13 ------------- src/compile-testcases.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) delete mode 100644 scripts/compile-testcases.ts create mode 100644 src/compile-testcases.ts 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);