Merge commit 'cc26b1ef111100f26a137bcbcd39fd4e35be9a59'

pull/315/head
Wilfred Hughes 2022-07-10 23:20:32 +07:00
commit beacd69dd2
18 changed files with 52020 additions and 51857 deletions

@ -2,9 +2,13 @@ name: build
on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
build:
name: build
build-node:
name: build-node
runs-on: ubuntu-latest
steps:
- name: Checkout code
@ -23,5 +27,30 @@ jobs:
- name: Install dependencies
run: npm install
- name: Cache examples
uses: actions/cache@v3
with:
path: examples
key: ${{ hashFiles('script/parse-examples') }}
- name: Test corpus & parse examples
run: npm test
build-rust:
name: build-rust
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
- name: Build
run: cargo build --release
- name: Test
run: cargo test

@ -3,7 +3,17 @@ node_modules
build
examples
*.log
test.ml
test.mli
log.html
/test.ml
/test.mli
target
Cargo.lock
# These files would be generated by 'tree-sitter generate' with the default
# settings. We don't want them because there's already a copy at the root.
/interface/Cargo.toml
/interface/binding.gyp
/interface/bindings
/ocaml/Cargo.toml
/ocaml/binding.gyp
/ocaml/bindings

@ -1,10 +1,10 @@
[package]
name = "tree-sitter-ocaml"
description = "OCaml grammar for the tree-sitter parsing library"
version = "0.19.0"
version = "0.20.0"
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
license = "MIT"
readme = "README.md"
readme = "bindings/rust/README.md"
keywords = ["incremental", "parsing", "ocaml"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-ocaml"
@ -12,20 +12,20 @@ edition = "2018"
build = "bindings/rust/build.rs"
include = [
"common",
"common/*",
"bindings/rust/*",
"ocaml/grammar.js",
"ocaml/src",
"ocaml/src/*",
"interface/grammar.js",
"interface/src",
"queries"
"interface/src/*",
"queries/*"
]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.19"
tree-sitter = "0.20"
[build-dependencies]
cc = "1.0"

@ -8,12 +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:
```js
require('tree-sitter-ocaml/ocaml');
require('tree-sitter-ocaml/interface');
require('tree-sitter-ocaml').ocaml;
require('tree-sitter-ocaml').interface;
```
References
* [OCaml language reference](https://caml.inria.fr/pub/docs/manual-ocaml/language.html)
* [OCaml language extensions](https://caml.inria.fr/pub/docs/manual-ocaml/extn.html)
* [OCaml language reference](https://ocaml.org/manual/language.html)
* [OCaml language extensions](https://ocaml.org/manual/extn.html)
* [OCaml parser](https://github.com/ocaml/ocaml/blob/trunk/parsing/parser.mly)

@ -0,0 +1,42 @@
# tree-sitter-ocaml
This crate provides Ocaml grammars for the [tree-sitter][] parsing library.
There are separate grammars for implementation (`.ml`) and interface (`.mli`)
files.
To use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
file. (Note that you will probably also need to depend on the
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
way.)
```toml
[dependencies]
tree-sitter = "0.20"
tree-sitter-ocaml = "0.20"
```
Typically, you will use the [language][language func] function to add this
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
```rust
let code = r#"
module M = struct
let x = 0
end
"#;
let mut parser = Parser::new();
parser
.set_language(tree_sitter_ocaml::language_ocaml())
.expect("Error loading OCaml grammar");
let tree = parser.parse(code, None).unwrap();
```
If you have any questions, please reach out to us in the [tree-sitter
discussions] page.
[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
[language func]: https://docs.rs/tree-sitter-rust/*/tree_sitter_ocaml/fn.language_ocaml.html
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
[tree-sitter]: https://tree-sitter.github.io/
[tree-sitter crate]: https://crates.io/crates/tree-sitter
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions

@ -4,15 +4,16 @@ fn main() {
let interface_dir = root_dir.join("interface").join("src");
let mut c_config = cc::Build::new();
c_config.include(&ocaml_dir);
c_config
.include(&ocaml_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&ocaml_dir);
cpp_config
.cpp(true)
.include(&ocaml_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");

@ -1,23 +1,22 @@
//! This crate provides OCaml and OCaml Interface grammars for the [tree-sitter][] parsing library.
//! This crate provides OCaml grammars for the [tree-sitter][] parsing library.
//! There are separate grammars for implementation (`.ml`) and interface
//! (`.mli`) files.
//!
//! Typically, you will use the [language_ocaml][language func] function to add this grammar to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//! Typically, you will use the [language_ocaml][language func] function to add
//! this grammar to a tree-sitter [Parser][], and then use the parser to parse
//! some code:
//!
//! ```
//! use tree_sitter::Parser;
//!
//! let code = r#"
//! module M = struct
//! let x = x
//! let x = 0
//! end
//! "#;
//! let mut parser = Parser::new();
//! let mut parser = tree_sitter::Parser::new();
//! parser
//! .set_language(tree_sitter_ocaml::language_ocaml())
//! .expect("Error loading ocaml grammar");
//! let parsed = parser.parse(code, None).unwrap();
//! let root = parsed.root_node();
//! assert!(!root.has_error());
//! .expect("Error loading OCaml grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
@ -32,31 +31,74 @@ extern "C" {
fn tree_sitter_ocaml_interface() -> Language;
}
/// Returns the tree-sitter [Language][] for this OCaml.
/// Get the tree-sitter [Language][] for OCaml.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language_ocaml() -> Language {
unsafe { tree_sitter_ocaml() }
}
/// Returns the tree-sitter [Language][] for TSX.
/// Get the tree-sitter [Language][] for OCaml interfaces.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language_ocaml_interface() -> Language {
unsafe { tree_sitter_ocaml_interface() }
}
/// The syntax highlighting query for this language.
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm");
/// The local-variable syntax highlighting query for this language.
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
/// The symbol tagging query for this language.
pub const TAGGING_QUERY: &str = include_str!("../../queries/tags.scm");
/// The content of the [`node-types.json`][] file for OCaml.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const OCAML_NODE_TYPES: &'static str = include_str!("../../ocaml/src/node-types.json");
/// The content of the [`node-types.json`][] file for this grammar.
/// The content of the [`node-types.json`][] file for OCaml interfaces.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const OCAML_NODE_TYPES: &str = include_str!("../../ocaml/src/node-types.json");
pub const INTERFACE_NODE_TYPES: &str = include_str!("../../interface/src/node-types.json");
pub const INTERFACE_NODE_TYPES: &'static str = include_str!("../../interface/src/node-types.json");
/// The syntax highlighting query for OCaml.
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
/// The local-variable syntax highlighting query for OCaml.
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
/// The symbol tagging query for OCaml.
pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
#[cfg(test)]
mod tests {
#[test]
fn test_ocaml() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language_ocaml())
.expect("Error loading OCaml grammar");
let code = r#"
module M = struct
let x = 0
end
"#;
let tree = parser.parse(code, None).unwrap();
let root = tree.root_node();
assert!(!root.has_error());
}
#[test]
fn test_ocaml_interface() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language_ocaml_interface())
.expect("Error loading OCaml interface grammar");
let code = r#"
module M : sig
val x : int
end
"#;
let tree = parser.parse(code, None).unwrap();
let root = tree.root_node();
assert!(!root.has_error());
}
}

@ -8711,12 +8711,20 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_ext"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_ext"
},
{
"type": "SYMBOL",
"name": "_signature"
}
]
},
{
"type": "SYMBOL",
"name": "_signature"
"type": "BLANK"
}
]
}

