Skip to content

Update to Pug Customized Grammar #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 124 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
cf308e6
add query match
PKuebler Oct 4, 2022
f7d6aea
Merge branch 'smacker:master' into master
PKuebler Oct 24, 2022
73be3c8
add query validator tests
PKuebler Oct 24, 2022
b5f1aa0
add eq and match tests
PKuebler Oct 24, 2022
1c6a3ce
feat: add kotlin grammar
williamfzc Jan 12, 2023
af7e2ef
Merge pull request #91 from williamfzc/master
smacker Jan 13, 2023
9569cee
Update Java grammar to v0.20.1
ahumenberger Feb 20, 2023
cdf18a5
Merge pull request #94 from symflower/update-java
smacker Feb 21, 2023
53b1156
Merge pull request #83 from PKuebler/master
smacker Feb 23, 2023
6d85ade
Move predicate tests to a separate file
smacker Feb 23, 2023
4d4cba2
Update README adding section about predicates
smacker Feb 23, 2023
f12d939
Add custom grammars section to README
smacker Feb 26, 2023
c459dbd
Fix typo
smacker Feb 26, 2023
a7b074a
New script to manage grammars
smacker Mar 25, 2023
112ac78
Improve columns formatting in the automation output
smacker Mar 28, 2023
50aa312
Correct cue grammar version
smacker Mar 28, 2023
0203fdb
Merge pull request #99 from smacker/new-grammars-automation
smacker Mar 28, 2023
6f682c3
Add missing import
smacker Mar 28, 2023
4dc5595
Update elm grammar to v5.6.3
smacker Mar 28, 2023
d17a3e0
Update ocaml to v0.20.1
smacker Mar 28, 2023
f309fb0
Update rust to v0.20.3
smacker Mar 28, 2023
3db5c7c
Update elixir grammar to v0.1.0
smacker Mar 28, 2023
d6bf149
Update golang grammar
smacker Mar 28, 2023
3f79800
Update scala grammar to v0.19.1
smacker Mar 28, 2023
f68d0c8
Update svelte grammar to v0.10.1
smacker Mar 28, 2023
46c0df0
Update lua grammar
smacker Mar 28, 2023
b02ac7b
Update typescipt grammar to v2.20.2
smacker Mar 28, 2023
df7fd2e
fix doc for updating specific grammar
broofa Apr 14, 2023
af16b10
Merge pull request #100 from broofa/patch-1
smacker Apr 15, 2023
9e6836f
Improve handling of query errors
wesen Apr 23, 2023
3eeb0b6
Fix predicate handling to match tree-sitter cli
wesen Apr 23, 2023
a896a22
Bump because of version nonsense
wesen Apr 23, 2023
a7d9277
Merge pull request #102 from wesen/misc/improve-query-handling
smacker May 1, 2023
fba87dc
Implemented multi-predicate support #103
sam-ulrich1 May 28, 2023
46e4b04
Added attribution to klothoplatform & Removed .idea file
sam-ulrich1 Jul 19, 2023
0d0a9f7
Merge pull request #109 from Gage-Technologies/multi-predicate
smacker Jul 20, 2023
ec190c4
Add info about external gotemplate grammar
qvalentin Jul 31, 2023
6d5d8b1
use MichaHoffmann/tree-sitter-hcl instead
jamesnicolas Oct 6, 2023
ab54e6e
fix: fetch grammars from non-reference commits
jbedard Nov 30, 2023
533c67d
update typescript grammar to v0.20.3
jbedard Nov 30, 2023
ca67695
update javascript grammar to v0.20.1
jbedard Nov 30, 2023
0eec0d7
Merge pull request #134 from jbedard/lang-typescript
smacker Dec 15, 2023
4c62eac
Merge pull request #135 from jbedard/lang-javascript
smacker Dec 15, 2023
e703811
Merge pull request #133 from jbedard/fix-update-refs
smacker Dec 15, 2023
902ba97
Merge pull request #127 from jamesnicolas/master
smacker Dec 15, 2023
06670b6
Merge pull request #104 from qvalentin/master
smacker Dec 15, 2023
cd3cb7e
Added treesitter_updater automation to update this project to using t…
micksmix Dec 17, 2023
55cfc70
Bumped treesitter to v0.20.8.
micksmix Dec 17, 2023
233c2f9
Merge pull request #138 from micksmix/master
smacker Dec 19, 2023
93f60d7
Update java grammar
yuraaka Jan 26, 2024
3d302b2
Merge pull request #141 from YuraAka/master
smacker Jan 29, 2024
ea12938
tree sitter update to 0.20.9
yuraaka Jan 30, 2024
5175f84
Merge pull request #142 from YuraAka/master
smacker Jan 31, 2024
8ec5d6b
fix: deprecation warning from README
tobb10001 Feb 7, 2024
0bc1991
Bumped kotlin to latest version
micksmix Feb 8, 2024
ad63693
Merge pull request #144 from tobb10001/readme-deprecation-warning
smacker Feb 8, 2024
afc7582
updated _automation/main.go script to prefer commits tied to a latest…
mickgmdb Feb 8, 2024
f20b58d
updated README
mickgmdb Feb 8, 2024
fd22af3
updated README
mickgmdb Feb 8, 2024
9f249fd
added logic to support adding Swift grammar. Also added latest versio…
micksmix Feb 9, 2024
2dff9fb
ci: update used github actions and go version matrix
jochil Feb 13, 2024
746cc92
Merge pull request #147 from jochil/pipeline-update
smacker Feb 14, 2024
2315621
feat: add Groovy support
jochil Feb 13, 2024
1f283e2
Merge pull request #146 from jochil/groovy-support
smacker Feb 14, 2024
9a27c1f
Updated updater based on PR feedback.
mickgmdb Feb 18, 2024
bc1387f
Updated updater based on PR feedback.
mickgmdb Feb 18, 2024
557e5a4
Updated updater based on PR feedback.
mickgmdb Feb 18, 2024
3637960
changes made in response to PR comments
micksmix Mar 19, 2024
b934799
updated Swift and Kotlin to latest
micksmix Mar 19, 2024
a4b649a
Merge pull request #145 from micksmix/master
smacker Mar 20, 2024
9537ed5
javascript: update grammar to latest version
glkz Apr 1, 2024
99ab967
Merge pull request #154 from poolsideai/update-javascript
smacker Apr 2, 2024
c890dce
updated tree-sitter to v0.21.0
micksmix Apr 20, 2024
169cf1e
updated tree-sitter to v0.22.5
micksmix Apr 20, 2024
31bae7b
Merge pull request #156 from micksmix/master
smacker Apr 22, 2024
0628b34
updated bash grammar to v0.21.0
micksmix Apr 22, 2024
8516e80
updated python grammar to v0.21.0
micksmix Apr 22, 2024
f07c98b
updated C grammar
micksmix Apr 22, 2024
43c365f
updated C++ grammar to v0.22.0
micksmix Apr 22, 2024
ca694a2
updated CSS grammar to v0.20.0
micksmix Apr 22, 2024
db8d98e
updated cue grammar
micksmix Apr 22, 2024
30c014c
updated Elixir grammar to v0.2.0
micksmix Apr 22, 2024
9307606
updated Elm grammar to v5.7.0
micksmix Apr 22, 2024
5ba7776
updated Golang grammar
micksmix Apr 22, 2024
07a0a46
updated HCL grammar
micksmix Apr 22, 2024
3e85dc0
updated HTML grammar to v0.20.2
micksmix Apr 22, 2024
c4ba412
updated Java grammar to v0.21.0
micksmix Apr 22, 2024
3a18b15
updated JavaScript grammar to v0.21.0
micksmix Apr 22, 2024
0cf7cbe
updated Lua grammar
micksmix Apr 22, 2024
81461aa
updated Ruby grammar to v0.20.1
micksmix Apr 22, 2024
cc89539
updated Ruby grammar to v0.20.1
micksmix Apr 22, 2024
8c36985
updated Rust grammar to v0.21.0
micksmix Apr 22, 2024
2c2d348
updated Scala grammar to v0.21.0
micksmix Apr 22, 2024
a6bccaa
updated Svelte grammar to v0.11.0
micksmix Apr 22, 2024
ca3426d
updated Typescript grammar to v0.20.6
micksmix Apr 22, 2024
9422537
updated Typescript grammar to v0.20.6
micksmix Apr 22, 2024
8ba0365
Merge pull request #158 from micksmix/master
smacker Apr 23, 2024
679e829
update php to 0.22.4
ahmedash95 May 9, 2024
04d6b33
Merge pull request #160 from ahmedash95/update-php
smacker May 10, 2024
d0cddf6
updated C# parser to 0.21.2
codeFather2 May 13, 2024
14902bd
updated csharp with automation script to 0.21.2
codeFather2 May 14, 2024
c5d1f3f
Merge pull request #161 from codeFather2/csharp-0.21.2-update
smacker May 14, 2024
bfabf0b
feat: add markdown support
wasd96040501 Jun 14, 2024
0ac8d7d
Merge pull request #163 from wasd96040501/feat/markdown
smacker Jun 14, 2024
79334e4
add sql support
vladlyt May 17, 2024
a31a98a
Merge pull request #162 from vladlyt/master
smacker Jun 25, 2024
e00ecde
updated grammars
asalvi0 Aug 25, 2024
aa14595
fixed `Ocaml` files mapping
asalvi0 Aug 25, 2024
0add1af
updated Go to `1.23` and indirect deps
asalvi0 Aug 25, 2024
64d0717
improved `UpdateAll` logic
asalvi0 Aug 25, 2024
7ed0b5f
reverted `Ocaml` file mappings, this change is in another PR
asalvi0 Aug 25, 2024
4978e36
updated Go to `1.20`
asalvi0 Aug 26, 2024
2fa7913
fixed `typescript` & `ocaml` file mapping
asalvi0 Aug 26, 2024
0de3e3a
updated grammar files
asalvi0 Aug 26, 2024
a46cd22
updated kotlin test
asalvi0 Aug 26, 2024
6362d4c
minor cleanup to `downloadOcaml`
asalvi0 Aug 26, 2024
4a0dd13
added custom file mapping for `dockerfile`
asalvi0 Aug 26, 2024
d6e0408
updated grammars file
asalvi0 Aug 26, 2024
a85ceeb
Merge pull request #170 from asalvi0/update-grammars
smacker Aug 27, 2024
30107c6
updated go versions in test job
asalvi0 Aug 27, 2024
dd81d9e
Merge pull request #172 from asalvi0/improve-updater
smacker Aug 27, 2024
d07e774
Save readme updates
quezo Nov 15, 2024
22e4d80
save updates
quezo Nov 15, 2024
1b61a4b
Merge branch 'master' of https://github.com/smacker/go-tree-sitter in…
quezo Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ on:
jobs:
test:
runs-on: ubuntu-latest
name: go-tree-sitter
strategy:
matrix:
go: ["1.23", "1.22", "1.21", "1.20"]
name: Test on ${{ matrix.go }}
steps:
- name: Check out source code
uses: actions/[email protected]
- uses: actions/setup-go@v3.3.1
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Download dependencies
Expand Down
58 changes: 57 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
vendor
.idea

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos
93 changes: 89 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,98 @@

