Skip to content

Commit

Permalink
pass over docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TiarkRompf committed Dec 28, 2024
1 parent 8a0f2d0 commit 74b4db7
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 115 deletions.
18 changes: 14 additions & 4 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ export default defineConfig({
text: 'Introduction',
items: [
{ text: 'Overview', link: '/overview' },
],
{ text: 'Getting Started', link: '/getting-started' },
{ text: 'Development Setup', link: '/development' },
]
}, {
text: 'Documentation',
items: [
{ text: 'Reference', link: '/reference' },
{ text: 'Examples', link: '/examples' },
]
},/*{
text: 'Examples',
items: [
{ text: 'Markdown Examples', link: '/markdown-examples' },
{ text: 'Runtime API Examples', link: '/api-examples' }
{ text: 'Markdown Examples', link: '/xx-markdown-examples' },
{ text: 'Runtime API Examples', link: '/xx-api-examples' }
]
}
}*/
],

socialLinks: [
{ icon: 'npm', link: 'https://www.npmjs.com/package/rhyme-lang' },
{ icon: 'github', link: 'https://github.com/rhyme-lang' }
]
}
Expand Down
49 changes: 49 additions & 0 deletions docs/development.md
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.

13 changes: 13 additions & 0 deletions docs/examples.md
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)
99 changes: 99 additions & 0 deletions docs/getting-started.md
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.


22 changes: 11 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout: home
hero:
name: "Rhyme"
text: "An Expressive \nData-Centric \nQuery Language"
tagline: My great project tagline
tagline: Query nested data, produce nested data as result
image:
src: "https://avatars.githubusercontent.com/u/150201258?s=400&u=c165a8a5fc98d1ddc149652fcdb818e4222f3094&v=4"
alt: Rhyme
Expand All @@ -14,18 +14,18 @@ hero:
text: Overview
link: /overview
- theme: alt
text: Markdown Examples
link: /markdown-examples
text: Getting Started
link: /getting-started
- theme: alt
text: API Examples
link: /api-examples
text: Examples
link: /examples

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Tree-to-Tree Queries
details: Process nested structures (JSON, Tensors) as input, produce nested structures as result.
- title: Easy to Metaprogram
details: Compose query fragments in JS, following the structure of the input or output.
- title: Compile to JS (or C)
details: Queries are optimized and translated to low-level code for maximum performance.
---

Loading

0 comments on commit 74b4db7

Please sign in to comment.