-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from s-kybound/main
Upgrade Scm-slang parser
- Loading branch information
Showing
63 changed files
with
11,616 additions
and
2,737 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
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,8 @@ | ||
env: | ||
browser: true | ||
es2021: true | ||
extends: standard-with-typescript | ||
parserOptions: | ||
ecmaVersion: latest | ||
sourceType: module | ||
rules: {} |
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 @@ | ||
module.exports = { presets: ["@babel/preset-env"] }; |
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,7 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
transform: { | ||
"^.+\\.(ts|tsx)?$": "ts-jest", | ||
"^.+\\.(js|jsx)$": "babel-jest", | ||
}, | ||
}; |
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,40 +1,58 @@ | ||
{ | ||
"name": "scm-slang", | ||
"version": "0.5.0", | ||
"license": "Apache-2.0", | ||
"description": "Scheme-based implementations of Source, written in Typescript", | ||
"keywords": [ | ||
"Scheme", | ||
"interpreter", | ||
"compiler", | ||
"Source", | ||
"SICP" | ||
], | ||
"author": { | ||
"name": "Source Academy", | ||
"url": "https://github.com/source-academy/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/source-academy/scm-slang.git" | ||
}, | ||
"main": "index.js", | ||
"bugs": { | ||
"url": "https://github.com/source-academy/scm-slang/issues" | ||
}, | ||
"homepage": "https://github.com/source-academy/scm-slang#readme", | ||
"private": true, | ||
"dependencies": { | ||
"@types/estree": "^1.0.0", | ||
"acorn": "^8.8.2", | ||
"acorn-walk": "^8.2.0", | ||
"js-base64": "^3.7.5" | ||
}, | ||
"scripts": {}, | ||
"meta": {}, | ||
"devDependencies": { | ||
"@types/node": "^18.14.2", | ||
"astring": "^1.8.4", | ||
"source-map": "^0.7.4" | ||
} | ||
"name": "scm-slang", | ||
"version": "1.0.3", | ||
"license": "Apache-2.0", | ||
"description": "Scheme-based implementations of Source, written in Typescript", | ||
"keywords": [ | ||
"Scheme", | ||
"interpreter", | ||
"compiler", | ||
"Source", | ||
"SICP" | ||
], | ||
"author": { | ||
"name": "Source Academy", | ||
"url": "https://github.com/source-academy/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/source-academy/scm-slang.git" | ||
}, | ||
"main": "index.js", | ||
"bugs": { | ||
"url": "https://github.com/source-academy/scm-slang/issues" | ||
}, | ||
"homepage": "https://github.com/source-academy/scm-slang#readme", | ||
"private": true, | ||
"dependencies": { | ||
"@types/estree": "^1.0.0", | ||
"acorn": "^8.8.2", | ||
"acorn-walk": "^8.2.0", | ||
"js-base64": "^3.7.5" | ||
}, | ||
"scripts": { | ||
"build-libs": "npx ts-node ./src/compile-libs.ts", | ||
"test": "jest", | ||
"lint": "eslint --ignore-path .eslintignore --ext .ts", | ||
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"" | ||
}, | ||
"meta": {}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.23.9", | ||
"@types/jest": "^29.5.11", | ||
"@types/node": "^18.14.2", | ||
"@typescript-eslint/eslint-plugin": "^6.4.0", | ||
"babel-jest": "^29.7.0", | ||
"escodegen": "^2.1.0", | ||
"eslint": "^8.0.1", | ||
"eslint-config-standard-with-typescript": "^43.0.1", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.2.4", | ||
"source-map": "^0.7.4", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "*" | ||
} | ||
} |
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,45 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import { schemeParse } from "./transpiler"; | ||
import { estreeEncode } from "./utils/encoder-visitor"; | ||
const escodegen = require("escodegen"); | ||
|
||
function transpile(inputFilePath: string, outputFilePath: string) { | ||
fs.readFile(inputFilePath, "utf8", (err, data) => { | ||
if (err) { | ||
console.error(`Error reading file: ${err}`); | ||
return; | ||
} | ||
|
||
// we transpile the file | ||
const transpiledAST = schemeParse(data); | ||
const encodedAST = estreeEncode(transpiledAST); | ||
const transpiledProgram = escodegen.generate(encodedAST); | ||
|
||
fs.writeFile(outputFilePath, transpiledProgram, (err) => { | ||
if (err) { | ||
console.error(`Error writing file: ${err}`); | ||
return; | ||
} | ||
console.log(`${inputFilePath} has been transpiled to ${outputFilePath}`); | ||
}); | ||
}); | ||
} | ||
|
||
// get file paths from command line arguments | ||
const inputFilePath: string = process.argv[2]; | ||
const outputFilePath: string = process.argv[3] | ||
? process.argv[3] | ||
: inputFilePath.replace(".scm", ".js"); | ||
|
||
// validate file paths | ||
if (!inputFilePath) { | ||
console.error("Please provide an input file path and an output file path"); | ||
} | ||
|
||
if (!(path.extname(inputFilePath) === ".scm")) { | ||
console.error("Please provide a .scm file for compilation!"); | ||
} | ||
|
||
// if everything is fine, we transpile the file | ||
transpile(inputFilePath, outputFilePath); |
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.