-
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.
Rewrite grammar to follow Surrealist Lezer grammar (#1)
- Loading branch information
Showing
26 changed files
with
101,823 additions
and
5,149 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 |
---|---|---|
|
@@ -7,4 +7,3 @@ end_of_line = lf | |
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
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,58 @@ | ||
name: Bug Report | ||
description: File a bug or issue | ||
title: "bug: " | ||
labels: [bug] | ||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
**Before** reporting an issue, make sure to search [existing issues](https://github.com/tree-sitter/tree-sitter-surrealql/issues). Usage questions such as ***"How do I...?"*** either belong in [Discussions](https://github.com/tree-sitter/tree-sitter/discussions) upstream or in our [Discord server](https://discord.gg/w7nTvsVJhm) and will be closed. | ||
If your issue is related to a bug in your editor-experience because your editor *leverages* tree-sitter and this parser, then it is likely your issue does *NOT* belong here and belongs in the relevant editor's repository. | ||
- type: checkboxes | ||
attributes: | ||
label: Did you check existing issues? | ||
description: Make sure you've checked all of the below before submitting an issue | ||
options: | ||
- label: I have read all the [tree-sitter docs](https://tree-sitter.github.io/tree-sitter/using-parsers) if it relates to using the parser | ||
required: false | ||
- label: I have searched the existing issues of tree-sitter-surrealql | ||
required: true | ||
- type: input | ||
attributes: | ||
label: "Tree-Sitter CLI Version, if relevant (output of `tree-sitter --version`)" | ||
placeholder: "tree-sitter 0.20.8 (6bbb50bef8249e6460e7d69e42cc8146622fa4fd)" | ||
validations: | ||
required: false | ||
- type: textarea | ||
attributes: | ||
label: Describe the bug | ||
description: A clear and concise description of what the bug is. Please include any related errors you see such as parsing errors or tree-sitter cli errors. | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Steps To Reproduce/Bad Parse Tree | ||
description: Steps to reproduce the behavior. If you have a bad parse tree, please include it here. You can get this by running `tree-sitter parse <path-to-file>` and copying the output. | ||
placeholder: | | ||
1. | ||
2. | ||
3. | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Expected Behavior/Parse Tree | ||
description: A concise description of what you expected to happen, or in the case of a bad parse tree, the expected parse tree. | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Repro | ||
description: Minimal code to reproduce this issue. Ideally this should be reproducible with the C library or the tree-sitter cli, do not suggest an editor or external tool. | ||
value: | | ||
# Example code that causes the issue | ||
SELECT * FROM person; | ||
... | ||
render: sql | ||
validations: | ||
required: false |
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 @@ | ||
blank_issues_enabled: false |
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,36 @@ | ||
name: Feature Request | ||
description: Suggest a new feature | ||
title: "feature: " | ||
labels: [enhancement] | ||
body: | ||
- type: checkboxes | ||
attributes: | ||
label: Did you check the tree-sitter docs? | ||
description: Make sure you read all the docs before submitting a feature request | ||
options: | ||
- label: I have read all the [tree-sitter docs](https://tree-sitter.github.io/tree-sitter/using-parsers) if it relates to using the parser | ||
required: false | ||
- type: textarea | ||
validations: | ||
required: true | ||
attributes: | ||
label: Is your feature request related to a problem? Please describe. | ||
description: A clear and concise description of what the problem is. Ex. I think the grammar models this rule incorrectly and can be improved, or the scanner can be improved by doing [...], or SurrealDB has officially added a new feature that should be added to the grammar. | ||
- type: textarea | ||
validations: | ||
required: true | ||
attributes: | ||
label: Describe the solution you'd like | ||
description: A clear and concise description of what you want to happen. | ||
- type: textarea | ||
validations: | ||
required: true | ||
attributes: | ||
label: Describe alternatives you've considered | ||
description: A clear and concise description of any alternative solutions or features you've considered. | ||
- type: textarea | ||
validations: | ||
required: false | ||
attributes: | ||
label: Additional context | ||
description: Add any other context or screenshots about the feature request here. If your feature request is related to a new SurrealDB feature, please include a link to the relevant **official** SurrealDB documentation. |
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,64 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: ["*"] | ||
paths: | ||
- grammar.js | ||
- src/** | ||
- test/** | ||
- bindings/** | ||
- binding.gyp | ||
pull_request: | ||
paths: | ||
- grammar.js | ||
- src/** | ||
- test/** | ||
- bindings/** | ||
- binding.gyp | ||
|
||
concurrency: | ||
group: ${{github.workflow}}-${{github.ref}} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
name: Test parser | ||
runs-on: ${{matrix.os}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-14] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up the repo | ||
uses: tree-sitter/setup-action/cli@v1 | ||
- name: Run tests | ||
uses: tree-sitter/parser-test-action@v2 | ||
with: | ||
test-rust: ${{runner.os == 'Linux'}} | ||
- name: Parse examples | ||
uses: tree-sitter/parse-action@v4 | ||
with: | ||
files: | | ||
examples/**/*.py | ||
fuzz: | ||
name: Fuzz parser | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
- name: Check for scanner changes | ||
id: scanner-changes | ||
run: |- | ||
if git diff --quiet HEAD^ -- src/scanner.c; then | ||
printf 'changed=false\n' >> "$GITHUB_OUTPUT" | ||
else | ||
printf 'changed=true\n' >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Fuzz parser | ||
uses: tree-sitter/fuzz-action@v4 | ||
if: steps.scanner-changes.outputs.changed == 'true' |
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,23 @@ | ||
name: Publish package | ||
|
||
on: | ||
push: | ||
tags: ["*"] | ||
|
||
concurrency: | ||
group: ${{github.workflow}}-${{github.ref}} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
npm: | ||
uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main | ||
secrets: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
crates: | ||
uses: tree-sitter/workflows/.github/workflows/package-crates.yml@main | ||
secrets: | ||
CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}} | ||
pypi: | ||
uses: tree-sitter/workflows/.github/workflows/package-pypi.yml@main | ||
secrets: | ||
PYPI_API_TOKEN: ${{secrets.PYPI_API_TOKEN}} |
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 |
---|---|---|
|
@@ -15,4 +15,3 @@ test | |
.gitattributes | ||
.gitmodules | ||
.npmignore | ||
|
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ README.md | |
bindings/ | ||
target/ | ||
src/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
# tree-sitter-surrealql | ||
|
||
SurrealQL grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). | ||
[![CI][ci]](https://github.com/ce11an/tree-sitter-surrealql/actions/workflows/ci.yml) | ||
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org) | ||
[![crates][crates]](https://crates.io/crates/tree-sitter-surrealql) | ||
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-surrealql) | ||
[![pypi][pypi]](https://pypi.org/project/tree-sitter-surrealql/) | ||
|
||
SurrealQL grammar for [tree-sitter][]. | ||
|
||
## Installation | ||
|
||
### [cargo](https://crates.io/crates/tree-sitter-surrealql) | ||
|
||
```sh | ||
cargo add tree-sitter-surrealql | ||
``` | ||
|
||
### [npm](https://www.npmjs.com/package/ce11an/tree-sitter-surrealql) | ||
|
||
```bash | ||
npm i @ce11an/tree-sitter-surrealql | ||
``` | ||
|
||
### Using [pip](https://pypi.org/project/tree-sitter-surrealql) | ||
|
||
```bash | ||
pip install tree-sitter-surrealql | ||
``` | ||
|
||
## Features | ||
Please check the [examples](examples) directory for a complete list of features. | ||
|
||
## References | ||
- [SurrealDB](https://surrealdb.com/docs/surrealdb) | ||
|
||
[ci]: https://img.shields.io/github/actions/workflow/status/ce11an/tree-sitter-surrealql/ci.yml?logo=github&label=CI | ||
[tree-sitter]: https://github.com/tree-sitter/tree-sitter | ||
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord | ||
[npm]: https://img.shields.io/npm/v/tree-sitter-surrealql?logo=npm | ||
[crates]: https://img.shields.io/crates/v/tree-sitter-surrealql?logo=rust | ||
[pypi]: https://img.shields.io/pypi/v/tree-sitter-surrealql?logo=pypi&logoColor=ffd242 |
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,22 @@ | ||
-- Start a new database transaction. Transactions are a way to ensure multiple operations | ||
-- either all succeed or all fail, maintaining data integrity. | ||
BEGIN TRANSACTION; | ||
|
||
-- Create a new account with the ID 'one' and set its initial balance to 135605.16 | ||
CREATE account:one SET balance = 135605.16; | ||
|
||
-- Create another new account with the ID 'two' and set its initial balance to 91031.31 | ||
CREATE account:two SET balance = 91031.31; | ||
|
||
-- Update the balance of account 'one' by adding 300.00 to the current balance. | ||
-- This could represent a deposit or other form of credit on the balance property. | ||
UPDATE account:one SET balance += 300.00; | ||
|
||
-- Update the balance of account 'two' by subtracting 300.00 from the current balance. | ||
-- This could represent a withdrawal or other form of debit on the balance property. | ||
UPDATE account:two SET balance -= 300.00; | ||
|
||
-- Finalize the transaction. This will apply the changes to the database. If there was an error | ||
-- during any of the previous steps within the transaction, all changes would be rolled back and | ||
-- the database would remain in its initial state. | ||
COMMIT TRANSACTION; |
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,53 @@ | ||
--TODO: Fix `LET` statement | ||
--TODO: Fix `CONTINUE` keyword | ||
--TODO: Fix `BREAK` keyword | ||
LET $numbers = [1,2,3,4,5,6,7,8,9]; | ||
|
||
FOR $num IN $numbers { | ||
IF $num > 5 { | ||
BREAK; | ||
} ELSE IF $num < 5 { | ||
CREATE type::thing( | ||
'person', $num | ||
) CONTENT { | ||
name: "Person number " + <string>$num | ||
}; | ||
}; | ||
}; | ||
|
||
-- Data retrieved from somewhere which contains many NONE values | ||
LET $weather = [ | ||
{ | ||
city: 'London', | ||
temperature: 22.2, | ||
timestamp: 1722565566389 | ||
}, | ||
NONE, | ||
{ | ||
city: 'London', | ||
temperature: 20.1, | ||
timestamp: 1722652002699 | ||
}, | ||
{ | ||
city: 'Phoenix', | ||
temperature: 45.1, | ||
timestamp: 1722565642160 | ||
}, | ||
NONE, | ||
NONE, | ||
{ | ||
city: 'Phoenix', | ||
temperature: 45.1, | ||
timestamp: 1722652070372 | ||
}, | ||
]; | ||
|
||
-- Sort the data to move the NONE values to the end | ||
-- and break once the first NONE is reached | ||
FOR $data IN array::sort::desc($weather) { | ||
IF $data IS NONE { | ||
BREAK; | ||
} ELSE { | ||
CREATE weather CONTENT $data; | ||
}; | ||
}; |
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,12 @@ | ||
BEGIN TRANSACTION; | ||
|
||
-- Setup accounts | ||
CREATE account:one SET balance = 135605.16; | ||
CREATE account:two SET balance = 91031.31; | ||
|
||
-- Move money | ||
UPDATE account:one SET balance += 300.00; | ||
UPDATE account:two SET balance -= 300.00; | ||
|
||
-- Finalise all changes | ||
COMMIT TRANSACTION; |
Oops, something went wrong.