-
Notifications
You must be signed in to change notification settings - Fork 0
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
8a0f2d0
commit 74b4db7
Showing
7 changed files
with
357 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Development Setup | ||
|
||
<!-- ## Setup --> | ||
|
||
Clone the repo and run `npm install` to install all the dependencies. | ||
|
||
If you want to use the development version of the library you cloned in a different | ||
project, you can run `npm link` in the root directory of the repo and then run | ||
`npm link rhyme-lang` in your project directory. | ||
|
||
## Setup for Running in the Browser | ||
|
||
If you want to use the development version of the library in the browser, you can use | ||
webpack to build the browser version of the library. | ||
Use the following commands. | ||
|
||
```bash | ||
npm install webpack webpack-cli --save-dev | ||
./node_modules/.bin/webpack | ||
``` | ||
|
||
This will generate a file `umd/rhyme-lang.min.js` that you can include in your HTML file. | ||
|
||
## Code Structure | ||
|
||
The code is broadly structured according to compiler phases. | ||
The following four javascript files provide useful entry points into the codebase: | ||
- `src/rhyme.js`: Contains the main APIs that are exposed to the user. | ||
- `src/parser.js`: Contains the logic for the parser that provides a simple | ||
textual interface for writing Rhyme expressions. | ||
- `src/ir.js`: Contains the logic for creating the Rhyme intermediate representation (IR) from input query ASTs. | ||
- `src/codegen.js`: Contains the logic for generating optimized javascript code from the Rhyme IR. | ||
|
||
|
||
## Running tests | ||
|
||
Typing `npm test` will run all the tests that are in the `test` directory. | ||
|
||
Running tests that involve running generated C++ code will also need Niels Lohmann's | ||
[C++ JSON library](https://github.com/nlohmann/json) installed. This can be done | ||
either system-wide (e.g. using `brew install nlohmann-json`) or by cloning the | ||
git repo in a Rhyme subdirectory called 'thirdparty'. | ||
|
||
If you're using VSCode, you can install [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) extension and run/debug individual tests. | ||
|
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,13 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Examples | ||
|
||
The Rhyme test suite contains many helpful usage examples: | ||
|
||
- [Miscellaneous Tests and Examples](https://github.com/rhyme-lang/rhyme/tree/main/test/semantics) | ||
|
||
- [Advent of Code](https://github.com/rhyme-lang/rhyme/tree/main/test/aoc) | ||
|
||
- [HTML and React demos](https://github.com/rhyme-lang/rhyme/tree/main/demos) |
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,99 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Getting Started | ||
|
||
Rhyme can be used in multiple different ways: as dependency in a node.js project, | ||
directly in the browser, or as a command-line tool. | ||
|
||
|
||
## Using Rhyme in Node Projects | ||
|
||
To get started with the latest release of Rhyme in your node project, | ||
run the following command: | ||
|
||
```bash | ||
npm install rhyme-lang | ||
``` | ||
|
||
You can then import the library (as you would any other node module) and start using it: | ||
|
||
```javascript | ||
const { api } = require('rhyme-lang') | ||
|
||
let data = [ | ||
{ key: "A", value: 10 }, | ||
{ key: "B", value: 20 }, | ||
{ key: "A", value: 30 } | ||
] | ||
|
||
let query = { | ||
total: api.sum("data.*.value"), | ||
"data.*.key": api.sum("data.*.value"), | ||
} | ||
let res = api.compile(query)({ data }) | ||
console.log("Result: " + JSON.stringify(res)) | ||
``` | ||
|
||
Visit [documentation](https://rhyme-lang.github.io/docs/) to get a glimpse of what Rhyme can do. | ||
|
||
|
||
## Using Rhyme in the Browser/Frontend | ||
|
||
The npm package `rhyme-lang` installed using the above commands is intended for use in node.js projects. | ||
However, if you want to use Rhyme in the browser (especially the visualization features), | ||
you can use `unpkg` CDN to get the browser version of the library. | ||
Specifically, you can include the script from the following URL in your HTML file: | ||
``` | ||
https://unpkg.com/rhyme-lang/umd/rhyme-lang.min.js | ||
``` | ||
|
||
|
||
Shown below is a simple complete example HTML file: | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Rhyme Example</title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<h1>Rhyme Example</h1> | ||
<div id="root"></div> | ||
|
||
<script src="https://unpkg.com/rhyme-lang/umd/rhyme-lang.min.js"></script> | ||
|
||
<script> | ||
let api = rhyme.api | ||
let domParent = document.getElementById("root") | ||
let data = [{x:20,y:70},{x:40,y:30},{x:60,y:50},{x:80,y:60},{x:100,y:40}] | ||
let query = { | ||
"$display": "select", | ||
data: data | ||
} | ||
let res = api.query(query) | ||
api.display(res({}), domParent) | ||
</script> | ||
</body> | ||
</html> | ||
``` | ||
|
||
## Using Rhyme as a Command-Line Tool | ||
|
||
You can also use Rhyme as a command-line tool to process JSON files. For this, install rhyme globally: | ||
|
||
```bash | ||
npm install -g rhyme-lang | ||
``` | ||
|
||
Then you can use it as follows: | ||
|
||
```bash | ||
echo '[1,2,3,4]' | rhyme 'sum stdin.*' | ||
10 | ||
``` | ||
|
||
When given an argument ending in `.rh`, as in `rhyme query.rh`, Rhyme will treat it as a file name to load the query from. | ||
|
||
|
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.