Skip to content

Commit 9182a99

Browse files
feat: add support for editions (#1)
* grammar: add support for edition * feat: add support for editions In addition to adding support for edition keyword, this also adds support for the new grammer rules introduced such as skipping `"` (quotation) marks around reserved field names. * fix: lint and do not test on swift * bump: to 0.2.0
1 parent ac08241 commit 9182a99

17 files changed

+4063
-3753
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: tree-sitter/parser-test-action@v2
3939
with:
4040
test-rust: true
41-
test-node: false
4241
test-python: true
4342
test-go: true
44-
test-swift: true
43+
test-swift: false
44+
test-node: false

.github/workflows/fuzz.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tree-sitter-proto"
33
description = "Parser for proto2 and proto3 files"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
authors = ["Mohammad Ashar Khan <[email protected]>"]
66
license = "MIT"
77
readme = "README.md"

Makefile

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
[![CI][ci]](https://github.com/coder3101/tree-sitter-proto/actions/workflows/ci.yml)
44
[![crates][crates]](https://crates.io/coder3101/tree-sitter-proto)
5-
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-proto)
6-
[![pypi][pypi]](https://pypi.org/project/tree-sitter-proto)
75

86
Protocol buffer grammer for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
97

8+
9+
## ✨ Features
10+
11+
- ✅ Basic Proto2 support
12+
- ✅ Proto3 support
13+
- ✅ Support for editions
14+
15+
16+
### Special Thanks
17+
18+
Special thanks to the following people for their amazing work in this grammer.
19+
20+
- [mitchellh](https://github.com/mitchellh/tree-sitter-proto) for their original work.
21+
- [treywood](https://github.com/treywood/tree-sitter-proto) for basic proto2 support.
22+
1023
[ci]: https://img.shields.io/github/actions/workflow/status/coder3101/tree-sitter-proto/ci.yml?logo=github&label=CI
11-
[npm]: https://img.shields.io/npm/v/tree-sitter-proto?logo=npm
12-
[crates]: https://img.shields.io/crates/v/tree-sitter-proto?logo=rust
13-
[pypi]: https://img.shields.io/pypi/v/tree-sitter-proto?logo=pypi&logoColor=ffd242
24+
[crates]: https://img.shields.io/crates/v/tree-sitter-proto?logo=rust

grammar.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = grammar({
3434
// proto = syntax { import | package | option | topLevelDef | emptyStatement }
3535
// topLevelDef = message | enum | service
3636
source_file: $ => seq(
37-
optional($.syntax),
37+
optional(choice($.syntax, $.edition)),
3838
optional(repeat(choice(
3939
$.import,
4040
$.package,
@@ -49,6 +49,8 @@ module.exports = grammar({
4949

5050
empty_statement: _ => ';',
5151

52+
// edition = "edition" "=" quote numeric quote ";"
53+
edition: $ => seq('edition', '=', field('year', $.string), ';'),
5254
// syntax = "syntax" "=" quote "proto3" quote ";"
5355
syntax: $ => seq('syntax', '=', choice('"proto3"', '"proto2"'), ';'),
5456

@@ -411,17 +413,27 @@ module.exports = grammar({
411413
))),
412414
)),
413415

414-
// reserved_identifier = \" letter { letter | decimalDigit | "_" } \"
415-
reserved_identifier: $ => token(seq(
416-
'"',
417-
letter,
418-
optional(repeat(choice(
419-
letter,
420-
decimal_digit,
421-
'_',
422-
))),
423-
'"',
424-
)),
416+
// reserved_identifier = \" | ' letter { letter | decimalDigit | "_" } ' | \"
417+
reserved_identifier: $ => token(
418+
choice(
419+
seq(
420+
'"',
421+
letter,
422+
optional(repeat(choice(letter, decimal_digit, '_'))),
423+
'"',
424+
),
425+
seq(
426+
'\'',
427+
letter,
428+
optional(repeat(choice(letter, decimal_digit, '_'))),
429+
'\'',
430+
),
431+
seq(
432+
letter,
433+
optional(repeat(choice(letter, decimal_digit, '_'))),
434+
),
435+
),
436+
),
425437
_identifier_or_string: $ => choice($.identifier, $.string),
426438

427439
// fullIdent = ident { "." ident }

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tree-sitter-proto",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Parser for proto2 and proto3 files",
55
"repository": "github:tree-sitter/tree-sitter-proto",
66
"license": "MIT",
@@ -46,6 +46,7 @@
4646
"scripts": {
4747
"install": "node-gyp-build",
4848
"lint": "eslint grammar.js",
49+
"lint-fix": "eslint grammar.js --fix",
4950
"prestart": "tree-sitter build --wasm",
5051
"start": "tree-sitter playground",
5152
"test": "node --test bindings/node/*_test.js"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "tree-sitter-proto"
77
description = "Parser for proto2 and proto3 files"
8-
version = "0.1.0"
8+
version = "0.2.0"
99
keywords = ["incremental", "parsing", "tree-sitter", "proto"]
1010
classifiers = [
1111
"Intended Audience :: Developers",

queries/highlights.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
"syntax"
3+
"edition"
34
"package"
45
"option"
56
"import"

0 commit comments

Comments
 (0)