Skip to content

feat: add support for editions #1

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 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: tree-sitter/parser-test-action@v2
with:
test-rust: true
test-node: false
test-python: true
test-go: true
test-swift: true
test-swift: false
test-node: false
19 changes: 0 additions & 19 deletions .github/workflows/fuzz.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-proto"
description = "Parser for proto2 and proto3 files"
version = "0.1.0"
version = "0.2.0"
authors = ["Mohammad Ashar Khan <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

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

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


## ✨ Features

- ✅ Basic Proto2 support
- ✅ Proto3 support
- ✅ Support for editions


### Special Thanks

Special thanks to the following people for their amazing work in this grammer.

- [mitchellh](https://github.com/mitchellh/tree-sitter-proto) for their original work.
- [treywood](https://github.com/treywood/tree-sitter-proto) for basic proto2 support.

[ci]: https://img.shields.io/github/actions/workflow/status/coder3101/tree-sitter-proto/ci.yml?logo=github&label=CI
[npm]: https://img.shields.io/npm/v/tree-sitter-proto?logo=npm
[crates]: https://img.shields.io/crates/v/tree-sitter-proto?logo=rust
[pypi]: https://img.shields.io/pypi/v/tree-sitter-proto?logo=pypi&logoColor=ffd242
[crates]: https://img.shields.io/crates/v/tree-sitter-proto?logo=rust
36 changes: 24 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = grammar({
// proto = syntax { import | package | option | topLevelDef | emptyStatement }
// topLevelDef = message | enum | service
source_file: $ => seq(
optional($.syntax),
optional(choice($.syntax, $.edition)),
optional(repeat(choice(
$.import,
$.package,
Expand All @@ -49,6 +49,8 @@ module.exports = grammar({

empty_statement: _ => ';',

// edition = "edition" "=" quote numeric quote ";"
edition: $ => seq('edition', '=', field('year', $.string), ';'),
// syntax = "syntax" "=" quote "proto3" quote ";"
syntax: $ => seq('syntax', '=', choice('"proto3"', '"proto2"'), ';'),

Expand Down Expand Up @@ -411,17 +413,27 @@ module.exports = grammar({
))),
)),

// reserved_identifier = \" letter { letter | decimalDigit | "_" } \"
reserved_identifier: $ => token(seq(
'"',
letter,
optional(repeat(choice(
letter,
decimal_digit,
'_',
))),
'"',
)),
// reserved_identifier = \" | ' letter { letter | decimalDigit | "_" } ' | \"
reserved_identifier: $ => token(
choice(
seq(
'"',
letter,
optional(repeat(choice(letter, decimal_digit, '_'))),
'"',
),
seq(
'\'',
letter,
optional(repeat(choice(letter, decimal_digit, '_'))),
'\'',
),
seq(
letter,
optional(repeat(choice(letter, decimal_digit, '_'))),
),
),
),
_identifier_or_string: $ => choice($.identifier, $.string),

// fullIdent = ident { "." ident }
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tree-sitter-proto",
"version": "0.1.0",
"version": "0.2.0",
"description": "Parser for proto2 and proto3 files",
"repository": "github:tree-sitter/tree-sitter-proto",
"license": "MIT",
Expand Down Expand Up @@ -46,6 +46,7 @@
"scripts": {
"install": "node-gyp-build",
"lint": "eslint grammar.js",
"lint-fix": "eslint grammar.js --fix",
"prestart": "tree-sitter build --wasm",
"start": "tree-sitter playground",
"test": "node --test bindings/node/*_test.js"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "tree-sitter-proto"
description = "Parser for proto2 and proto3 files"
version = "0.1.0"
version = "0.2.0"
keywords = ["incremental", "parsing", "tree-sitter", "proto"]
classifiers = [
"Intended Audience :: Developers",
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"syntax"
"edition"
"package"
"option"
"import"
Expand Down
Loading