Golang bindings for [tree-sitter](https://github.com/tree-sitter/tree-sitter)

## How to Update Pug Grammar

### 1. Update Automation Grammars Configuration File
Update the grammar to the `codepen/go-tree-sitter/_automation/grammars.json` file. The format is:

```json
{
"language": "pug",
"url": "https://github.com/codepen/tree-sitter-pug",
"files": ["parser.c", "scanner.cc"],
"reference": "master",
"revision": "757e95a5fbf26058e38f9beb1fd2f05c140410a7"
},
```

### 2. Run Script to Update Grammar

This will pull the latest generated C parser files from the GitHub repo.

```bash
go run _automation/main.go update pug -force
```

### 3. Add Go Binding

Manually add a file called `binding.go` to the `codepen/go-tree-sitter/pug` directory. This file should contain the following code, specific to your grammar:

```go
package pug

//#include "parser.h"
//TSLanguage *tree_sitter_pug();
import "C"

import (
"unsafe"

sitter "github.com/codepen/go-tree-sitter"
)

func GetLanguage() *sitter.Language {
ptr := unsafe.Pointer(C.tree_sitter_pug())
return sitter.NewLanguage(ptr)
}
```

This logic adds a `GetLanguage` method that allows you to call the underlying C code from Go.

Be sure to set the correct language name in two places in this file:
Line 4: `//TSLanguage *tree_sitter_<language>();`
Line 14: `ptr := unsafe.Pointer(C.tree_sitter_<language>())`

### 4. Add Binding Test
Test the syntax tree your newly added parser generates by creating a test file in the `codepen/go-tree-sitter/<language>` directory. This file should contain the following code, specific to your grammar:

```go
package pug_test

import (
"context"
"testing"

sitter "github.com/codepen/go-tree-sitter"
"github.com/codepen/go-tree-sitter/pug"
"github.com/stretchr/testify/assert"
)

func TestGrammar(t *testing.T) {
assert := assert.New(t)

n, err := sitter.ParseCtx(context.Background(), []byte(`extends layout.pug`), pug.GetLanguage())
assert.NoError(err)
assert.Equal("(source_file (extends_statement (path)))", n.String())
}
```

Run the test from the root of the repo with the following command:
```bash
go test -v pug/binding_test.go
```

## Usage

Create a parser with a grammar:

```go
import (
sitter "github.com/codepen/go-tree-sitter"
"github.com/codepen/go-tree-sitter/javascript"
"context"
"fmt"

sitter "github.com/smacker/go-tree-sitter"
"github.com/smacker/go-tree-sitter/javascript"
)

parser := sitter.NewParser()
Expand All @@ -23,7 +107,7 @@ Parse some code:

```go
sourceCode := []byte("let a = 1")
tree := parser.Parse(nil, sourceCode)
tree, _ := parser.ParseCtx(context.Background(), nil, sourceCode)
```

Inspect the syntax tree:
Expand Down Expand Up @@ -51,6 +135,7 @@ Known external grammars:

- [Salesforce grammars](https://github.com/aheber/tree-sitter-sfapex) - including Apex, SOQL, and SOSL languages.
- [Ruby](https://github.com/shagabutdinov/go-tree-sitter-ruby) - Deprecated, grammar is provided by main repo instead
- [Go Template](https://github.com/mrjosh/helm-ls/tree/master/internal/tree-sitter/gotemplate) - Used for helm

### Editing

Expand Down Expand Up @@ -149,7 +234,7 @@ Update vendor files:

- open `_automation/grammars.json`
- modify `reference` (for tagged grammars) or `revision` (for grammars from a branch)
- run `c <grammar-name>`
- run `go run _automation/main.go update <grammar-name>`

It is also possible to update all grammars in one go using

Expand Down
62 changes: 62 additions & 0 deletions _automation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Grammar Version Checker

This Go program automates the process of checking and updating grammar versions for various programming languages. It targets specific grammars defined in a JSON configuration file and supports operations like checking for updates and performing updates.

## Features

- **Check for Updates**: Scan through defined grammars and check if there are new versions available.
- **Update Grammar**: Update a specific grammar to its latest version.
- **Update All**: Batch update all grammars to their latest versions.

## Prerequisites

- Go installed on your machine.
- Git installed and accessible from your command line.

## Configuration

The program relies on a JSON file (`_automation/grammars.json`) for the list of grammars to manage. Each grammar should specify its `language`, `url`, `files`, `reference` (tag or branch), and `revision` (commit hash).

Example structure of `grammars.json`:

```json
[
{
"language": "golang",
"url": "https://github.com/tree-sitter/tree-sitter-go",
"files": [
"parser.c"
],
"reference": "master",
"revision": "64457ea6b73ef5422ed1687178d4545c3e91334a",
"updatedBasedOn": "commit", //OPTIONAL: Use "tag" (instead of "commit") to restrict updates to the latest tag and not latest commit
}
]
```

`updatedBasedOn` is an OPTIONAL property. If not provided, updating from the latest commit will be presumed.

## Usage

### To Check for Updates

```bash
go run ./_automation/main.go check-updates
```

### To update a specific grammar
```bash
go run ./_automation/main.go update <language> [--force]
```

### To update all grammars
```bash
go run ./_automation/main.go update-all
```

## Test After Updating
Once you've updated a grammar, it is important to test that the binding tests still pass (`binding_test.go`). Then run:

```bash
go test -v ./...
```
Loading