tree-sitter-ocaml

    OCaml grammar for tree-sitter (tree-sitter/tree-sitter-ocaml v0.26.0), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).

    tree-sitter
    parser
    grammar
    ocaml
    ocaml_interface
    ocaml_type
    Download zip
    Version
    0.26.0
    License
    MIT
    Last updated
    21 days ago
    Downloads
    23

    #tree-sitter-ocaml for MoonBit

    OCaml grammar for tree-sitter.

    This module packages tree-sitter/tree-sitter-ocaml v0.26.0 for moonbit-community/treesitter, the pure MoonBit port of Tree-sitter. The parse tables are generated from the grammar's src/grammar.json by the port's generator, which produces the same tables as tree-sitter generate 0.28.0. External scanners come from @scanners.scanner_for in moonbit-community/treesitter/scanners, the MoonBit ports of the C scanners.

    #API

    The package mirrors the grammar's Rust binding (bindings/rust/lib.rs):

    MoonBitRust
    language_ocaml() -> @treesitter.LanguageLANGUAGE_OCAML
    language_ocaml_interface() -> @treesitter.LanguageLANGUAGE_OCAML_INTERFACE
    language_ocaml_type() -> @treesitter.LanguageLANGUAGE_OCAML_TYPE
    ocaml_node_types : StringOCAML_NODE_TYPES (grammars/ocaml/src/node-types.json)
    interface_node_types : StringINTERFACE_NODE_TYPES (grammars/interface/src/node-types.json)
    type_node_types : StringTYPE_NODE_TYPES (grammars/type/src/node-types.json)
    highlights_query : StringHIGHLIGHTS_QUERY (queries/highlights.scm)
    locals_query : StringLOCALS_QUERY (queries/locals.scm)
    tags_query : StringTAGS_QUERY (queries/tags.scm)

    #Usage

    moon add moonbit-community/tree-sitter-ocaml

    In moon.pkg:

    import { "moonbit-community/treesitter", "moonbit-community/tree-sitter-ocaml" @tree_sitter_ocaml, }

    ///|
    test "parse ocaml" {
    let language = @tree_sitter_ocaml.language_ocaml()
    let parser = @treesitter.Parser::new()
    parser.set_language(language)
    let source =
    #|[@@@id]
    #|[@@@I.D]
    #|[@@@id let x = x]
    #|[@@@id:]
    #|[@@@id : t]
    #|[@@@id : type t type t]
    #|[@@@id ? A x]
    #|
    guard parser.parse(@utf8.encode(source)) is Some(tree) else {
    fail("parse failed")
    }
    let root = tree.root_node()
    assert_false(root.has_error())
    assert_false(root.to_sexp().contains("ERROR"))
    }

    #License

    The grammar and the files copied from it (src/grammar.json, queries, test corpus) are under the license of tree-sitter/tree-sitter-ocaml, in LICENSE.

    highlights_query

    let highlights_query : String

    The content of queries/highlights.scm (HIGHLIGHTS_QUERY in the Rust binding).

    interface_node_types

    let interface_node_types : String

    The content of grammars/interface/src/node-types.json (INTERFACE_NODE_TYPES in the Rust binding).

    language_ocaml

    The tree-sitter language for ocaml (LANGUAGE_OCAML in the Rust binding), generated from grammars/ocaml/src/grammar.json. Its external scanner is @scanners.scanner_for("ocaml"); without one (a scanner not ported yet) the language is not parseable (@treesitter.Language::is_parseable).

    language_ocaml_interface

    fn language_ocaml_interface() ->
    Language

    The tree-sitter language for ocaml_interface (LANGUAGE_OCAML_INTERFACE in the Rust binding), generated from grammars/interface/src/grammar.json. Its external scanner is @scanners.scanner_for("ocaml_interface"); without one (a scanner not ported yet) the language is not parseable (@treesitter.Language::is_parseable).

    language_ocaml_type

    The tree-sitter language for ocaml_type (LANGUAGE_OCAML_TYPE in the Rust binding), generated from grammars/type/src/grammar.json. Its external scanner is @scanners.scanner_for("ocaml_type"); without one (a scanner not ported yet) the language is not parseable (@treesitter.Language::is_parseable).

    locals_query

    let locals_query : String

    The content of queries/locals.scm (LOCALS_QUERY in the Rust binding).

    ocaml_node_types

    let ocaml_node_types : String

    The content of grammars/ocaml/src/node-types.json (OCAML_NODE_TYPES in the Rust binding).

    tags_query

    let tags_query : String

    The content of queries/tags.scm (TAGS_QUERY in the Rust binding).

    type_node_types

    let type_node_types : String

    The content of grammars/type/src/node-types.json (TYPE_NODE_TYPES in the Rust binding).