Skip to content
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

Add type grammar #89

Merged
merged 1 commit into from
Mar 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
* text eol=lf

grammars/ocaml/src/*.json linguist-generated
grammars/ocaml/src/parser.c linguist-generated

grammars/interface/src/*.json linguist-generated
grammars/interface/src/parser.c linguist-generated

grammars/ocaml/src/*.json linguist-generated
grammars/ocaml/src/parser.c linguist-generated
grammars/type/src/*.json linguist-generated
grammars/type/src/parser.c linguist-generated

include/tree_sitter/* linguist-vendored

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Test interface
working-directory: grammars/interface
run: tree-sitter test
- name: Test type
working-directory: grammars/type
run: tree-sitter test
- name: Test highlighting
run: tree-sitter test

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ include = [
"grammars/interface/grammar.js",
"grammars/interface/src/*.c",
"grammars/interface/src/*.json",
"grammars/type/grammar.js",
"grammars/type/src/*.c",
"grammars/type/src/*.json",
"include/*",
"queries/*"
]
Expand Down
4 changes: 4 additions & 0 deletions Makefile

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

6 changes: 4 additions & 2 deletions Package.swift

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

OCaml grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).

This module defines two grammars for implementation (`.ml`) and interface (`.mli`) files. Require them as follows:
This module defines grammars for implementations (`.ml`) interfaces (`.mli`) and types. Require them as follows:

```js
require('tree-sitter-ocaml').ocaml;
require('tree-sitter-ocaml').interface;
require('tree-sitter-ocaml').type;
```

References
Expand Down
2 changes: 2 additions & 0 deletions binding.gyp

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

1 change: 1 addition & 0 deletions bindings/c/tree-sitter-ocaml.h

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

14 changes: 14 additions & 0 deletions bindings/go/binding_test.go

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

13 changes: 13 additions & 0 deletions bindings/go/binding_type.go

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

8 changes: 8 additions & 0 deletions bindings/node/binding.cc

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

1 change: 1 addition & 0 deletions bindings/node/index.d.ts

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

1 change: 1 addition & 0 deletions bindings/node/index.js

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

1 change: 1 addition & 0 deletions bindings/node/type.js

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

4 changes: 2 additions & 2 deletions bindings/python/tree_sitter_ocaml/__init__.py

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

4 changes: 3 additions & 1 deletion bindings/python/tree_sitter_ocaml/__init__.pyi

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

7 changes: 7 additions & 0 deletions bindings/python/tree_sitter_ocaml/binding.c

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

4 changes: 2 additions & 2 deletions bindings/rust/README.md

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

3 changes: 2 additions & 1 deletion bindings/rust/build.rs

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

31 changes: 29 additions & 2 deletions bindings/rust/lib.rs

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

1 change: 1 addition & 0 deletions bindings/swift/TreeSitterOCaml/ocaml.h

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

14 changes: 14 additions & 0 deletions bindings/swift/TreeSitterOCamlTests/TreeSitterOCamlTests.swift

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

16 changes: 16 additions & 0 deletions grammars/type/grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

module.exports = grammar(require('../ocaml/grammar'), {
name: 'ocaml_type',

rules: {
type: $ => $._type
}
})

// Make 'type' the first rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this extra magic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, we'd have to reuse the compilation_unit entrypoint of the ocaml grammar, so 'a would be parsed as

(compilation_unit (type_variable))

instead of

(type (type_variable))

The tree-sitter extension mechanism is not really made for changing the entrypoint of a grammar, but for overriding some rules to create a variation of the same grammar.

module.exports.grammar.rules = Object.assign(
{type: null},
module.exports.grammar.rules
)
3 changes: 3 additions & 0 deletions grammars/type/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "../../bindings/node/type"
}