mirror of https://github.com/Wilfred/difftastic/
Add 'vendor/tree-sitter-ocaml/' from commit '0348562f385bc2bd67ecf181425e1afd6d454192'
git-subtree-dir: vendor/tree-sitter-ocaml git-subtree-mainline:ida_star7f259afc79git-subtree-split:0348562f38
commit
4a6bb3db1f
@ -0,0 +1,3 @@
|
||||
ocaml/src/parser.c linguist-vendored
|
||||
interface/src/parser.c linguist-vendored
|
||||
/examples/** linguist-vendored
|
||||
@ -0,0 +1,27 @@
|
||||
name: build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: '12'
|
||||
|
||||
- name: Display Node versions
|
||||
run: |
|
||||
node --version
|
||||
npm --version
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Test corpus & parse examples
|
||||
run: npm test
|
||||
@ -0,0 +1,9 @@
|
||||
package-lock.json
|
||||
node_modules
|
||||
build
|
||||
examples
|
||||
*.log
|
||||
test.ml
|
||||
test.mli
|
||||
target
|
||||
Cargo.lock
|
||||
@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "tree-sitter-ocaml"
|
||||
description = "OCaml grammar for the tree-sitter parsing library"
|
||||
version = "0.19.0"
|
||||
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
keywords = ["incremental", "parsing", "ocaml"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-ocaml"
|
||||
edition = "2018"
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = [
|
||||
"common",
|
||||
"bindings/rust/*",
|
||||
"ocaml/grammar.js",
|
||||
"ocaml/src",
|
||||
"interface/grammar.js",
|
||||
"interface/src",
|
||||
"queries"
|
||||
]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "0.19"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Max Brunsfeld and Pieter Goetschalckx
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -0,0 +1,19 @@
|
||||
tree-sitter-ocaml
|
||||
=================
|
||||
|
||||
[](https://github.com/tree-sitter/tree-sitter-ocaml/actions?query=workflow%3Abuild)
|
||||
|
||||
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');
|
||||
```
|
||||
|
||||
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 parser](https://github.com/ocaml/ocaml/blob/trunk/parsing/parser.mly)
|
||||
@ -0,0 +1,21 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_ocaml_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"ocaml/src"
|
||||
],
|
||||
"sources": [
|
||||
"ocaml/src/parser.c",
|
||||
"ocaml/src/scanner.c",
|
||||
"interface/src/parser.c",
|
||||
"interface/src/scanner.c",
|
||||
"bindings/node/binding.cc"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_ocaml();
|
||||
extern "C" TSLanguage * tree_sitter_ocaml_interface();
|
||||
|
||||
namespace {
|
||||
|
||||
NAN_METHOD(New) {}
|
||||
|
||||
void Init(Local<Object> exports, Local<Object> module) {
|
||||
Local<FunctionTemplate> ocaml_tpl = Nan::New<FunctionTemplate>(New);
|
||||
ocaml_tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
ocaml_tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
Local<Function> ocaml_constructor = Nan::GetFunction(ocaml_tpl).ToLocalChecked();
|
||||
Local<Object> ocaml_instance = ocaml_constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(ocaml_instance, 0, tree_sitter_ocaml());
|
||||
Nan::Set(ocaml_instance, Nan::New("name").ToLocalChecked(), Nan::New("ocaml").ToLocalChecked());
|
||||
|
||||
Local<FunctionTemplate> iface_tpl = Nan::New<FunctionTemplate>(New);
|
||||
iface_tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
iface_tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
Local<Function> iface_constructor = Nan::GetFunction(iface_tpl).ToLocalChecked();
|
||||
Local<Object> iface_instance = iface_constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(iface_instance, 0, tree_sitter_ocaml_interface());
|
||||
Nan::Set(iface_instance, Nan::New("name").ToLocalChecked(), Nan::New("ocaml_interface").ToLocalChecked());
|
||||
|
||||
Nan::Set(exports, Nan::New("ocaml").ToLocalChecked(), ocaml_instance);
|
||||
Nan::Set(exports, Nan::New("interface").ToLocalChecked(), iface_instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_ocaml_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -0,0 +1,20 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_ocaml_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_ocaml_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.ocaml.nodeTypeInfo = require("../../ocaml/src/node-types.json");
|
||||
module.exports.interface.nodeTypeInfo = require("../../interface/src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -0,0 +1 @@
|
||||
module.exports = require('./index').interface;
|
||||
@ -0,0 +1 @@
|
||||
module.exports = require('./index').ocaml;
|
||||
@ -0,0 +1,30 @@
|
||||
fn main() {
|
||||
let root_dir = std::path::Path::new(".");
|
||||
let ocaml_dir = root_dir.join("ocaml").join("src");
|
||||
let interface_dir = root_dir.join("interface").join("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config
|
||||
.include(&ocaml_dir)
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
|
||||
let mut cpp_config = cc::Build::new();
|
||||
cpp_config
|
||||
.cpp(true)
|
||||
.include(&ocaml_dir)
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
|
||||
for dir in &[ocaml_dir, interface_dir] {
|
||||
let parser_path = dir.join("parser.c");
|
||||
let scanner_path = dir.join("scanner.cc");
|
||||
c_config.file(&parser_path);
|
||||
cpp_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
}
|
||||
|
||||
c_config.compile("parser");
|
||||
cpp_config.compile("scanner");
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
//! This crate provides OCaml and OCaml Interface grammars for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! 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
|
||||
//! end
|
||||
//! "#;
|
||||
//! let mut parser = 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());
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language_ocaml.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_ocaml() -> Language;
|
||||
fn tree_sitter_ocaml_interface() -> Language;
|
||||
}
|
||||
|
||||
/// Returns the tree-sitter [Language][] for this 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.
|
||||
///
|
||||
/// [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 this grammar.
|
||||
///
|
||||
/// [`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");
|
||||
@ -0,0 +1,294 @@
|
||||
#include <tree_sitter/parser.h>
|
||||
#include <string>
|
||||
#include <wctype.h>
|
||||
|
||||
namespace {
|
||||
|
||||
enum {
|
||||
COMMENT,
|
||||
LEFT_QUOTED_STRING_DELIM,
|
||||
RIGHT_QUOTED_STRING_DELIM,
|
||||
STRING_DELIM,
|
||||
LINE_NUMBER_DIRECTIVE,
|
||||
NULL_CHARACTER
|
||||
};
|
||||
|
||||
struct Scanner {
|
||||
bool in_string = false;
|
||||
std::string quoted_string_id;
|
||||
|
||||
unsigned serialize(char *buffer) {
|
||||
size_t size = quoted_string_id.size();
|
||||
|
||||
buffer[0] = in_string;
|
||||
quoted_string_id.copy(&buffer[1], size);
|
||||
return size + 1;
|
||||
}
|
||||
|
||||
void deserialize(const char *buffer, unsigned length) {
|
||||
if (length > 0) {
|
||||
in_string = buffer[0];
|
||||
quoted_string_id.assign(&buffer[1], length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void advance(TSLexer *lexer) {
|
||||
lexer->advance(lexer, false);
|
||||
}
|
||||
|
||||
void skip(TSLexer *lexer) {
|
||||
lexer->advance(lexer, true);
|
||||
}
|
||||
|
||||
bool scan(TSLexer *lexer, const bool *valid_symbols) {
|
||||
if (valid_symbols[LEFT_QUOTED_STRING_DELIM] && (iswlower(lexer->lookahead) || lexer->lookahead == '_' || lexer->lookahead == '|')) {
|
||||
lexer->result_symbol = LEFT_QUOTED_STRING_DELIM;
|
||||
return scan_left_quoted_string_delimiter(lexer);
|
||||
} else if (valid_symbols[RIGHT_QUOTED_STRING_DELIM] && (lexer->lookahead == '|')) {
|
||||
advance(lexer);
|
||||
lexer->result_symbol = RIGHT_QUOTED_STRING_DELIM;
|
||||
return scan_right_quoted_string_delimiter(lexer);
|
||||
} else if (in_string && valid_symbols[STRING_DELIM] && lexer->lookahead == '"') {
|
||||
advance(lexer);
|
||||
in_string = false;
|
||||
lexer->result_symbol = STRING_DELIM;
|
||||
return true;
|
||||
}
|
||||
|
||||
while (iswspace(lexer->lookahead)) {
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
if (!in_string && lexer->lookahead == '#' && lexer->get_column(lexer) == 0) {
|
||||
advance(lexer);
|
||||
|
||||
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') advance(lexer);
|
||||
|
||||
if (!iswdigit(lexer->lookahead)) return false;
|
||||
while (iswdigit(lexer->lookahead)) advance(lexer);
|
||||
|
||||
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') advance(lexer);
|
||||
|
||||
if (lexer->lookahead != '"') return false;
|
||||
while (lexer->lookahead != '\n' && lexer->lookahead != '\r' && lexer->lookahead != '"') advance(lexer);
|
||||
if (lexer->lookahead != '"') return false;
|
||||
|
||||
while (lexer->lookahead != '\n' && lexer->lookahead != '\r') advance(lexer);
|
||||
|
||||
lexer->result_symbol = LINE_NUMBER_DIRECTIVE;
|
||||
return true;
|
||||
} else if (!in_string && lexer->lookahead == '(') {
|
||||
advance(lexer);
|
||||
lexer->result_symbol = COMMENT;
|
||||
return scan_comment(lexer);
|
||||
} else if (!in_string && valid_symbols[STRING_DELIM] && lexer->lookahead == '"') {
|
||||
advance(lexer);
|
||||
in_string = true;
|
||||
lexer->result_symbol = STRING_DELIM;
|
||||
return true;
|
||||
} else if (valid_symbols[NULL_CHARACTER] && lexer->lookahead == '\0') {
|
||||
return !lexer->eof(lexer);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void scan_string(TSLexer *lexer) {
|
||||
for (;;) {
|
||||
switch (lexer->lookahead) {
|
||||
case '\\':
|
||||
advance(lexer);
|
||||
advance(lexer);
|
||||
break;
|
||||
case '"':
|
||||
advance(lexer);
|
||||
return;
|
||||
case '\0':
|
||||
if (lexer->eof(lexer)) return;
|
||||
advance(lexer);
|
||||
break;
|
||||
default:
|
||||
advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char scan_character(TSLexer *lexer) {
|
||||
char last = 0;
|
||||
|
||||
switch (lexer->lookahead) {
|
||||
case '\\':
|
||||
advance(lexer);
|
||||
if (iswdigit(lexer->lookahead)) {
|
||||
advance(lexer);
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
if (!iswdigit(lexer->lookahead)) return 0;
|
||||
advance(lexer);
|
||||
}
|
||||
} else {
|
||||
switch (lexer->lookahead) {
|
||||
case 'x':
|
||||
advance(lexer);
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
if (!iswdigit(lexer->lookahead) && (towupper(lexer->lookahead) < 'A' || towupper(lexer->lookahead) > 'F')) return 0;
|
||||
advance(lexer);
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
advance(lexer);
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (!iswdigit(lexer->lookahead) || lexer->lookahead > '7') return 0;
|
||||
advance(lexer);
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
case '"':
|
||||
case '\\':
|
||||
case 'n':
|
||||
case 't':
|
||||
case 'b':
|
||||
case 'r':
|
||||
case ' ':
|
||||
last = lexer->lookahead;
|
||||
advance(lexer);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
break;
|
||||
case '\0':
|
||||
if (lexer->eof(lexer)) return 0;
|
||||
advance(lexer);
|
||||
break;
|
||||
default:
|
||||
last = lexer->lookahead;
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '\'') {
|
||||
advance(lexer);
|
||||
return 0;
|
||||
} else {
|
||||
return last;
|
||||
}
|
||||
}
|
||||
|
||||
bool scan_left_quoted_string_delimiter(TSLexer *lexer) {
|
||||
quoted_string_id.clear();
|
||||
|
||||
while (iswlower(lexer->lookahead) || lexer->lookahead == '_') {
|
||||
quoted_string_id.push_back(lexer->lookahead);
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
if (lexer->lookahead != '|') return false;
|
||||
|
||||
advance(lexer);
|
||||
in_string = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scan_right_quoted_string_delimiter(TSLexer *lexer) {
|
||||
for (size_t i = 0; i < quoted_string_id.size(); i++) {
|
||||
if (lexer->lookahead != quoted_string_id[i]) return false;
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
if (lexer->lookahead != '}') return false;
|
||||
|
||||
in_string = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scan_quoted_string(TSLexer *lexer) {
|
||||
if (!scan_left_quoted_string_delimiter(lexer)) return false;
|
||||
|
||||
for (;;) {
|
||||
switch (lexer->lookahead) {
|
||||
case '|':
|
||||
advance(lexer);
|
||||
if (scan_right_quoted_string_delimiter(lexer)) return true;
|
||||
break;
|
||||
case '\0':
|
||||
if (lexer->eof(lexer)) return false;
|
||||
advance(lexer);
|
||||
break;
|
||||
default:
|
||||
advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool scan_identifier(TSLexer *lexer) {
|
||||
if (iswalpha(lexer->lookahead) || lexer->lookahead == '_') {
|
||||
advance(lexer);
|
||||
while (iswalnum(lexer->lookahead) || lexer->lookahead == '_' || lexer->lookahead == '\'') {
|
||||
advance(lexer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool scan_extattrident(TSLexer *lexer) {
|
||||
while (scan_identifier(lexer)) {
|
||||
if (lexer->lookahead != '.') return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool scan_comment(TSLexer *lexer) {
|
||||
char last = 0;
|
||||
|
||||
if (lexer->lookahead != '*') return false;
|
||||
advance(lexer);
|
||||
|
||||
for (;;) {
|
||||
switch (last ? last : lexer->lookahead) {
|
||||
case '(':
|
||||
if (last) last = 0; else advance(lexer);
|
||||
scan_comment(lexer);
|
||||
break;
|
||||
case '*':
|
||||
if (last) last = 0; else advance(lexer);
|
||||
if (lexer->lookahead == ')') {
|
||||
advance(lexer);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
if (last) last = 0; else advance(lexer);
|
||||
last = scan_character(lexer);
|
||||
break;
|
||||
case '"':
|
||||
if (last) last = 0; else advance(lexer);
|
||||
scan_string(lexer);
|
||||
break;
|
||||
case '{':
|
||||
if (last) last = 0; else advance(lexer);
|
||||
if (lexer->lookahead == '%') {
|
||||
advance(lexer);
|
||||
if (lexer->lookahead == '%') advance(lexer);
|
||||
if (scan_extattrident(lexer)) {
|
||||
while (iswspace(lexer->lookahead)) advance(lexer);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scan_quoted_string(lexer)) advance(lexer);
|
||||
break;
|
||||
case '\0':
|
||||
if (lexer->eof(lexer)) return false;
|
||||
if (last) last = 0; else advance(lexer);
|
||||
break;
|
||||
default:
|
||||
if (scan_identifier(lexer) || last) last = 0; else advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
../../ocaml/corpus/module-items.txt
|
||||
@ -0,0 +1,49 @@
|
||||
==============================
|
||||
Value specification
|
||||
==============================
|
||||
|
||||
val x : t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(value_specification
|
||||
(value_name)
|
||||
(type_constructor_path (type_constructor))))
|
||||
|
||||
==============================
|
||||
Include
|
||||
==============================
|
||||
|
||||
include M
|
||||
include t
|
||||
include M.M
|
||||
include M.t
|
||||
include M.M.M
|
||||
include M.M.t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(include_module_type (module_type_path (module_type_name)))
|
||||
(include_module_type (module_type_path (module_type_name)))
|
||||
(include_module_type
|
||||
(module_type_path
|
||||
(extended_module_path (module_name))
|
||||
(module_type_name)))
|
||||
(include_module_type
|
||||
(module_type_path
|
||||
(extended_module_path (module_name))
|
||||
(module_type_name)))
|
||||
(include_module_type
|
||||
(module_type_path
|
||||
(extended_module_path
|
||||
(extended_module_path (module_name))
|
||||
(module_name))
|
||||
(module_type_name)))
|
||||
(include_module_type
|
||||
(module_type_path
|
||||
(extended_module_path
|
||||
(extended_module_path (module_name))
|
||||
(module_name))
|
||||
(module_type_name))))
|
||||
@ -0,0 +1,7 @@
|
||||
module.exports = grammar(require('../ocaml/grammar'), {
|
||||
name: 'ocaml_interface',
|
||||
|
||||
rules: {
|
||||
compilation_unit: $ => optional($._signature)
|
||||
}
|
||||
})
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"main": "../bindings/node/interface"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
#include "../../common/scanner.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void *tree_sitter_ocaml_interface_external_scanner_create() {
|
||||
return new Scanner();
|
||||
}
|
||||
|
||||
void tree_sitter_ocaml_interface_external_scanner_destroy(void *payload) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
delete scanner;
|
||||
}
|
||||
|
||||
unsigned tree_sitter_ocaml_interface_external_scanner_serialize(void *payload, char *buffer) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->serialize(buffer);
|
||||
}
|
||||
|
||||
void tree_sitter_ocaml_interface_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
scanner->deserialize(buffer, length);
|
||||
}
|
||||
|
||||
bool tree_sitter_ocaml_interface_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->scan(lexer, valid_symbols);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,223 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
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 TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
@ -0,0 +1,171 @@
|
||||
===========================
|
||||
Floating attributes
|
||||
===========================
|
||||
|
||||
[@@@id]
|
||||
[@@@I.D]
|
||||
[@@@id let x = x]
|
||||
[@@@id : t]
|
||||
[@@@id : type t type t]
|
||||
[@@@id ? A x]
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(floating_attribute (attribute_id))
|
||||
(floating_attribute (attribute_id))
|
||||
(floating_attribute
|
||||
(attribute_id)
|
||||
(attribute_payload
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))))))
|
||||
(floating_attribute
|
||||
(attribute_id)
|
||||
(attribute_payload
|
||||
(type_constructor_path (type_constructor))))
|
||||
(floating_attribute
|
||||
(attribute_id)
|
||||
(attribute_payload
|
||||
(type_definition (type_binding (type_constructor)))
|
||||
(type_definition (type_binding (type_constructor)))))
|
||||
(floating_attribute
|
||||
(attribute_id)
|
||||
(attribute_payload
|
||||
(constructor_pattern
|
||||
(constructor_path (constructor_name))
|
||||
(value_pattern)))))
|
||||
|
||||
===========================
|
||||
Item attributes
|
||||
===========================
|
||||
|
||||
x [@@id] [@@id]
|
||||
let x = x [@@id] and x = x [@@id]
|
||||
module M = M [@@id]
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item (value_path (value_name))
|
||||
(item_attribute (attribute_id))
|
||||
(item_attribute (attribute_id)))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))
|
||||
(item_attribute (attribute_id)))
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))
|
||||
(item_attribute (attribute_id))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name))
|
||||
(item_attribute (attribute_id)))))
|
||||
|
||||
===========================
|
||||
Attributes
|
||||
===========================
|
||||
|
||||
let%id x = x and [@id] x = x [@id]
|
||||
type t = A [@id] [@id]
|
||||
type t = { x : t [@id]; [@id] }
|
||||
module M = struct [@id] end [@id];;
|
||||
x ;%id x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(value_definition
|
||||
(attribute_id)
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name)))
|
||||
(attribute (attribute_id))
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))))
|
||||
(attribute (attribute_id))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(variant_declaration
|
||||
(constructor_declaration
|
||||
(constructor_name)))))
|
||||
(attribute (attribute_id))
|
||||
(attribute (attribute_id))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(record_declaration
|
||||
(field_declaration
|
||||
(field_name)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(attribute (attribute_id))
|
||||
(attribute (attribute_id)))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(structure (attribute (attribute_id)))))
|
||||
(attribute (attribute_id))
|
||||
(expression_item
|
||||
(sequence_expression
|
||||
(value_path (value_name))
|
||||
(attribute_id)
|
||||
(value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Item extension
|
||||
===========================
|
||||
|
||||
[%%id];;
|
||||
{%%M.id|payload|};;
|
||||
{%%id ab|payload|ab};;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(item_extension (attribute_id))
|
||||
(quoted_item_extension (attribute_id) (quoted_string_content))
|
||||
(quoted_item_extension (attribute_id) (quoted_string_content)))
|
||||
|
||||
===========================
|
||||
Extension
|
||||
===========================
|
||||
|
||||
module type T = [%id]
|
||||
module M = [%id]
|
||||
type t = [%id]
|
||||
let x = [%id]
|
||||
let x = {%id|payload|}
|
||||
let x = {%id ab|payload|ab};;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_type_definition
|
||||
(module_type_name)
|
||||
(extension (attribute_id)))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(extension (attribute_id))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(extension (attribute_id))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(extension (attribute_id))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(quoted_extension (attribute_id) (quoted_string_content))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(quoted_extension (attribute_id) (quoted_string_content)))))
|
||||
@ -0,0 +1,77 @@
|
||||
==============================
|
||||
Comments
|
||||
==============================
|
||||
|
||||
(**)
|
||||
(* *)
|
||||
(**
|
||||
doc
|
||||
*)
|
||||
( *)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(expression_item (value_path (parenthesized_operator (infix_operator)))))
|
||||
|
||||
==============================
|
||||
Strings and comments
|
||||
==============================
|
||||
|
||||
(* "*)" *)
|
||||
"(**)";;
|
||||
"(*";;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(comment)
|
||||
(expression_item (string (string_content)))
|
||||
(expression_item (string (string_content))))
|
||||
|
||||
==============================
|
||||
Characters and comments
|
||||
==============================
|
||||
|
||||
(* '"' *)
|
||||
(* f' '"' *)
|
||||
(* *)
|
||||
(* '\o170' '"' *)
|
||||
(* '\'"' *)
|
||||
(* '\" " *)
|
||||
(* '" " *)
|
||||
(* '*)
|
||||
x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(expression_item (value_path (value_name))))
|
||||
|
||||
==============================
|
||||
Quoted strings and comments
|
||||
==============================
|
||||
|
||||
(* {|*)|} *)
|
||||
(* {%id |*)|} *)
|
||||
{|(**)|};;
|
||||
{|(*|};;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(comment)
|
||||
(comment)
|
||||
(expression_item (quoted_string (quoted_string_content)))
|
||||
(expression_item (quoted_string (quoted_string_content))))
|
||||
@ -0,0 +1,716 @@
|
||||
===========================
|
||||
Values
|
||||
===========================
|
||||
|
||||
x;;
|
||||
M.x;;
|
||||
( + );;
|
||||
M.( + );;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item (value_path (value_name)))
|
||||
(expression_item
|
||||
(value_path
|
||||
(module_path (module_name))
|
||||
(value_name)))
|
||||
(expression_item
|
||||
(value_path (parenthesized_operator (infix_operator))))
|
||||
(expression_item
|
||||
(value_path
|
||||
(module_path (module_name))
|
||||
(parenthesized_operator (infix_operator)))))
|
||||
|
||||
===========================
|
||||
Constants
|
||||
===========================
|
||||
|
||||
493;;
|
||||
10_000_000;;
|
||||
0x1ed;;
|
||||
0o644;;
|
||||
0b111101101;;
|
||||
4.93e2;;
|
||||
493e+0;;
|
||||
0x7b.4p2;;
|
||||
'x';;
|
||||
'\n';;
|
||||
'\'';;
|
||||
'\120';;
|
||||
'\x78';;
|
||||
'\o170';;
|
||||
'
|
||||
';;
|
||||
"OCaml";;
|
||||
"\"\079\u{43}aml\"";;
|
||||
"OCaml\
|
||||
OCaml";;
|
||||
"%d %05.2f";;
|
||||
"@[%s@ %d@]@.";;
|
||||
"
|
||||
";;
|
||||
" ";;
|
||||
"";;
|
||||
{|OCaml|};;
|
||||
{id||id};;
|
||||
{id|{|}id}|idd||id};;
|
||||
{|%d@.|};;
|
||||
{|
|
||||
|};;
|
||||
{| |};;
|
||||
true;;
|
||||
();;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (number))
|
||||
(expression_item (character (character_content)))
|
||||
(expression_item (character (character_content (escape_sequence))))
|
||||
(expression_item (character (character_content (escape_sequence))))
|
||||
(expression_item (character (character_content (escape_sequence))))
|
||||
(expression_item (character (character_content (escape_sequence))))
|
||||
(expression_item (character (character_content (escape_sequence))))
|
||||
(expression_item (character (character_content)))
|
||||
(expression_item (string (string_content)))
|
||||
(expression_item (string (string_content (escape_sequence) (escape_sequence) (escape_sequence) (escape_sequence))))
|
||||
(expression_item (string (string_content (escape_sequence))))
|
||||
(expression_item (string (string_content (conversion_specification) (conversion_specification))))
|
||||
(expression_item (string (string_content
|
||||
(pretty_printing_indication)
|
||||
(conversion_specification)
|
||||
(pretty_printing_indication)
|
||||
(conversion_specification)
|
||||
(pretty_printing_indication)
|
||||
(pretty_printing_indication))))
|
||||
(expression_item (string (string_content)))
|
||||
(expression_item (string (string_content)))
|
||||
(expression_item (string))
|
||||
(expression_item (quoted_string (quoted_string_content)))
|
||||
(expression_item (quoted_string))
|
||||
(expression_item (quoted_string (quoted_string_content)))
|
||||
(expression_item (quoted_string (quoted_string_content
|
||||
(conversion_specification)
|
||||
(pretty_printing_indication))))
|
||||
(expression_item (quoted_string (quoted_string_content)))
|
||||
(expression_item (quoted_string (quoted_string_content)))
|
||||
(expression_item (boolean))
|
||||
(expression_item (unit)))
|
||||
|
||||
===========================
|
||||
Typed expression
|
||||
===========================
|
||||
|
||||
(x : t)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(typed_expression
|
||||
(value_path (value_name))
|
||||
(type_constructor_path (type_constructor)))))
|
||||
|
||||
===========================
|
||||
Lists, arrays and records
|
||||
===========================
|
||||
|
||||
[];;
|
||||
[x; x; x];;
|
||||
x :: x :: xs;;
|
||||
[||];;
|
||||
[| x; x; x |];;
|
||||
{ x = x; x; };;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item (list_expression))
|
||||
(expression_item
|
||||
(list_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(cons_expression
|
||||
(value_path (value_name))
|
||||
(cons_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name)))))
|
||||
(expression_item (array_expression))
|
||||
(expression_item
|
||||
(array_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(record_expression
|
||||
(field_expression
|
||||
(field_path (field_name))
|
||||
(value_path (value_name)))
|
||||
(field_expression
|
||||
(field_path (field_name))))))
|
||||
|
||||
===========================
|
||||
Get and set expressions
|
||||
===========================
|
||||
|
||||
x.y.z <- x;;
|
||||
x.(0).[0].{0,0} <- x;;
|
||||
x.%(0).M.%(0) <- x;;
|
||||
1 #? x.%(0);;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(set_expression
|
||||
(field_get_expression
|
||||
(field_get_expression
|
||||
(value_path (value_name))
|
||||
(field_path (field_name)))
|
||||
(field_path (field_name)))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(set_expression
|
||||
(bigarray_get_expression
|
||||
(string_get_expression
|
||||
(array_get_expression
|
||||
(value_path (value_name))
|
||||
(number))
|
||||
(number))
|
||||
(product_expression
|
||||
(number)
|
||||
(number)))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(set_expression
|
||||
(array_get_expression
|
||||
(array_get_expression
|
||||
(value_path (value_name))
|
||||
(indexing_operator_path (indexing_operator))
|
||||
(number))
|
||||
(indexing_operator_path
|
||||
(module_path (module_name))
|
||||
(indexing_operator))
|
||||
(number))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(hash_expression
|
||||
(number)
|
||||
(hash_operator)
|
||||
(array_get_expression
|
||||
(value_path (value_name))
|
||||
(indexing_operator_path (indexing_operator))
|
||||
(number)))))
|
||||
|
||||
===========================
|
||||
Coercions
|
||||
===========================
|
||||
|
||||
(x :> t);;
|
||||
(x : t :> t);;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(coercion_expression
|
||||
(value_path (value_name))
|
||||
(type_constructor_path (type_constructor))))
|
||||
(expression_item
|
||||
(coercion_expression
|
||||
(value_path (value_name))
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))))
|
||||
|
||||
===========================
|
||||
Local opens
|
||||
===========================
|
||||
|
||||
M.(x);;
|
||||
M.[x; x];;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(local_open_expression
|
||||
(module_path (module_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(local_open_expression
|
||||
(module_path (module_name))
|
||||
(list_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Package expressions
|
||||
===========================
|
||||
|
||||
(module M);;
|
||||
(module M : T);;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(package_expression
|
||||
(module_path (module_name))))
|
||||
(expression_item
|
||||
(package_expression
|
||||
(module_path (module_name))
|
||||
(module_type_path (module_type_name)))))
|
||||
|
||||
===========================
|
||||
Product expressions
|
||||
===========================
|
||||
|
||||
x, y, z;;
|
||||
(x, y)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(product_expression
|
||||
(product_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name)))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(parenthesized_expression
|
||||
(product_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Constructors
|
||||
===========================
|
||||
|
||||
A;;
|
||||
M.A;;
|
||||
A x;;
|
||||
( :: ) (x, l);;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(constructor_path (constructor_name)))
|
||||
(expression_item
|
||||
(constructor_path
|
||||
(module_path (module_name))
|
||||
(constructor_name)))
|
||||
(expression_item
|
||||
(application_expression
|
||||
(constructor_path (constructor_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(application_expression
|
||||
(constructor_path (constructor_name))
|
||||
(parenthesized_expression
|
||||
(product_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name)))))))
|
||||
|
||||
===========================
|
||||
Tags
|
||||
===========================
|
||||
|
||||
`A;;
|
||||
`A x;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item (tag))
|
||||
(expression_item
|
||||
(application_expression
|
||||
(tag)
|
||||
(value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Function application
|
||||
===========================
|
||||
|
||||
f x;;
|
||||
f x x;;
|
||||
f ~x ?x:x;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(application_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(application_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(application_expression
|
||||
(value_path (value_name))
|
||||
(labeled_argument (label_name))
|
||||
(labeled_argument
|
||||
(label_name)
|
||||
(value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Operators
|
||||
===========================
|
||||
|
||||
!x;;
|
||||
~-x;;
|
||||
-x;;
|
||||
x - y;;
|
||||
x lsl 1;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(prefix_expression
|
||||
(prefix_operator)
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(prefix_expression
|
||||
(prefix_operator)
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(sign_expression
|
||||
(sign_operator)
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(number))))
|
||||
|
||||
===========================
|
||||
If, while and for
|
||||
===========================
|
||||
|
||||
if x then y;;
|
||||
if x then y else z;;
|
||||
while x do y done;;
|
||||
for i = 1 to n do x done;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(if_expression
|
||||
(value_path (value_name))
|
||||
(then_clause (value_path (value_name)))))
|
||||
(expression_item
|
||||
(if_expression
|
||||
(value_path (value_name))
|
||||
(then_clause (value_path (value_name)))
|
||||
(else_clause (value_path (value_name)))))
|
||||
(expression_item
|
||||
(while_expression
|
||||
(value_path (value_name))
|
||||
(do_clause (value_path (value_name)))))
|
||||
(expression_item
|
||||
(for_expression
|
||||
(value_pattern)
|
||||
(number)
|
||||
(value_path (value_name))
|
||||
(do_clause (value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Sequence expressions
|
||||
===========================
|
||||
|
||||
x; y; z;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(sequence_expression
|
||||
(value_path (value_name))
|
||||
(sequence_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Match expressions
|
||||
===========================
|
||||
|
||||
match x with
|
||||
| x -> x
|
||||
| x when x -> x
|
||||
| x | x -> x
|
||||
| exception x -> x;;
|
||||
match+ x with x -> x;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(match_expression
|
||||
(value_path (value_name))
|
||||
(match_case
|
||||
(value_pattern)
|
||||
(value_path (value_name)))
|
||||
(match_case
|
||||
(value_pattern)
|
||||
(guard (value_path (value_name)))
|
||||
(value_path (value_name)))
|
||||
(match_case
|
||||
(or_pattern (value_pattern) (value_pattern))
|
||||
(value_path (value_name)))
|
||||
(match_case
|
||||
(exception_pattern (value_pattern))
|
||||
(value_path (value_name)))))
|
||||
(expression_item
|
||||
(match_expression
|
||||
(match_operator)
|
||||
(value_path (value_name))
|
||||
(match_case
|
||||
(value_pattern)
|
||||
(value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Function expressions
|
||||
===========================
|
||||
|
||||
function 0 -> 0 | x -> 1;;
|
||||
function A (type a) x -> 1;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(number)
|
||||
(number))
|
||||
(match_case
|
||||
(value_pattern)
|
||||
(number))))
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(constructor_pattern
|
||||
(constructor_path (constructor_name))
|
||||
(abstract_type (type_constructor))
|
||||
(value_pattern))
|
||||
(number)))))
|
||||
|
||||
===========================
|
||||
Try expressions
|
||||
===========================
|
||||
|
||||
try x with Exception -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(try_expression
|
||||
(value_path (value_name))
|
||||
(match_case
|
||||
(constructor_path (constructor_name))
|
||||
(unit)))))
|
||||
|
||||
===========================
|
||||
Let expressions
|
||||
===========================
|
||||
|
||||
let x = 0 in x;;
|
||||
let rec x = y and y = x in x;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(let_expression
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(number)))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(let_expression
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name)))
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))))
|
||||
(value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Assert expressions
|
||||
===========================
|
||||
|
||||
assert x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(assert_expression (value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Lazy expressions
|
||||
===========================
|
||||
|
||||
lazy x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(lazy_expression (value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Let module, open, exception
|
||||
===========================
|
||||
|
||||
let module M = M in x;;
|
||||
let open M in x;;
|
||||
let exception E in x;;
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(let_module_expression
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name))))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(let_open_expression
|
||||
(open_module (module_path (module_name)))
|
||||
(value_path (value_name))))
|
||||
(expression_item
|
||||
(let_exception_expression
|
||||
(exception_definition
|
||||
(constructor_declaration (constructor_name)))
|
||||
(value_path (value_name)))))
|
||||
|
||||
===========================
|
||||
Parenthesized expressions
|
||||
===========================
|
||||
|
||||
let x = (x)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(parenthesized_expression (value_path (value_name))))))
|
||||
|
||||
===========================
|
||||
Precedence
|
||||
===========================
|
||||
|
||||
let x = x in if x then x <- x := ! x . x ## x x x lsl x ** x * x mod x + x - x :: x :: x @ x ^ x < x > x & x && x or x || x, x, x; x; x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(let_expression
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name))))
|
||||
(sequence_expression
|
||||
(if_expression
|
||||
(value_path (value_name))
|
||||
(then_clause
|
||||
(set_expression
|
||||
(instance_variable_name)
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(product_expression
|
||||
(product_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(cons_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(infix_expression
|
||||
(application_expression
|
||||
(hash_expression
|
||||
(field_get_expression
|
||||
(prefix_expression
|
||||
(prefix_operator)
|
||||
(value_path (value_name)))
|
||||
(field_path (field_name)))
|
||||
(hash_operator)
|
||||
(value_path (value_name)))
|
||||
(value_path (value_name))
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(value_path (value_name))))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(cons_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name))))
|
||||
(infix_operator)
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(value_path (value_name))))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(value_path (value_name)))
|
||||
(infix_operator)
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(value_path (value_name))))
|
||||
(infix_operator)
|
||||
(infix_expression
|
||||
(value_path (value_name))
|
||||
(infix_operator)
|
||||
(value_path (value_name))))
|
||||
(value_path (value_name)))
|
||||
(value_path (value_name)))))))
|
||||
(sequence_expression
|
||||
(value_path (value_name))
|
||||
(value_path (value_name)))))))
|
||||
@ -0,0 +1,146 @@
|
||||
==========================
|
||||
Module paths
|
||||
==========================
|
||||
|
||||
module M = M
|
||||
module M = M.M
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path
|
||||
(module_path (module_name))
|
||||
(module_name)))))
|
||||
|
||||
============================
|
||||
Structures
|
||||
============================
|
||||
|
||||
module M = struct
|
||||
let x = x
|
||||
end
|
||||
module M = struct ;; end
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(structure
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(value_path (value_name)))))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(structure))))
|
||||
|
||||
============================
|
||||
Module applications
|
||||
============================
|
||||
|
||||
module M = M (M)
|
||||
module M = M (M) (M)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_application
|
||||
(module_path (module_name))
|
||||
(parenthesized_module_expression (module_path (module_name))))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_application
|
||||
(module_application
|
||||
(module_path (module_name))
|
||||
(parenthesized_module_expression (module_path (module_name))))
|
||||
(parenthesized_module_expression (module_path (module_name)))))))
|
||||
|
||||
==========================
|
||||
Typed module expressions
|
||||
==========================
|
||||
|
||||
module M = (M : T)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(typed_module_expression
|
||||
(module_path (module_name))
|
||||
(module_type_path (module_type_name))))))
|
||||
|
||||
=========================
|
||||
Packed modules
|
||||
==========================
|
||||
|
||||
module M = (val m)
|
||||
module M = (val m : T)
|
||||
module M = M (val m)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(packed_module (value_path (value_name)))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(packed_module
|
||||
(value_path (value_name))
|
||||
(module_type_path (module_type_name)))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_application
|
||||
(module_path (module_name))
|
||||
(packed_module (value_path (value_name)))))))
|
||||
|
||||
=========================
|
||||
Functors
|
||||
==========================
|
||||
|
||||
module M = functor (M : T) -> M
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(functor
|
||||
(module_parameter
|
||||
(module_name)
|
||||
(module_type_path (module_type_name)))
|
||||
(module_path (module_name))))))
|
||||
|
||||
==============================
|
||||
Parenthesized module expressions
|
||||
==============================
|
||||
|
||||
module M = (M)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(parenthesized_module_expression (module_path (module_name))))))
|
||||
@ -0,0 +1,98 @@
|
||||
==============================
|
||||
Value definition
|
||||
==============================
|
||||
|
||||
let x = y
|
||||
let ( + ) = x
|
||||
let rec x = y and y = x
|
||||
let x, y = y, x
|
||||
let x : 'a . 'a t = y
|
||||
let f ~x ~l:y ~(x : t) ?(l = y) ?l:((x, y) : t = xy) = x
|
||||
let f (type t) x : t = x
|
||||
let+ x = a and+ y = b
|
||||
let%ext x
|
||||
let* x and* y
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(value_definition
|
||||
(let_binding (value_name) (value_path (value_name))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(parenthesized_operator (infix_operator))
|
||||
(value_path (value_name))))
|
||||
(value_definition
|
||||
(let_binding (value_name) (value_path (value_name)))
|
||||
(let_binding (value_name) (value_path (value_name))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(tuple_pattern (value_name) (value_name))
|
||||
(product_expression (value_path (value_name)) (value_path (value_name)))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(polymorphic_type
|
||||
(type_variable)
|
||||
(constructed_type (type_variable) (type_constructor_path (type_constructor))))
|
||||
(value_path (value_name))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(parameter (value_pattern))
|
||||
(parameter (label_name) (value_pattern))
|
||||
(parameter (value_pattern) (type_constructor_path (type_constructor)))
|
||||
(parameter (value_pattern) (value_path (value_name)))
|
||||
(parameter
|
||||
(label_name)
|
||||
(parenthesized_pattern
|
||||
(tuple_pattern (value_pattern) (value_pattern)))
|
||||
(type_constructor_path (type_constructor))
|
||||
(value_path (value_name)))
|
||||
(value_path (value_name))))
|
||||
(value_definition
|
||||
(let_binding
|
||||
(value_name)
|
||||
(abstract_type (type_constructor))
|
||||
(parameter (value_pattern))
|
||||
(type_constructor_path (type_constructor))
|
||||
(value_path (value_name))))
|
||||
(value_definition
|
||||
(let_operator)
|
||||
(let_binding (value_name) (value_path (value_name)))
|
||||
(and_operator)
|
||||
(let_binding (value_name) (value_path (value_name))))
|
||||
(value_definition (attribute_id) (let_binding (value_name)))
|
||||
(value_definition
|
||||
(let_operator)
|
||||
(let_binding (value_name))
|
||||
(and_operator)
|
||||
(let_binding (value_name))))
|
||||
|
||||
==============================
|
||||
Include
|
||||
==============================
|
||||
|
||||
include M
|
||||
include M.M
|
||||
include M.M.M
|
||||
include M(M)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(include_module (module_path (module_name)))
|
||||
(include_module
|
||||
(module_path
|
||||
(module_path (module_name))
|
||||
(module_name)))
|
||||
(include_module
|
||||
(module_path
|
||||
(module_path
|
||||
(module_path (module_name))
|
||||
(module_name))
|
||||
(module_name)))
|
||||
(include_module
|
||||
(module_application
|
||||
(module_path (module_name))
|
||||
(parenthesized_module_expression (module_path (module_name))))))
|
||||
@ -0,0 +1,199 @@
|
||||
==============================
|
||||
External
|
||||
==============================
|
||||
|
||||
external x : int = "x"
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(external
|
||||
(value_name)
|
||||
(type_constructor_path (type_constructor))
|
||||
(string (string_content))))
|
||||
|
||||
==============================
|
||||
Type definition
|
||||
==============================
|
||||
|
||||
type t
|
||||
type nonrec 'a t = t and ('a, 'b) t = t
|
||||
type t = private t
|
||||
type t = A | B of t | C of t * t | D of {x : t}
|
||||
type _ t =
|
||||
| A : 'a -> 'a t
|
||||
type t = {
|
||||
mutable x : t;
|
||||
}
|
||||
type t = t constraint 'a = t
|
||||
type t = |
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition (type_binding (type_constructor)))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(type_binding
|
||||
(type_variable) (type_variable)
|
||||
(type_constructor)
|
||||
(type_constructor_path (type_constructor))))
|
||||
(type_definition (type_binding (type_constructor) (type_constructor_path (type_constructor))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(variant_declaration
|
||||
(constructor_declaration (constructor_name))
|
||||
(constructor_declaration
|
||||
(constructor_name)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(constructor_declaration
|
||||
(constructor_name)
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))
|
||||
(constructor_declaration
|
||||
(constructor_name)
|
||||
(record_declaration
|
||||
(field_declaration
|
||||
(field_name)
|
||||
(type_constructor_path (type_constructor))))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(variant_declaration
|
||||
(constructor_declaration
|
||||
(constructor_name)
|
||||
(type_variable)
|
||||
(constructed_type (type_variable) (type_constructor_path (type_constructor)))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(record_declaration
|
||||
(field_declaration (field_name) (type_constructor_path (type_constructor))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constraint (type_variable) (type_constructor_path (type_constructor)))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(variant_declaration))))
|
||||
|
||||
==============================
|
||||
Exception definition
|
||||
==============================
|
||||
|
||||
exception E
|
||||
exception E of t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(exception_definition (constructor_declaration (constructor_name)))
|
||||
(exception_definition
|
||||
(constructor_declaration
|
||||
(constructor_name)
|
||||
(type_constructor_path (type_constructor)))))
|
||||
|
||||
==============================
|
||||
Module definition
|
||||
==============================
|
||||
|
||||
module M
|
||||
module M : T
|
||||
module M (M : T) : E
|
||||
module rec M : T and M : T
|
||||
|
||||
module M = M
|
||||
module M : T = M
|
||||
module M (M : T) = M
|
||||
module rec M = N and N = M
|
||||
|
||||
module _ (_ : T) = M
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path (module_type_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_parameter (module_name) (module_type_path (module_type_name)))
|
||||
(module_type_path (module_type_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path (module_type_name)))
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path (module_type_name))))
|
||||
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path (module_type_name))
|
||||
(module_path (module_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_parameter (module_name) (module_type_path (module_type_name)))
|
||||
(module_path (module_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name)))
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_path (module_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_parameter (module_name) (module_type_path (module_type_name)))
|
||||
(module_path (module_name)))))
|
||||
|
||||
==============================
|
||||
Module type definition
|
||||
==============================
|
||||
|
||||
module type T = T
|
||||
module type T := T
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_type_definition
|
||||
(module_type_name)
|
||||
(module_type_path (module_type_name)))
|
||||
(module_type_definition
|
||||
(module_type_name)
|
||||
(module_type_path (module_type_name))))
|
||||
|
||||
==============================
|
||||
Open
|
||||
==============================
|
||||
|
||||
open M
|
||||
open! M
|
||||
open ! M
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(open_module (module_path (module_name)))
|
||||
(open_module (module_path (module_name)))
|
||||
(open_module (module_path (module_name))))
|
||||
@ -0,0 +1,118 @@
|
||||
==============================
|
||||
Module type path
|
||||
==============================
|
||||
|
||||
module M : T
|
||||
module M : M.T
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path (module_type_name))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_path
|
||||
(extended_module_path (module_name))
|
||||
(module_type_name)))))
|
||||
|
||||
==============================
|
||||
Signatures
|
||||
==============================
|
||||
|
||||
module M : sig
|
||||
val x : t
|
||||
end
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(signature
|
||||
(value_specification
|
||||
(value_name)
|
||||
(type_constructor_path (type_constructor)))))))
|
||||
|
||||
==============================
|
||||
Constraints
|
||||
==============================
|
||||
|
||||
module M : T with type t = t and module M := M and module type T = T
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_constraint
|
||||
(module_type_path (module_type_name))
|
||||
(constrain_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))
|
||||
(constrain_module
|
||||
(module_path (module_name))
|
||||
(extended_module_path (module_name)))
|
||||
(constrain_module_type
|
||||
(module_type_path (module_type_name))
|
||||
(module_type_path (module_type_name)))))))
|
||||
|
||||
==============================
|
||||
Module type of
|
||||
==============================
|
||||
|
||||
module M : module type of M
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(module_type_of (module_path (module_name))))))
|
||||
|
||||
==============================
|
||||
Functor types
|
||||
==============================
|
||||
|
||||
module M : functor (M : T) -> T
|
||||
module M : T -> T -> T
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(functor_type
|
||||
(module_parameter
|
||||
(module_name)
|
||||
(module_type_path (module_type_name)))
|
||||
(module_type_path (module_type_name)))))
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(functor_type
|
||||
(module_type_path (module_type_name))
|
||||
(functor_type
|
||||
(module_type_path (module_type_name))
|
||||
(module_type_path (module_type_name)))))))
|
||||
|
||||
==============================
|
||||
Parenthesized module types
|
||||
==============================
|
||||
|
||||
module M : (T)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(module_definition
|
||||
(module_binding
|
||||
(module_name)
|
||||
(parenthesized_module_type (module_type_path (module_type_name))))))
|
||||
@ -0,0 +1,235 @@
|
||||
============================
|
||||
Values
|
||||
============================
|
||||
|
||||
function x -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case (value_pattern) (unit)))))
|
||||
|
||||
============================
|
||||
Constant patterns
|
||||
============================
|
||||
|
||||
function 1 | +1.0 | 'x' | "x" | {|x|} | true | () -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(number)
|
||||
(signed_number))
|
||||
(character (character_content)))
|
||||
(string (string_content)))
|
||||
(quoted_string (quoted_string_content)))
|
||||
(boolean))
|
||||
(unit))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Typed patterns
|
||||
============================
|
||||
|
||||
function (x : t) -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(typed_pattern
|
||||
(value_pattern)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Constructors and tags
|
||||
============================
|
||||
|
||||
function A x | A | `A | `A x -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(constructor_pattern
|
||||
(constructor_path (constructor_name))
|
||||
(value_pattern))
|
||||
(constructor_path (constructor_name)))
|
||||
(tag))
|
||||
(tag_pattern (tag) (value_pattern)))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Polymorphic variant patterns
|
||||
============================
|
||||
|
||||
function #t -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(polymorphic_variant_pattern
|
||||
(type_constructor_path (type_constructor)))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Records, lists and arrays
|
||||
============================
|
||||
|
||||
function {x} | [x] | [|x|] | [|x;y;|] | x :: xs -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(or_pattern
|
||||
(record_pattern
|
||||
(field_pattern (field_path (field_name))))
|
||||
(list_pattern (value_pattern)))
|
||||
(array_pattern (value_pattern)))
|
||||
(array_pattern (value_pattern) (value_pattern)))
|
||||
(cons_pattern (value_pattern) (value_pattern)))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Local open patterns
|
||||
============================
|
||||
|
||||
function M.(A x) | M.[x] -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(or_pattern
|
||||
(local_open_pattern
|
||||
(module_path (module_name))
|
||||
(constructor_pattern
|
||||
(constructor_path (constructor_name))
|
||||
(value_pattern)))
|
||||
(local_open_pattern
|
||||
(module_path (module_name))
|
||||
(list_pattern (value_pattern))))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Package patterns
|
||||
============================
|
||||
|
||||
function (module M) -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(package_pattern (module_name))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Alias patterns
|
||||
============================
|
||||
|
||||
function x as t -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(alias_pattern (value_pattern) (value_pattern))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Tuple patterns
|
||||
============================
|
||||
|
||||
function x, x, x -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(tuple_pattern
|
||||
(tuple_pattern
|
||||
(value_pattern)
|
||||
(value_pattern))
|
||||
(value_pattern))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Range patterns
|
||||
============================
|
||||
|
||||
function 'a' .. 'z' -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(range_pattern (character (character_content)) (character (character_content)))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Lazy patterns
|
||||
============================
|
||||
|
||||
function lazy x -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case (lazy_pattern (value_pattern))
|
||||
(unit)))))
|
||||
|
||||
============================
|
||||
Parenthesized patterns
|
||||
============================
|
||||
|
||||
function (x) -> ()
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(expression_item
|
||||
(function_expression
|
||||
(match_case
|
||||
(parenthesized_pattern (value_pattern))
|
||||
(unit)))))
|
||||
@ -0,0 +1,31 @@
|
||||
==============================
|
||||
Toplevel directives
|
||||
==============================
|
||||
|
||||
#help
|
||||
#use "file.ml"
|
||||
#show_module M
|
||||
#show x
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(toplevel_directive (directive))
|
||||
(toplevel_directive (directive) (string (string_content)))
|
||||
(toplevel_directive (directive) (module_path (module_name)))
|
||||
(toplevel_directive
|
||||
(directive)
|
||||
(value_path (value_name))))
|
||||
|
||||
==============================
|
||||
Line number directives
|
||||
==============================
|
||||
|
||||
# 1 "test.ml"
|
||||
# 2 "test.ml" (* comment *)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(line_number_directive)
|
||||
(line_number_directive))
|
||||
@ -0,0 +1,244 @@
|
||||
===========================
|
||||
Type variables
|
||||
===========================
|
||||
|
||||
type 'a t = 'a
|
||||
type ('a, 'b) t = 'a
|
||||
type +'a t = 'a
|
||||
type !+'a t = 'a
|
||||
type +!'a t = 'a
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_variable)))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_variable)))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_variable)))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_variable)))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_variable)
|
||||
(type_constructor)
|
||||
(type_variable))))
|
||||
|
||||
===========================
|
||||
Type constructors
|
||||
===========================
|
||||
|
||||
type t = t
|
||||
type t = M.t
|
||||
type t = M(M).t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(type_constructor_path (type_constructor))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(type_constructor_path
|
||||
(extended_module_path (module_name))
|
||||
(type_constructor))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(type_constructor_path
|
||||
(extended_module_path
|
||||
(extended_module_path (module_name))
|
||||
(extended_module_path (module_name)))
|
||||
(type_constructor)))))
|
||||
|
||||
===========================
|
||||
Constructed types
|
||||
===========================
|
||||
|
||||
type t = int list
|
||||
type t = int list list
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(constructed_type
|
||||
(type_constructor_path (type_constructor)) (type_constructor_path (type_constructor)))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(constructed_type
|
||||
(constructed_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))
|
||||
(type_constructor_path (type_constructor))))))
|
||||
|
||||
===========================
|
||||
Polymorphic variant types
|
||||
===========================
|
||||
|
||||
type t = [`A | `B of t]
|
||||
type t = [>
|
||||
| t
|
||||
| `C
|
||||
]
|
||||
type t = [< `A of t & t ]
|
||||
type t = [< `A > `A ]
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(polymorphic_variant_type
|
||||
(tag_specification (tag))
|
||||
(tag_specification
|
||||
(tag)
|
||||
(type_constructor_path (type_constructor))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(polymorphic_variant_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(tag_specification (tag)))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(polymorphic_variant_type
|
||||
(tag_specification
|
||||
(tag)
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(polymorphic_variant_type
|
||||
(tag_specification (tag))
|
||||
(tag)))))
|
||||
|
||||
===========================
|
||||
Package types
|
||||
===========================
|
||||
|
||||
type t = (module T)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(package_type
|
||||
(module_type_path (module_type_name))))))
|
||||
|
||||
===========================
|
||||
Function types
|
||||
===========================
|
||||
|
||||
type t = t -> t
|
||||
type t = t -> t -> t
|
||||
type t = l:t -> ?l:t -> t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(function_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(function_type
|
||||
(type_constructor_path (type_constructor)) (function_type
|
||||
(type_constructor_path (type_constructor)) (type_constructor_path (type_constructor))))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(function_type
|
||||
(typed_label
|
||||
(label_name)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(function_type
|
||||
(typed_label
|
||||
(label_name)
|
||||
(type_constructor_path (type_constructor)))
|
||||
(type_constructor_path (type_constructor)))))))
|
||||
|
||||
===========================
|
||||
Tuple types
|
||||
===========================
|
||||
|
||||
type t = t * t
|
||||
type t = t * t * t
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(tuple_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))))
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(tuple_type
|
||||
(tuple_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_constructor_path (type_constructor)))
|
||||
(type_constructor_path (type_constructor))))))
|
||||
|
||||
===========================
|
||||
Aliased types
|
||||
===========================
|
||||
|
||||
type t = t as 't
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(aliased_type
|
||||
(type_constructor_path (type_constructor))
|
||||
(type_variable)))))
|
||||
|
||||
===========================
|
||||
Parenthesized types
|
||||
===========================
|
||||
|
||||
type t = (t)
|
||||
|
||||
---
|
||||
|
||||
(compilation_unit
|
||||
(type_definition
|
||||
(type_binding
|
||||
(type_constructor)
|
||||
(parenthesized_type
|
||||
(type_constructor_path (type_constructor))))))
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
||||
{
|
||||
"main": "../bindings/node/ocaml"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
#include "../../common/scanner.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void *tree_sitter_ocaml_external_scanner_create() {
|
||||
return new Scanner();
|
||||
}
|
||||
|
||||
void tree_sitter_ocaml_external_scanner_destroy(void *payload) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
delete scanner;
|
||||
}
|
||||
|
||||
unsigned tree_sitter_ocaml_external_scanner_serialize(void *payload, char *buffer) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->serialize(buffer);
|
||||
}
|
||||
|
||||
void tree_sitter_ocaml_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
scanner->deserialize(buffer, length);
|
||||
}
|
||||
|
||||
bool tree_sitter_ocaml_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
||||
Scanner *scanner = static_cast<Scanner *>(payload);
|
||||
return scanner->scan(lexer, valid_symbols);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,223 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
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 TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "tree-sitter-ocaml",
|
||||
"version": "0.19.0",
|
||||
"description": "OCaml grammar for tree-sitter",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"ocaml"
|
||||
],
|
||||
"author": "Max Brunsfeld",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.19.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build-ocaml && npm run build-interface",
|
||||
"build-ocaml": "cd ocaml && tree-sitter generate",
|
||||
"build-interface": "cd interface && tree-sitter generate",
|
||||
"test": "npm run test-ocaml && npm run test-interface && npm run test-highlight && script/parse-examples",
|
||||
"test-ocaml": "cd ocaml && tree-sitter test",
|
||||
"test-interface": "cd interface && tree-sitter test",
|
||||
"test-highlight": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.ocaml",
|
||||
"file-types": [
|
||||
"ml"
|
||||
],
|
||||
"first-line-regex": "",
|
||||
"path": "ocaml",
|
||||
"injection-regex": "^(ocaml|ml)$"
|
||||
},
|
||||
{
|
||||
"scope": "source.ocaml.interface",
|
||||
"file-types": [
|
||||
"mli"
|
||||
],
|
||||
"path": "interface",
|
||||
"injection-regex": "^ocaml_interface$"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,147 @@
|
||||
; Modules
|
||||
;--------
|
||||
|
||||
[(module_name) (module_type_name)] @constructor
|
||||
|
||||
; Types
|
||||
;------
|
||||
|
||||
(
|
||||
(type_constructor) @type.builtin
|
||||
(#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$")
|
||||
)
|
||||
|
||||
[(class_name) (class_type_name) (type_constructor)] @type
|
||||
|
||||
[(constructor_name) (tag)] @tag
|
||||
|
||||
; Functions
|
||||
;----------
|
||||
|
||||
(let_binding
|
||||
pattern: (value_name) @function
|
||||
(parameter))
|
||||
|
||||
(let_binding
|
||||
pattern: (value_name) @function
|
||||
body: [(fun_expression) (function_expression)])
|
||||
|
||||
(value_specification (value_name) @function)
|
||||
|
||||
(external (value_name) @function)
|
||||
|
||||
(method_name) @function.method
|
||||
|
||||
; Application
|
||||
;------------
|
||||
|
||||
(
|
||||
(value_name) @function.builtin
|
||||
(#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$")
|
||||
)
|
||||
|
||||
(infix_expression
|
||||
left: (value_path (value_name) @function)
|
||||
(infix_operator) @operator
|
||||
(#eq? @operator "@@"))
|
||||
|
||||
(infix_expression
|
||||
(infix_operator) @operator
|
||||
right: (value_path (value_name) @function)
|
||||
(#eq? @operator "|>"))
|
||||
|
||||
(application_expression
|
||||
function: (value_path (value_name) @function))
|
||||
|
||||
; Variables
|
||||
;----------
|
||||
|
||||
[(value_name) (type_variable)] @variable
|
||||
|
||||
(value_pattern) @variable.parameter
|
||||
|
||||
; Properties
|
||||
;-----------
|
||||
|
||||
[(label_name) (field_name) (instance_variable_name)] @property
|
||||
|
||||
; Constants
|
||||
;----------
|
||||
|
||||
(boolean) @constant
|
||||
|
||||
[(number) (signed_number)] @number
|
||||
|
||||
[(string) (character)] @string
|
||||
|
||||
(quoted_string "{" @string "}" @string) @string
|
||||
|
||||
(escape_sequence) @escape
|
||||
|
||||
(conversion_specification) @string.special
|
||||
|
||||
; Operators
|
||||
;----------
|
||||
|
||||
(match_expression (match_operator) @keyword)
|
||||
|
||||
(value_definition [(let_operator) (and_operator)] @keyword)
|
||||
|
||||
[
|
||||
(prefix_operator)
|
||||
(sign_operator)
|
||||
(infix_operator)
|
||||
(hash_operator)
|
||||
(indexing_operator)
|
||||
(let_operator)
|
||||
(and_operator)
|
||||
(match_operator)
|
||||
] @operator
|
||||
|
||||
(infix_operator ["&" "+" "-" "=" ">" "|" "%"] @operator)
|
||||
(signed_number ["+" "-"] @operator)
|
||||
|
||||
["*" "#" "::" "<-"] @operator
|
||||
|
||||
; Keywords
|
||||
;---------
|
||||
|
||||
[
|
||||
"and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else"
|
||||
"end" "exception" "external" "for" "fun" "function" "functor" "if" "in"
|
||||
"include" "inherit" "initializer" "lazy" "let" "match" "method" "module"
|
||||
"mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct"
|
||||
"then" "to" "try" "type" "val" "virtual" "when" "while" "with"
|
||||
] @keyword
|
||||
|
||||
; Punctuation
|
||||
;------------
|
||||
|
||||
(attribute ["[@" "]"] @punctuation.special)
|
||||
(item_attribute ["[@@" "]"] @punctuation.special)
|
||||
(floating_attribute ["[@@@" "]"] @punctuation.special)
|
||||
(extension ["[%" "]"] @punctuation.special)
|
||||
(item_extension ["[%%" "]"] @punctuation.special)
|
||||
(quoted_extension ["{%" "}"] @punctuation.special)
|
||||
(quoted_item_extension ["{%%" "}"] @punctuation.special)
|
||||
|
||||
"%" @punctuation.special
|
||||
|
||||
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
|
||||
|
||||
(object_type ["<" ">"] @punctuation.bracket)
|
||||
|
||||
[
|
||||
"," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&"
|
||||
"->" ";;" ":>" "+=" ":=" ".."
|
||||
] @punctuation.delimiter
|
||||
|
||||
; Attributes
|
||||
;-----------
|
||||
|
||||
(attribute_id) @attribute
|
||||
|
||||
; Comments
|
||||
;---------
|
||||
|
||||
[(comment) (line_number_directive) (directive) (shebang)] @comment
|
||||
@ -0,0 +1,24 @@
|
||||
; Scopes
|
||||
;-------
|
||||
|
||||
[
|
||||
(let_binding)
|
||||
(class_binding)
|
||||
(class_function)
|
||||
(method_definition)
|
||||
(fun_expression)
|
||||
(object_expression)
|
||||
(for_expression)
|
||||
(match_case)
|
||||
(attribute_payload)
|
||||
] @local.scope
|
||||
|
||||
; Definitions
|
||||
;------------
|
||||
|
||||
(value_pattern) @local.definition
|
||||
|
||||
; References
|
||||
;-----------
|
||||
|
||||
(value_path . (value_name) @local.reference)
|
||||
@ -0,0 +1,116 @@
|
||||
; Modules
|
||||
;--------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(module_definition (module_binding (module_name) @name) @definition.module)
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
(module_path (module_name) @name) @reference.module
|
||||
|
||||
; Modules types
|
||||
;--------------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(module_type_definition (module_type_name) @name) @definition.interface
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
(module_type_path (module_type_name) @name) @reference.implementation
|
||||
|
||||
; Functions
|
||||
;----------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(value_definition
|
||||
[
|
||||
(let_binding
|
||||
pattern: (value_name) @name
|
||||
(parameter))
|
||||
(let_binding
|
||||
pattern: (value_name) @name
|
||||
body: [(fun_expression) (function_expression)])
|
||||
] @definition.function
|
||||
)
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(external (value_name) @name) @definition.function
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
(application_expression
|
||||
function: (value_path (value_name) @name)) @reference.call
|
||||
|
||||
(infix_expression
|
||||
left: (value_path (value_name) @name)
|
||||
(infix_operator) @reference.call
|
||||
(#eq? @reference.call "@@"))
|
||||
|
||||
(infix_expression
|
||||
(infix_operator) @reference.call
|
||||
right: (value_path (value_name) @name)
|
||||
(#eq? @reference.call "|>"))
|
||||
|
||||
; Operator
|
||||
;---------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(value_definition
|
||||
(let_binding
|
||||
pattern: (parenthesized_operator [
|
||||
(prefix_operator)
|
||||
(infix_operator)
|
||||
(hash_operator)
|
||||
(indexing_operator)
|
||||
(let_operator)
|
||||
(and_operator)
|
||||
(match_operator)
|
||||
] @name)) @definition.function)
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
[
|
||||
(prefix_operator)
|
||||
(sign_operator)
|
||||
(infix_operator)
|
||||
(hash_operator)
|
||||
(indexing_operator)
|
||||
(let_operator)
|
||||
(and_operator)
|
||||
(match_operator)
|
||||
] @name @reference.call
|
||||
|
||||
; Classes
|
||||
;--------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
[
|
||||
(class_definition (class_binding (class_name) @name) @definition.class)
|
||||
(class_type_definition (class_type_binding (class_type_name) @name) @definition.class)
|
||||
]
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
[
|
||||
(class_path (class_name) @name)
|
||||
(class_type_path (class_type_name) @name)
|
||||
] @reference.class
|
||||
|
||||
; Methods
|
||||
;--------
|
||||
|
||||
(
|
||||
(comment)? @doc .
|
||||
(method_definition (method_name) @name) @definition.method
|
||||
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||
)
|
||||
|
||||
(method_invocation (method_name) @name) @reference.call
|
||||
@ -0,0 +1,50 @@
|
||||
examples/lablgtk/applications/osiris/osiris.ml
|
||||
examples/lablgtk/examples/csview.ml
|
||||
examples/lablgtk/tools/introspection/stubs/stubs_Atk.ml
|
||||
examples/lablgtk/tools/introspection/stubs/stubs_Pango.ml
|
||||
examples/lwt/src/react/lwt_react.cppo.ml
|
||||
examples/lwt/src/unix/lwt_unix.cppo.ml
|
||||
examples/lwt/src/unix/lwt_unix.cppo.mli
|
||||
examples/lwt/test/unix/test_lwt_unix.cppo.ml
|
||||
examples/merlin/tests/test-dirs/completion/infix.t/infix.ml
|
||||
examples/merlin/tests/test-dirs/completion/parenthesize.t/parenthesize.ml
|
||||
examples/merlin/tests/test-dirs/errors/typing-after-parsing.t/test.ml
|
||||
examples/merlin/tests/test-dirs/locate/context-detection/cd-label.t/label.ml
|
||||
examples/ocaml/stdlib/templates/float.template.mli
|
||||
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/parsing/anonymous_class_parameter.ml
|
||||
examples/ocaml/testsuite/tests/parsing/arrow_ambiguity.ml
|
||||
examples/ocaml/testsuite/tests/parsing/constructor_declarations.ml
|
||||
examples/ocaml/testsuite/tests/parsing/docstrings.ml
|
||||
examples/ocaml/testsuite/tests/parsing/pr6604_2.ml
|
||||
examples/ocaml/testsuite/tests/parsing/pr6604.ml
|
||||
examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting_use2.ml
|
||||
examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting_use3.ml
|
||||
examples/ocaml/testsuite/tests/tool-toplevel/error_highlighting.ml
|
||||
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/opam/src/core/opamCompat.ml
|
||||
examples/opam/src/core/opamCompat.mli
|
||||
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
function clone_repo {
|
||||
owner=$1
|
||||
name=$2
|
||||
sha=$3
|
||||
|
||||
path=examples/$name
|
||||
if [ ! -d "$path" ]; then
|
||||
echo "Cloning $owner/$name"
|
||||
git clone "https://github.com/$owner/$name" "$path"
|
||||
fi
|
||||
|
||||
pushd "$path" > /dev/null
|
||||
if [ "$(git rev-parse HEAD)" != "$sha" ]; then
|
||||
echo "Updating $owner/$name to $sha"
|
||||
git fetch
|
||||
git reset --hard $sha
|
||||
fi
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
clone_repo 0install 0install 5555f2e456c59a1e640cc096781a832956045d28
|
||||
clone_repo BinaryAnalysisPlatform bap 40efc122b6fc3bb9de45aa482372437cd70d731d
|
||||
clone_repo dbuenzli cmdliner db4d02a9eb47b5c43127a67cb121004b03ea3719
|
||||
clone_repo facebook flow 824fc9779b90e1ec4cdb1b540917968119a561f6
|
||||
clone_repo facebook pyre-check 71baba79031d6a6b5447174faebd625029d72792
|
||||
clone_repo garrigue lablgtk 034d4fbb1f09431048dd4231bf2ba9c69db59e6a
|
||||
clone_repo janestreet base 7bc01b2b9895dd6638702437605c53cd255096c4
|
||||
clone_repo mirage ocaml-cohttp c3a59cd11fae2ccf084fbfc3eb02b75773511d25
|
||||
clone_repo ocaml dune a8c6ed8bb27af690955e51eabbef0382b7e2d41e
|
||||
clone_repo ocaml merlin 2a0dd5c16178efcc4b8132e3c3b3c2a6cc7b13ea
|
||||
clone_repo ocaml ocaml 2ea972b151ae16261a701b63177c5592df45425a
|
||||
clone_repo ocaml opam 5b5be7b96ac4150ba1471c130d697e2e992763e6
|
||||
clone_repo ocsigen js_of_ocaml c97f2543ff7bfa6c8fe683cca7beec884b38f918
|
||||
clone_repo ocsigen lwt c5f895e35a38df2d06f19fd23bf553129b9e95b3
|
||||
clone_repo owlbarn owl b8110574cb9d9b9e9d4a9bdf2743b86ab39549e3
|
||||
|
||||
known_failures="$(cat script/known_failures.txt)"
|
||||
|
||||
tree-sitter parse -q \
|
||||
'examples/**/*.ml' \
|
||||
'examples/**/*.mli' \
|
||||
$(for failure in $known_failures; do echo "!${failure}"; done)
|
||||
|
||||
example_count=$(find examples -name '*.ml' -o -name '*.mli' | wc -l)
|
||||
failure_count=$(wc -w <<< "$known_failures")
|
||||
success_count=$(( $example_count - $failure_count ))
|
||||
success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
|
||||
|
||||
printf \
|
||||
"Successfully parsed %d of %d example files (%.1f%%)\n" \
|
||||
$success_count $example_count $success_percent
|
||||
@ -0,0 +1,4 @@
|
||||
[@@@id payload]
|
||||
(* <- punctuation.special *)
|
||||
(* ^ attribute *)
|
||||
(* ^ punctuation.special *)
|
||||
@ -0,0 +1,14 @@
|
||||
let t = true
|
||||
(* ^ constant *)
|
||||
|
||||
let c = 'c'
|
||||
(* ^ string *)
|
||||
|
||||
let () = Printf.printf "string\n%d" 5
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ string *)
|
||||
(* ^ escape *)
|
||||
(* ^ string.special *)
|
||||
(* ^ number *)
|
||||
let x = {id|string|id}
|
||||
(* ^ string *)
|
||||
@ -0,0 +1,32 @@
|
||||
let f x = failwith "not_implemented"
|
||||
(* ^ function *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ function.builtin *)
|
||||
let f = fun x -> x
|
||||
(* ^ function *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
|
||||
let f = function Some x -> true | None -> false
|
||||
(* ^ function *)
|
||||
|
||||
module type T = sig
|
||||
val f : int -> int
|
||||
(* ^ function *)
|
||||
end
|
||||
|
||||
external f : int -> int = "f"
|
||||
(* ^ function *)
|
||||
|
||||
let x = f 0
|
||||
(* ^ variable *)
|
||||
(* ^ function *)
|
||||
|
||||
let x = f @@ x |> f
|
||||
(* ^ variable *)
|
||||
(* ^ function *)
|
||||
(* ^ variable *)
|
||||
(* ^ function *)
|
||||
|
||||
let f ~l:x = 0
|
||||
(* ^ property *)
|
||||
@ -0,0 +1,47 @@
|
||||
let f x ({a = y} as r) (Some z) =
|
||||
(* ^ function *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ property *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
(x, a, y, r, z)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
|
||||
let f = fun x -> (x, y)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable *)
|
||||
|
||||
let _ =
|
||||
match o with
|
||||
| Some x -> x
|
||||
(* ^ variable.parameter *)
|
||||
| None -> y
|
||||
(* ^ variable *)
|
||||
|
||||
let () =
|
||||
for x = 1 to n do
|
||||
ignore x;
|
||||
(* ^ variable.parameter *)
|
||||
ignore n;
|
||||
(* ^ variable *)
|
||||
done
|
||||
|
||||
let (x, y) = (x, y)
|
||||
(* ^ variable *)
|
||||
(* ^ variable *)
|
||||
(* ^ variable *)
|
||||
(* ^ variable *)
|
||||
|
||||
let {a = x} = assert false
|
||||
(* ^ variable *)
|
||||
|
||||
let f x = (M.x, x)
|
||||
(* ^ variable.parameter *)
|
||||
(* ^ variable *)
|
||||
(* ^ variable.parameter *)
|
||||
@ -0,0 +1,38 @@
|
||||
module type T = sig
|
||||
(* <- keyword *)
|
||||
(* ^ keyword *)
|
||||
(* ^ constructor *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
(* ^ keyword *)
|
||||
val x : int
|
||||
end
|
||||
(* <- keyword *)
|
||||
|
||||
module M : T = struct
|
||||
(* <- keyword *)
|
||||
(* ^ constructor *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
(* ^ constructor *)
|
||||
let x = 0
|
||||
end
|
||||
|
||||
module F (M : T) = struct
|
||||
(* ^ constructor *)
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ constructor *)
|
||||
(* ^ constructor *)
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ keyword *)
|
||||
include M
|
||||
(* <- keyword *)
|
||||
(* ^ constructor *)
|
||||
end
|
||||
|
||||
module N = F (M)
|
||||
(* ^ constructor *)
|
||||
(* ^ constructor *)
|
||||
(* ^ constructor *)
|
||||
|
||||
let x = N.x
|
||||
(* ^ constructor *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
@ -0,0 +1,19 @@
|
||||
let ( + ) = ( * )
|
||||
(* ^ operator *)
|
||||
(* ^ operator *)
|
||||
let x = (1 + 2) :: 3
|
||||
(* ^ operator *)
|
||||
(* ^ operator *)
|
||||
|
||||
let f = function +1 -> true | -1 -> true | _ -> false
|
||||
(* ^ operator *)
|
||||
(* ^ operator *)
|
||||
|
||||
let ( let* ) x f = f x
|
||||
(* ^ operator *)
|
||||
|
||||
let () =
|
||||
let* x = 0 and* y = 1 in
|
||||
(* <- keyword *)
|
||||
(* ^ keyword *)
|
||||
ignore x
|
||||
@ -0,0 +1,33 @@
|
||||
type ('a, 'b) either = Left of 'a | Right of 'b
|
||||
(* <- keyword *) (* ^ tag *)
|
||||
(* ^ variable *) (* ^ keyword *)
|
||||
(* ^ variable *) (* ^ variable *)
|
||||
(* ^ type *) (* ^ punctuation.delimiter *)
|
||||
|
||||
let x : (bool, int) either = Left true
|
||||
(* ^ type.builtin *)
|
||||
(* ^ type.builtin *)
|
||||
(* ^ type *)
|
||||
(* ^ tag *)
|
||||
|
||||
|
||||
type ('a, 'b) either' = [`Left of 'a | `Right of 'b]
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ tag *) (* ^ tag *)
|
||||
|
||||
type pos = {x : int; y : int}
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ property *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
(* ^ property *)
|
||||
(* ^ punctuation.bracket *)
|
||||
|
||||
type x = < x : int >
|
||||
(* ^ punctuation.bracket *)
|
||||
(* ^ punctuation.bracket *)
|
||||
|
||||
type (-'a, +'b) func = 'a -> 'b
|
||||
(* ^ punctuation.delimiter *)
|
||||
(* ^ punctuation.delimiter *)
|
||||
Loading…
Reference in New Issue