https://github.com/gkjohnson/scientific-javascript
A proof of concept project that adds a unit notation to Javascript using Sweet.js
https://github.com/gkjohnson/scientific-javascript
engineering javascript parsing science sugar sweetjs syntax units
Last synced: 2 months ago
JSON representation
A proof of concept project that adds a unit notation to Javascript using Sweet.js
- Host: GitHub
- URL: https://github.com/gkjohnson/scientific-javascript
- Owner: gkjohnson
- Created: 2017-07-30T16:47:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-31T04:07:05.000Z (almost 8 years ago)
- Last Synced: 2025-02-02T01:12:16.610Z (4 months ago)
- Topics: engineering, javascript, parsing, science, sugar, sweetjs, syntax, units
- Language: JavaScript
- Homepage:
- Size: 85 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scientific-javascript
A prototype, proof of concept project that adds syntactic sugar for unit notation to Javascript using Sweet.js. The addition allows for adding units to numbers and automatic unit conversion when performing mathematical operations. Inspired by working with engineers modeling complex systems with manual unit conversion, making it difficult to trace.This is purely a prototype and should not be considered useable in any kind of real work.
## Syntax
### Units
A unit type is denoted by appending `` to the value.### Example
*Gotta love that floating point precision*
## Next Steps
The approach used to process the syntax is particularly hacky and involves a few regex replaces and two Sweet.js compilations in order to get to runnable javascript code. This syntax doesn't seem to be achieveable with the new version of Sweet.js, either.The better way to handle this is to extend a library that generates an AST, such as [Acorn.js](https://github.com/ternjs/acorn) or [ESPrima](http://esprima.org/) and use something like [ESCodeGen](https://github.com/estools/escodegen) write the javascript back out. Alternatively, a new language could be written with [LLVM](https://llvm.org/) to support this in a more robust fashion.
## How to Run
Run `npm install` in the directoryRun `node app.js`
Load `locahost:3000`