tree-sitter-php

    PHP grammar for tree-sitter (tree-sitter/tree-sitter-php v0.24.2), for the MoonBit port of Tree-sitter (moonbit-community/treesitter).

    tree-sitter
    parser
    grammar
    php
    php_only
    Download zip
    Version
    0.24.2
    License
    MIT
    Last updated
    21 days ago
    Downloads
    23

    #tree-sitter-php for MoonBit

    PHP grammar for tree-sitter.

    This module packages tree-sitter/tree-sitter-php v0.24.2 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_php() -> @treesitter.LanguageLANGUAGE_PHP
    language_php_only() -> @treesitter.LanguageLANGUAGE_PHP_ONLY
    php_node_types : StringPHP_NODE_TYPES (php/src/node-types.json)
    php_only_node_types : StringPHP_ONLY_NODE_TYPES (php_only/src/node-types.json)
    highlights_query : StringHIGHLIGHTS_QUERY (queries/highlights.scm)
    injections_query : StringINJECTIONS_QUERY (queries/injections.scm)
    tags_query : StringTAGS_QUERY (queries/tags.scm)

    #Usage

    moon add moonbit-community/tree-sitter-php

    In moon.pkg:

    import { "moonbit-community/treesitter", "moonbit-community/tree-sitter-php" @tree_sitter_php, }

    ///|
    test "parse php" {
    let language = @tree_sitter_php.language_php()
    let parser = @treesitter.Parser::new()
    parser.set_language(language)
    let source =
    #|<?php
    #|define('self', 'value');
    #|var_dump(self);
    #|
    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-php, in LICENSE.

    highlights_query

    let highlights_query : String

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

    injections_query

    let injections_query : String

    The content of queries/injections.scm (INJECTIONS_QUERY in the Rust binding).

    language_php

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

    language_php_only

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

    php_node_types

    let php_node_types : String

    The content of php/src/node-types.json (PHP_NODE_TYPES in the Rust binding).

    php_only_node_types

    let php_only_node_types : String

    The content of php_only/src/node-types.json (PHP_ONLY_NODE_TYPES in the Rust binding).

    tags_query

    let tags_query : String

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