-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
841cb71
commit b7a6ce0
Showing
53 changed files
with
2,039 additions
and
48 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Andy K. S. Wong | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,38 @@ | ||
# @mithic/jsonr | ||
|
||
[![mithic](https://img.shields.io/badge/project-mithic-blueviolet.svg?style=flat-square&logo=github)](https://github.com/andykswong/mithic) | ||
[![npm](https://img.shields.io/npm/v/@mithic/jsonr?style=flat-square&logo=npm)](https://www.npmjs.com/package/@mithic/jsonr) | ||
[![docs](https://img.shields.io/badge/docs-typedoc-blue?style=flat-square&logo=typescript&logoColor=white)](http://andykswong.github.io/mithic) | ||
[![license: MIT](https://img.shields.io/badge/License-MIT-red.svg?style=flat-square)](./LICENSE) | ||
[![build](https://img.shields.io/github/actions/workflow/status/andykswong/mithic/build.yaml?style=flat-square)](https://github.com/andykswong/mithic/actions/workflows/build.yaml) | ||
|
||
<br/> | ||
|
||
> mithic JSON intermediate representation for sandboxed scripting | ||
<br/> | ||
|
||
## Install | ||
```shell | ||
npm install --save @mithic/jsonr | ||
``` | ||
|
||
## Basic Usage | ||
To run an expression: | ||
1. Use a `Parser` (`JsonAstParser`) to parse JSON string into AST | ||
1. Use an `Evaluator` (currently `Interpreter` only) to evaluate the AST against an `Env` (`DefaultEnv`) to get a result as JS object | ||
|
||
#### Simplified JavaScript | ||
```js | ||
import { DefaultEnv, Interpreter, JsonAstParser, Stdlib } from '@mithic/jsonr'; | ||
|
||
const env = new DefaultEnv(null, Stdlib); | ||
const parser = new JsonAstParser(); | ||
const evaluator = new Interpreter(); | ||
|
||
const ast = parser.parse('["+",3,5]'); | ||
const result = evaluator.eval(ast, env); // 8 | ||
``` | ||
|
||
## License | ||
This repository and the code inside it is licensed under the MIT License. Read [LICENSE](./LICENSE) for more information. |
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 = require('../../jest.config.cjs'); |
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,47 @@ | ||
{ | ||
"name": "@mithic/jsonr", | ||
"version": "0.3.0", | ||
"description": "JSON intermediate representation for sandboxed scripting", | ||
"type": "module", | ||
"sideEffects": false, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": "./dist/index.js" | ||
}, | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc", | ||
"clean": "rimraf coverage docs dist", | ||
"prebuild": "npm run lint", | ||
"build": "npm run tsc && npm run babel", | ||
"lint": "eslint src --ext .ts", | ||
"babel": "babel src -d dist -x '.ts,.tsx' --root-mode upward", | ||
"tsc": "tsc --project tsconfig.build.json", | ||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", | ||
"test:update": "npm run test -- -u", | ||
"prestart": "npm run build", | ||
"doc": "typedoc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/andykswong/mithic.git" | ||
}, | ||
"keywords": [ | ||
"mithic", | ||
"typescript" | ||
], | ||
"author": "Andy K.S. Wong <andykswong@outlook.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/andykswong/mithic/issues" | ||
}, | ||
"homepage": "https://github.com/andykswong/mithic", | ||
"dependencies": { | ||
"@mithic/commons": "^0.3" | ||
}, | ||
"devDependencies": { | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/jsonr/src/__tests__/__snapshots__/integ.spec.ts.snap
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,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Integration tests async should catch rejected promise from readline 1`] = ` | ||
[ | ||
[ | ||
"you said:", | ||
"<nope, too slow>", | ||
], | ||
] | ||
`; | ||
|
||
exports[`Integration tests async should print the correct results 1`] = ` | ||
[ | ||
[ | ||
"you said:", | ||
"testing", | ||
], | ||
] | ||
`; | ||
|
||
exports[`Integration tests macro should print the correct results 1`] = ` | ||
[ | ||
[ | ||
2, | ||
], | ||
[ | ||
3, | ||
], | ||
[ | ||
[ | ||
"+", | ||
1, | ||
2, | ||
], | ||
], | ||
] | ||
`; |
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 @@ | ||
[ | ||
";", | ||
["async", "echo", ["prompt"], ["try", ["await", ["readline", "prompt", 2000]], ["catch", "e", "'<nope, too slow>"]]], | ||
["let", "input", ["await", ["echo", "'your input: "]]], | ||
["println", "'you said:", "input"], | ||
null | ||
] |
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,9 @@ | ||
[ | ||
";", | ||
["fn", "x", ["n"], ["+", "n", 1]], | ||
["macro", "y", ["a", "op", "b"], ["[]", "op", "a", "b"]], | ||
["println", ["x", 1]], | ||
["println", ["y", 1, "+", 2]], | ||
["println", ["macroexpand", ["y", 1, "+", 2]]], | ||
null | ||
] |
Oops, something went wrong.