File diff suppressed because it is too large Load Diff

@ -102,8 +102,8 @@ struct TSLanguage {
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char **symbol_names;
const char **field_names;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
@ -123,6 +123,7 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*

@ -5,6 +5,7 @@ Floating attributes
[@@@id]
[@@@I.D]
[@@@id let x = x]
[@@@id:]
[@@@id : t]
[@@@id : type t type t]
[@@@id ? A x]
@ -21,6 +22,7 @@ Floating attributes
(let_binding
(value_name)
(value_path (value_name))))))
(floating_attribute (attribute_id) (attribute_payload))
(floating_attribute
(attribute_id)
(attribute_payload

@ -1726,7 +1726,7 @@ module.exports = grammar({
attribute_payload: $ => choice(
$._structure,
seq(':', choice($._type_ext, $._signature)),
seq(':', optional(choice($._type_ext, $._signature))),
seq(
'?',
$._pattern_ext,

@ -8728,12 +8728,20 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_ext"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_ext"
},
{
"type": "SYMBOL",
"name": "_signature"
}
]
},
{
"type": "SYMBOL",
"name": "_signature"
"type": "BLANK"
}
]
}

File diff suppressed because it is too large Load Diff

@ -102,8 +102,8 @@ struct TSLanguage {
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char **symbol_names;
const char **field_names;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
@ -123,6 +123,7 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*

@ -1,6 +1,6 @@
{
"name": "tree-sitter-ocaml",
"version": "0.19.0",
"version": "0.20.0",
"description": "OCaml grammar for tree-sitter",
"keywords": [
"parser",
@ -9,10 +9,10 @@
"author": "Max Brunsfeld",
"license": "MIT",
"dependencies": {
"nan": "^2.14.1"
"nan": "^2.16.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.19.2"
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"build": "npm run build-ocaml && npm run build-interface",

@ -17,24 +17,7 @@ examples/ocaml/stdlib/templates/moreLabels.template.mli
examples/ocaml/testsuite/tests/generated-parse-errors/errors.ml
examples/ocaml/testsuite/tests/lexing/escape.ml
examples/ocaml/testsuite/tests/lexing/uchar_esc.ml
examples/ocaml/testsuite/tests/parse-errors/escape_error.ml
examples/ocaml/testsuite/tests/parse-errors/expecting.ml
examples/ocaml/testsuite/tests/parse-errors/pr7847.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_class_signature.mli
examples/ocaml/testsuite/tests/parse-errors/unclosed_class_simpl_expr1.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_class_simpl_expr2.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_class_simpl_expr3.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_object.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_expr1.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_expr2.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_expr3.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_expr4.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_expr5.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_paren_module_type.mli
examples/ocaml/testsuite/tests/parse-errors/unclosed_sig.mli
examples/ocaml/testsuite/tests/parse-errors/unclosed_simple_expr.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_simple_pattern.ml
examples/ocaml/testsuite/tests/parse-errors/unclosed_struct.ml
examples/ocaml/testsuite/tests/parse-errors/*
examples/ocaml/testsuite/tests/parsing/anonymous_class_parameter.ml
examples/ocaml/testsuite/tests/parsing/arrow_ambiguity.ml
examples/ocaml/testsuite/tests/parsing/constructor_declarations.ml
@ -48,5 +31,17 @@ examples/ocaml/testsuite/tests/typing-misc/typecore_errors.ml
examples/ocaml/testsuite/tests/typing-sigsubst/sig_local_aliases_syntax_errors.ml
examples/ocaml/testsuite/tests/typing-sigsubst/sig_local_aliases.ml
examples/ocaml/testsuite/tests/typing-warnings/pr7261.ml
examples/ocamlformat/test/failing/*/*
examples/ocamlformat/test/passing/*/*
examples/ocamlformat/test/rpc/big_margin/foo.ml
examples/ocamlformat/vendor/parser-recovery/test/expect/signature/*.mli
examples/ocamlformat/vendor/parser-recovery/test/expect/structure/*.ml
examples/ppxlib/astlib/astlib.ml
examples/ppxlib/astlib/location.ml
examples/ppxlib/astlib/longident.ml
examples/ppxlib/test/code_path/test.ml
examples/ppxlib/test/driver/non-compressible-suffix/test.ml
examples/ppxlib/test/ppx_import_support/test.ml
examples/ppxlib/test/quoter/test.ml
examples/opam/src/core/opamCompat.ml
examples/opam/src/core/opamCompat.mli

@ -25,21 +25,23 @@ function clone_repo {
popd > /dev/null
}
clone_repo 0install 0install 3411b55158e4896018d14946ab8a9f4522bc84b1
clone_repo BinaryAnalysisPlatform bap ea79178856512355f1789183a0dcfac7d2e830ed
clone_repo dbuenzli cmdliner db4d02a9eb47b5c43127a67cb121004b03ea3719
clone_repo facebook flow fef70240a1358704d14810032eaddd2a7b161aaa
clone_repo facebook pyre-check 50fd4352a53ff3d020308eaacb2d7801c672d719
clone_repo garrigue lablgtk 61e524bb6141d07f1fb46e00a48009eb49bfcca2
clone_repo janestreet base e8e658eded12b085bcca890dc035ffbe09460aec
clone_repo mirage ocaml-cohttp bc6191afb140279c222f33c8a5e7c7eb5d08e618
clone_repo ocaml dune d6e490c24dfb4607080b6a41930bb9d378bc2a43
clone_repo ocaml merlin 5ca4857302c2d2d329fd01d0db6a22fa5922b42a
clone_repo ocaml ocaml 90c1365901d22826e419129428a94515ca2b5af1
clone_repo ocaml opam 598d9691faa29e5876fd6db8d656c8d41ce78896
clone_repo ocsigen js_of_ocaml 69c904855b1f2099bdd7506e6cc075f3568f4b25
clone_repo ocsigen lwt f843bd81de08a0a27fd9908e960b0c3e8b2bc6b5
clone_repo owlbarn owl e5c440bba643c291ed2df29c3c8e990d7875bb94
clone_repo 0install 0install b88111c7dc1612b0beaa175df9c91df4fa36556b
clone_repo BinaryAnalysisPlatform bap a972f8a419294dfb21847db5172ba58c5d7767eb
clone_repo dbuenzli cmdliner 2c370b7ca519473584c04a3c4f89683f3cc0aad0
clone_repo facebook flow 5ada26749e0a95a1e562aee955859cc10decf517
clone_repo facebook pyre-check b794d924f77dd005af15da6fafb73010394804e3
clone_repo garrigue lablgtk b298ee1b4cba588537df1c4cfd996358e3a8750b
clone_repo janestreet base 8993e35ba2e83e5020b2deb548253ef1e4a699d4
clone_repo mirage ocaml-cohttp 628d8716b22bb7933863dd584673745c974707be
clone_repo ocaml dune 50815dbdda5c924142bf2c54feba87c5894465d5
clone_repo ocaml merlin dd7663fcff929ac395909cada9e829acdc77e97e
clone_repo ocaml ocaml 1042d5cd441ec2c8b5c87151313dbe7d1eebf2e7
clone_repo ocaml opam 51d458b5946d938aa2b45ddc924a2ad75130fb69
clone_repo ocaml-ppx ocamlformat b436f8d9e53661c1f5b51d40f701b9bd74cd4f84
clone_repo ocaml-ppx ppxlib 5fe8514d59ccbdd312b709ed3aea00781feefca3
clone_repo ocsigen js_of_ocaml ee5c335882aab362e66f5993d2a97bf7886cd247
clone_repo ocsigen lwt b3e7dd029dacbe37df9565c142c2206cfe6831c2
clone_repo owlbarn owl eead31f1920e63b876421e6a30e61c947f29827f
known_failures="$(cat script/known_failures.txt)"