Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PHP language #52

Merged
merged 42 commits into from
Apr 1, 2024
Merged

feat: add PHP language #52

merged 42 commits into from
Apr 1, 2024

Conversation

urbit-pilled
Copy link
Contributor

@urbit-pilled urbit-pilled commented Mar 22, 2024

Adds PHP as a target language.
/claim #48

Summary by CodeRabbit

  • New Features
    • Introduced comprehensive support for PHP language parsing and syntax highlighting.
    • Added PHP as a target language for pattern matching and language-specific handling.
    • Implemented functionality for dynamic snippet adjustments and pattern matching enhancements.
  • Enhancements
    • Updated project structure for adding new language implementations.
    • Improved test coverage for PHP language pattern matching.
  • Documentation
    • Updated CONTRIBUTING.md with new instructions for language implementation location.
  • Bug Fixes
    • Fixed an issue with dynamic snippet replacement logic.
  • Chores
    • Added a submodule for tree-sitter-php to improve PHP language support.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2024

Walkthrough

The project has been updated to include comprehensive support for the PHP language. This encompasses modifications across various components, including the addition of PHP as a submodule, updates in pattern matching and snippet handling, the introduction of new tests for PHP, and the integration of PHP language specifics in grammar and syntax highlighting. These changes collectively enable the parsing, syntax highlighting, and pattern matching for PHP code, addressing a significant enhancement for the project.

Changes

Files Summary
.gitmodules, crates/.../lib.rs, crates/.../language.rs, crates/.../patterns_directory.rs, crates/wasm-bindings/.../match_pattern.rs, resources/edit_grammars.mjs, resources/language-metavariables/tree-sitter-php/* Added comprehensive support for PHP language, including submodule declaration, pattern matching logic, language support modules, and PHP grammar and syntax highlighting.
CONTRIBUTING.md Updated project structure location for new language implementations.
crates/core/src/pattern/... (dynamic_snippet.rs, patterns.rs, variable.rs, code_snippet.rs) Enhanced pattern matching capabilities, including snippet handling and variable naming conventions.
crates/core/src/test.rs Introduced new PHP language pattern matching tests and updated existing tests.
crates/language/src/target_language.rs, crates/lsp/src/language.rs Added Php as a target language in various enums and implementations.

Possibly related issues

  • Issue PHP language support #48 (PHP language support): The comprehensive addition of PHP language support, including grammar, pattern matching, and tests, directly addresses the objectives of adding PHP as a supported language, meeting the acceptance criteria outlined in the issue.

Poem

In the codebase, deep and wide, 🐇
A new language, now resides.
PHP joins with grace and pride,
Through parsers, patterns, side by side.
A rabbit worked, through day and night,
To make the code both swift and bright.
🎉 Celebrate, for it's a sight,
PHP, in the spotlight.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@@ -651,6 +673,7 @@ impl TargetLanguage {
| TargetLanguage::Rust(_)
| TargetLanguage::Solidity(_)
| TargetLanguage::Tsx(_)
| TargetLanguage::Php(_)
| TargetLanguage::TypeScript(_) => format!("// {}\n", text),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be updated to use the comment_prefix method from the Language trait instead of redefining it here.

@urbit-pilled
Copy link
Contributor Author

urbit-pilled commented Mar 22, 2024

Php variables and Grit metavariables both start with $
what do you think we should do to differentiate the syntax? @morgante

Update: looks like you use µ internally for the metavariable prefix.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't update this submodule as part of this pr.

Copy link
Contributor

@ilevyor ilevyor left a comment

Choose a reason for hiding this comment

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

overall looks pretty good, please search the codebase for toml (or any other language we support) and make sure that you've added php everywhere that toml is found. unfortunately we didn't do a very good job encapsulating the addition of a language to a single place.

crates/language/src/language.rs Outdated Show resolved Hide resolved
crates/core/src/test.rs Outdated Show resolved Hide resolved
crates/core/src/test.rs Show resolved Hide resolved
crates/language/src/php.rs Outdated Show resolved Hide resolved
crates/core/src/test.rs Outdated Show resolved Hide resolved
@urbit-pilled urbit-pilled marked this pull request as ready for review March 25, 2024 22:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 14

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 51863c2 and f009c77.
Files ignored due to path filters (26)
  • crates/language/Cargo.toml is excluded by: !**/*.toml
  • crates/wasm-bindings/wasm_parsers/tree-sitter-gritql.wasm is excluded by: !**/*.wasm
  • crates/wasm-bindings/wasm_parsers/tree-sitter-php_only.wasm is excluded by: !**/*.wasm
  • resources/language-metavariables/tree-sitter-php/Cargo.lock is excluded by: !**/*.lock
  • resources/language-metavariables/tree-sitter-php/Cargo.toml is excluded by: !**/*.toml
  • resources/language-metavariables/tree-sitter-php/bindings/go/go.mod is excluded by: !**/*.mod
  • resources/language-metavariables/tree-sitter-php/package.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php/Cargo.toml is excluded by: !**/*.toml
  • resources/language-metavariables/tree-sitter-php/php/bindings/go/go.mod is excluded by: !**/*.mod
  • resources/language-metavariables/tree-sitter-php/php/package.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php/pyproject.toml is excluded by: !**/*.toml
  • resources/language-metavariables/tree-sitter-php/php/src/grammar.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php/src/node-types.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php_only/Cargo.toml is excluded by: !**/*.toml
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/go/go.mod is excluded by: !**/*.mod
  • resources/language-metavariables/tree-sitter-php/php_only/package.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php_only/pyproject.toml is excluded by: !**/*.toml
  • resources/language-metavariables/tree-sitter-php/php_only/src/grammar.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/php_only/src/node-types.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/src/grammar.json is excluded by: !**/*.json
  • resources/language-metavariables/tree-sitter-php/src/node-types.json is excluded by: !**/*.json
  • resources/node-types/grit-node-types.json is excluded by: !**/*.json
  • resources/node-types/gritql-node-types.json is excluded by: !**/*.json
  • resources/node-types/php-node-types.json is excluded by: !**/*.json
  • resources/node-types/php_only-node-types.json is excluded by: !**/*.json
  • vendor/tree-sitter-gritql is excluded by: !**/vendor/**
Files selected for processing (107)
  • .gitmodules (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • crates/core/src/pattern/dynamic_snippet.rs (1 hunks)
  • crates/core/src/pattern/patterns.rs (3 hunks)
  • crates/core/src/pattern/variable.rs (1 hunks)
  • crates/core/src/test.rs (3 hunks)
  • crates/gritmodule/src/patterns_directory.rs (5 hunks)
  • crates/language/src/language.rs (2 hunks)
  • crates/language/src/lib.rs (1 hunks)
  • crates/language/src/php.rs (1 hunks)
  • crates/language/src/target_language.rs (18 hunks)
  • crates/lsp/src/language.rs (2 hunks)
  • crates/wasm-bindings/src/match_pattern.rs (3 hunks)
  • resources/edit_grammars.mjs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/LICENSE (1 hunks)
  • resources/language-metavariables/tree-sitter-php/Makefile (1 hunks)
  • resources/language-metavariables/tree-sitter-php/Package.swift (1 hunks)
  • resources/language-metavariables/tree-sitter-php/README.md (1 hunks)
  • resources/language-metavariables/tree-sitter-php/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/go/binding.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/go/binding_test.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/index.d.ts (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/php.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/php_only.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/init.py (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/init.pyi (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/binding.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/rust/README.md (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPHP/php.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPhp/php.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/scanner.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/bugs.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/class.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/declarations.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/execution_operator.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/expressions.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/literals.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/statements.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/string.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/corpus/types.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/highlight/keywords.php (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/highlight/literals.php (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/highlight/types.php (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/test/highlight/variables.php (1 hunks)
  • resources/language-metavariables/tree-sitter-php/examples/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/.editorconfig (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/.gitattributes (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/Makefile (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/Package.swift (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/c/tree-sitter-php.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/c/tree-sitter-php.pc.in (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/go/binding.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/go/binding_test.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/index.d.ts (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/init.py (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/init.pyi (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/binding.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/swift/TreeSitterPhp/php.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/setup.py (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/scanner.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/scanner.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/alloc.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/array.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/parser.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/test/corpus/common (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/test/corpus/interpolation.txt (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/test/highlight (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/.editorconfig (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/.gitattributes (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/Makefile (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/Package.swift (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/c/tree-sitter-php_only.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/c/tree-sitter-php_only.pc.in (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/go/binding.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/go/binding_test.go (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.d.ts (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/python/tree_sitter_php_only/init.py (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/python/tree_sitter_php_only/init.pyi (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/python/tree_sitter_php_only/binding.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/swift/TreeSitterPhpOnly/php_only.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/setup.py (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/scanner.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/scanner.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/alloc.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/array.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/parser.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/test/corpus/common (1 hunks)
Files not processed due to max files limit (15)
  • resources/language-metavariables/tree-sitter-php/php_only/test/corpus/php_only.txt
  • resources/language-metavariables/tree-sitter-php/php_only/test/highlight
  • resources/language-metavariables/tree-sitter-php/queries/highlights.scm
  • resources/language-metavariables/tree-sitter-php/queries/injections-text.scm
  • resources/language-metavariables/tree-sitter-php/queries/injections.scm
  • resources/language-metavariables/tree-sitter-php/queries/tags.scm
  • resources/language-metavariables/tree-sitter-php/script/known-failures.txt
  • resources/language-metavariables/tree-sitter-php/script/parse-examples
  • resources/language-metavariables/tree-sitter-php/src/parser.backup
  • resources/language-metavariables/tree-sitter-php/src/parser.c
  • resources/language-metavariables/tree-sitter-php/src/tree_sitter/alloc.h
  • resources/language-metavariables/tree-sitter-php/src/tree_sitter/array.h
  • resources/language-metavariables/tree-sitter-php/src/tree_sitter/parser.h
  • resources/language-submodules/tree-sitter-php
  • resources/metavariable-grammars/php-metavariable-grammar.js
Files skipped from review due to trivial changes (19)
  • resources/language-metavariables/tree-sitter-php/.gitignore
  • resources/language-metavariables/tree-sitter-php/LICENSE
  • resources/language-metavariables/tree-sitter-php/bindings/node/php.js
  • resources/language-metavariables/tree-sitter-php/bindings/node/php_only.js
  • resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/init.py
  • resources/language-metavariables/tree-sitter-php/examples/.gitignore
  • resources/language-metavariables/tree-sitter-php/php/.editorconfig
  • resources/language-metavariables/tree-sitter-php/php/.gitattributes
  • resources/language-metavariables/tree-sitter-php/php/.gitignore
  • resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/init.py
  • resources/language-metavariables/tree-sitter-php/php/bindings/swift/TreeSitterPhp/php.h
  • resources/language-metavariables/tree-sitter-php/php/test/corpus/common
  • resources/language-metavariables/tree-sitter-php/php/test/highlight
  • resources/language-metavariables/tree-sitter-php/php_only/.editorconfig
  • resources/language-metavariables/tree-sitter-php/php_only/.gitattributes
  • resources/language-metavariables/tree-sitter-php/php_only/.gitignore
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/c/tree-sitter-php_only.pc.in
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/python/tree_sitter_php_only/init.py
  • resources/language-metavariables/tree-sitter-php/php_only/test/corpus/common
Additional comments: 198
resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/__init__.pyi (1)
  • 1-1: The function definition looks correct for a language binding. Ensure the return type (int) aligns with the project's expectations for language IDs.
resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/__init__.pyi (1)
  • 1-1: Identical to the previous review, ensure the return type (int) is consistent with the project's expectations for language IDs.
resources/language-metavariables/tree-sitter-php/php_only/bindings/python/tree_sitter_php_only/__init__.pyi (1)
  • 1-1: Given this is a PHP-only binding, ensure the return type (int) is consistent with the project's expectations, especially considering any specialized handling or features.
resources/language-metavariables/tree-sitter-php/php/grammar.js (1)
  • 1-3: The module definition using a common grammar utility is a good practice for modularity. Consider adding a comment explaining the grammar definition process for PHP for clarity.
resources/language-metavariables/tree-sitter-php/php_only/grammar.js (1)
  • 1-3: The module definition for PHP-only features is clear and maintainable. Adding a comment explaining the PHP-only grammar definition process could enhance clarity.
resources/language-metavariables/tree-sitter-php/bindings/node/index.js (1)
  • 1-7: The setup for Node.js bindings using node-gyp-build and the handling of node type information are correctly implemented. Ensure the path to node-types.json is correct and accessible.
resources/language-metavariables/tree-sitter-php/php/bindings/node/index.js (1)
  • 1-7: Identical to the previous review, ensure the path to node-types.json is correct and accessible for the PHP bindings.
resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.js (1)
  • 1-7: Given this is for PHP-only features, ensure the path to node-types.json is correct and accessible, especially considering any specialized handling or features.
resources/language-metavariables/tree-sitter-php/php/bindings/c/tree-sitter-php.pc.in (1)
  • 1-11: The pkg-config file for tree-sitter-php is correctly structured and follows standard conventions for specifying paths, dependencies, and compilation flags. This should facilitate the integration of the PHP grammar into projects using pkg-config to manage dependencies.
resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPhp/php.h (1)
  • 1-16: The Swift binding header file for tree-sitter-php is correctly implemented, ensuring proper C linkage and preventing multiple inclusions through the use of include guards. This setup is essential for integrating the PHP grammar with Swift projects.
resources/language-metavariables/tree-sitter-php/php/bindings/c/tree-sitter-php.h (1)
  • 1-16: The C binding header file for tree-sitter-php is correctly structured, ensuring proper C linkage for C++ compilers and preventing multiple inclusions with include guards. This is essential for integrating the PHP grammar with C projects.
resources/language-metavariables/tree-sitter-php/php_only/bindings/c/tree-sitter-php_only.h (1)
  • 1-16: The C binding header file for tree-sitter-php_only introduces a specialized variant of the PHP grammar. It is correctly structured, ensuring proper C linkage for C++ compilers and preventing multiple inclusions with include guards. This specialized grammar could be important for projects requiring specific PHP language features.
resources/language-metavariables/tree-sitter-php/php_only/bindings/swift/TreeSitterPhpOnly/php_only.h (1)
  • 1-16: The Swift binding header file for tree-sitter-php_only introduces a specialized variant of the PHP grammar. It is correctly structured, ensuring proper C linkage for C++ compilers and preventing multiple inclusions with include guards. This specialized grammar could be beneficial for Swift projects requiring specific PHP language features.
resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPHP/php.h (1)
  • 1-17: The Swift binding header file for TreeSitterPHP correctly declares both tree_sitter_php and tree_sitter_php_only functions, offering flexibility for projects that may need to switch between the standard and specialized PHP grammars. The file is well-structured, ensuring proper C linkage for C++ compilers and preventing multiple inclusions with include guards.
resources/language-metavariables/tree-sitter-php/bindings/go/binding.go (1)
  • 1-13: The Go binding file for tree-sitter-php is correctly implemented, using #cgo directives to integrate the C parser with Go. The inclusion of a note about external scanners is thoughtful for future extensions. This setup is essential for projects using Go to work with the PHP grammar.
resources/language-metavariables/tree-sitter-php/php/bindings/go/binding.go (1)
  • 1-13: The Go binding file for tree-sitter-php in the PHP bindings directory is correctly implemented, mirroring the setup in the previous Go bindings file. It uses #cgo directives effectively to integrate the C parser with Go, facilitating the use of the PHP grammar in Go projects.
resources/language-metavariables/tree-sitter-php/php_only/bindings/go/binding.go (2)
  • 3-6: The inclusion of parser.c directly in the Go binding file is a common practice for tree-sitter language bindings. However, ensure that any changes to the C parser are reflected here, and consider the maintainability of including C code directly in Go bindings.
  • 11-12: This function correctly exposes the tree-sitter PHP language parser to Go. It's important to ensure that the tree_sitter_php_only() function is correctly defined in the C code and returns a valid pointer to the tree-sitter language structure.
resources/language-metavariables/tree-sitter-php/bindings/go/binding_test.go (1)
  • 10-14: This test ensures that the PHP grammar can be successfully loaded. It's a good practice to include such tests to verify the integration of new languages. Consider adding more comprehensive tests that cover specific syntax cases or edge cases in PHP parsing to ensure robust support.
resources/language-metavariables/tree-sitter-php/php/bindings/go/binding_test.go (1)
  • 10-14: Identical to the previous review comment, this test verifies the PHP grammar loading. It's beneficial to expand testing to cover more detailed syntax parsing and edge cases to ensure comprehensive PHP support.
resources/language-metavariables/tree-sitter-php/common/test/highlight/literals.php (1)
  • 4-19: The syntax highlighting tests for PHP literals are well-covered, including strings, booleans, and constants. Ensure that the syntax highlighting engine correctly interprets these annotations and that all PHP literals are tested, including edge cases not covered here.
resources/language-metavariables/tree-sitter-php/php_only/bindings/go/binding_test.go (1)
  • 10-14: This test checks the loading of the PHPOnly grammar. As with the other language bindings, consider expanding the test suite to include more detailed syntax parsing tests to ensure the PHPOnly grammar is robustly supported.
crates/language/src/lib.rs (1)
  • 15-15: The addition of the PHP module is correctly placed in alphabetical order among the other language modules. This maintains consistency and readability in the module declarations. Ensure that the corresponding PHP module is properly implemented and tested.
resources/language-metavariables/tree-sitter-php/common/test/highlight/variables.php (1)
  • 3-20: The syntax highlighting tests for PHP variables, including constructors and built-in variables, are well-covered. It's important to ensure that the syntax highlighting engine correctly interprets these annotations. Consider adding tests for more complex variable usages or edge cases to ensure comprehensive coverage.
resources/language-metavariables/tree-sitter-php/binding.gyp (1)
  • 2-20: The build configuration for the tree-sitter PHP binding is correctly set up, including the necessary dependencies, source files, and compiler flags. Ensure that all source files, especially if an external scanner is added in the future, are correctly listed in the sources array. Maintaining this file is crucial for the build process.
resources/language-metavariables/tree-sitter-php/php/binding.gyp (1)
  • 1-21: The binding.gyp configuration for the tree_sitter_php_binding target is correctly defined, including dependencies, include directories, sources, and C flags. The note regarding the external scanner is a helpful reminder for future enhancements. Overall, the changes are well-structured and follow best practices for defining Node.js addon build configurations.
resources/language-metavariables/tree-sitter-php/php_only/binding.gyp (1)
  • 1-21: The binding.gyp configuration for the tree_sitter_php_only_binding target is correctly defined and follows the same best practices as the previous binding.gyp file reviewed. The target name distinction is appropriate, and the overall structure of the file is consistent with the requirements for defining Node.js addon build configurations.
resources/language-metavariables/tree-sitter-php/bindings/node/index.d.ts (1)
  • 1-28: The TypeScript declaration file correctly defines types for base nodes, child nodes, node information, and the language itself. The structure and syntax of the type definitions follow TypeScript best practices, and the export of the language constant is appropriately handled. These changes are well-suited for the project's expansion to support PHP.
resources/language-metavariables/tree-sitter-php/php/bindings/node/index.d.ts (1)
  • 1-28: The TypeScript declaration file in the tree-sitter-php/php/bindings/node directory is identical to the previously reviewed file, correctly defining types and exporting the language constant. The duplication appears to be intentional and is consistent with the project's structure for supporting PHP in different contexts.
resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.d.ts (1)
  • 1-28: The TypeScript declaration file in the tree-sitter-php/php_only/bindings/node directory is identical to the previously reviewed files, correctly defining types and exporting the language constant. The duplication appears to be intentional and is consistent with the project's structure for supporting PHP in various contexts.
resources/language-metavariables/tree-sitter-php/common/test/highlight/types.php (1)
  • 1-21: The types.php file provides well-structured test cases for syntax highlighting of PHP types, including both built-in and user-defined types. The comments indicating the expected syntax highlighting categories are clear and consistent, making this file a valuable resource for testing the project's syntax highlighting functionality for PHP.
resources/language-metavariables/tree-sitter-php/php/src/scanner.c (1)
  • 1-17: The scanner.c file correctly implements functions for creating, serializing, deserializing, scanning, and destroying an external scanner for PHP syntax. The implementations follow the expected pattern for tree-sitter external scanners and are consistent with best practices in C programming. These changes are well-suited for the project's expansion to support PHP.
resources/language-metavariables/tree-sitter-php/bindings/node/binding.cc (1)
  • 1-20: The binding.cc file correctly implements a Node.js addon for the PHP language using the tree-sitter grammar. The structure and syntax of the implementation follow best practices in C++ programming and Node.js addon development. The inclusion of a unique type tag for the language addon is a good practice for identification purposes. These changes are well-suited for the project's expansion to support PHP.
resources/language-metavariables/tree-sitter-php/php/bindings/node/binding.cc (1)
  • 1-20: The Node.js binding implementation for PHP language support looks correct and follows best practices for N-API module development. It properly exports the tree_sitter_php language parser and assigns a unique type tag for the language object, enhancing type safety.

Ensure that the tree_sitter_php function and the LANGUAGE_TYPE_TAG are thoroughly tested, especially since type tags are critical for N-API's type checking mechanisms.

resources/language-metavariables/tree-sitter-php/php/bindings/rust/build.rs (1)
  • 1-19: The Rust build script for compiling the PHP parser is well-structured and follows Rust conventions. It correctly specifies the C11 standard and includes the necessary source files. The commented block for an external scanner is a good placeholder for future extensions.

Consider verifying the build process on different platforms to ensure portability and compatibility, especially if the project aims to support a wide range of environments.

resources/language-metavariables/tree-sitter-php/php_only/bindings/node/binding.cc (1)
  • 1-20: The Node.js binding implementation for PHP-only language support is correctly implemented, mirroring the structure and practices of the previous PHP binding file. It properly exports the tree_sitter_php_only language parser and uses the same type tag for language object identification.

Given the similarity to the previous PHP binding, ensure consistency in testing and documentation between the two, especially regarding the unique aspects of the PHP-only support.

resources/language-metavariables/tree-sitter-php/php_only/src/scanner.c (1)
  • 1-17: The implementation of the external scanner for PHP-only appears to be correct and follows the conventions for tree-sitter external scanners. It provides essential lifecycle functions for the scanner, which are crucial for the parser's operation.

Ensure that the external scanner's logic, especially in the tree_sitter_php_only_external_scanner_scan function, is thoroughly tested with various PHP code snippets to guarantee accurate tokenization and parsing.

resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/build.rs (1)
  • 1-19: The Rust build script for the PHP-only parser is correctly set up, mirroring the structure and conventions of the PHP parser build script. It specifies the necessary compilation standards and includes the source files for the parser.

Given the presence of a commented block for an external scanner, if the PHP-only variant uses or plans to use an external scanner, ensure that the relevant code is uncommented and correctly integrated into the build process.

resources/language-metavariables/tree-sitter-php/Package.swift (1)
  • 1-29: The Swift package configuration for TreeSitterPHP is well-defined, including both PHP and PHP-only sources. It correctly specifies the library product and its targets, ensuring that the necessary source files and resources are included in the package.

Ensure that the publicHeadersPath and headerSearchPath are correctly set to integrate seamlessly with Swift projects. Additionally, consider specifying version constraints for dependencies if the package starts to depend on external Swift packages in the future.

resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php/binding.c (1)
  • 1-27: The Python C extension for PHP language support is correctly implemented, following the conventions for Python C extensions. It provides a method to retrieve the tree-sitter language object for PHP, which is essential for integrating the parser with Python projects.

Ensure that the extension is tested across different Python versions and platforms to guarantee compatibility and stability. Additionally, consider adding more detailed documentation in the module definition to assist developers in understanding its purpose and usage.

resources/language-metavariables/tree-sitter-php/php/bindings/python/tree_sitter_php/binding.c (1)
  • 1-27: This file appears to be a duplicate of the previously reviewed binding.c in the Python bindings for PHP. The implementation and considerations mentioned in the previous review comment apply here as well.

Ensure that any duplication is intentional and consider consolidating the files if they serve the same purpose to reduce maintenance overhead and potential confusion.

resources/language-metavariables/tree-sitter-php/README.md (1)
  • 1-15: The README file for the tree-sitter PHP grammar is well-structured and informative. It provides essential links and a brief description of the project. However, the static analysis hints at a possible spelling mistake, which seems to be a false positive in this context. The use of multiple exclamation marks in badges is standard practice and does not detract from the document's professionalism.
resources/language-metavariables/tree-sitter-php/bindings/rust/build.rs (1)
  • 1-29: The Rust build script for including the PHP grammar in the project is correctly set up. It properly includes source files and sets necessary compiler flags to suppress warnings that are not critical for the grammar's functionality. Additionally, it uses println! macros to ensure the build is re-triggered if any of the source files change, which is a good practice for build scripts.
resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/alloc.h (1)
  • 1-54: The alloc.h header file in the PHP grammar source is well-structured and provides a flexible mechanism for overriding memory allocation functions. This is particularly useful for embedding tree-sitter in environments where custom memory management is required. The use of preprocessor directives to conditionally define macros ensures that the default allocation functions (malloc, calloc, realloc, free) are used unless explicitly overridden, which is a good practice.
resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/alloc.h (1)
  • 1-54: The alloc.h header file in the PHP-only grammar source is identical to the one reviewed in the PHP grammar source. It correctly provides a mechanism for overriding memory allocation functions, which is beneficial for custom memory management strategies. The use of preprocessor directives to conditionally define macros is a good practice.
resources/language-metavariables/tree-sitter-php/bindings/rust/README.md (1)
  • 1-43: The README for the Rust bindings of the tree-sitter PHP grammar is clear and informative. It provides straightforward instructions for adding the grammar to a Rust project, including dependencies in Cargo.toml, and a simple example of how to use the grammar to parse PHP code. The static analysis hints at possible spelling mistakes, which seem to be false positives in this context.
resources/language-metavariables/tree-sitter-php/php/Package.swift (1)
  • 1-48: The Package.swift file for the tree-sitter PHP grammar is correctly configured. It specifies the necessary Swift tools version, supported platforms, library product, and target configuration. The exclusion list in the target configuration is comprehensive, ensuring that only relevant source files are included in the build. The use of .c11 as the C language standard is appropriate for the included C source files.
resources/language-metavariables/tree-sitter-php/php_only/Package.swift (1)
  • 1-48: The Package.swift file for the tree-sitter PHP-only grammar is correctly configured, mirroring the setup seen in the Package.swift for the PHP grammar. It specifies the necessary Swift tools version, supported platforms, library product, and target configuration. The comprehensive exclusion list ensures that only relevant source files are included in the build, and the use of .c11 as the C language standard is appropriate.
resources/language-metavariables/tree-sitter-php/php/setup.py (2)
  • 9-14: The custom build command Build correctly copies the queries directory if it exists. This ensures that any tree-sitter query files are included in the built package.
  • 17-22: The BdistWheel class customizes the wheel tags for compatibility. It forces the wheel to be compatible with CPython 3.8 and above, using the abi3 tag. This is a common practice for binary distributions that contain compiled extensions but want to maintain compatibility across Python 3.x versions.
resources/language-metavariables/tree-sitter-php/php_only/setup.py (2)
  • 9-14: The custom build command Build for the PHP-only package correctly handles the queries directory. This consistency in handling resource files across different language packages is good for maintainability.
  • 17-22: The BdistWheel class customization for the PHP-only package mirrors the approach taken in the PHP package, ensuring compatibility with CPython 3.8 and above using the abi3 tag. This consistency is good practice.
resources/language-metavariables/tree-sitter-php/php/bindings/rust/lib.rs (4)
  • 22-22: The file defines two external functions, tree_sitter_php and tree_sitter_php_only, but it's unclear why both are included in the PHP bindings file. This could potentially confuse users about which function to use for standard PHP parsing.

Consider clarifying the use cases for each function in the documentation or comments, or if tree_sitter_php_only is not needed here, consider removing it to avoid confusion.

  • 43-47: The constants PHP_NODE_TYPES and PHP_ONLY_NODE_TYPES are well-defined, providing easy access to the node types JSON files. This is a good practice for making grammar metadata available to users of the library.
  • 51-54: Including the queries (HIGHLIGHT_QUERY, INJECTIONS_QUERY, TAGS_QUERY) directly in the library is a good practice, as it allows users to utilize these queries without additional setup. However, ensure that these queries are up-to-date and relevant to the PHP grammar being supported.

Verify that the included queries are compatible with the current version of the PHP grammar and update them if necessary.

  • 1-54: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [56-64]

The test module includes a basic test to ensure that the grammar can be loaded. This is a good start, but consider adding more comprehensive tests to cover parsing different PHP constructs and ensuring that the grammar behaves as expected.

Consider expanding the test suite to cover more aspects of the PHP grammar, including parsing edge cases and common syntax patterns.

resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/lib.rs (1)
  • 1-54: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-64]

Ensure that the PHP-only Rust bindings are consistent with the PHP bindings in terms of functionality, naming conventions, and documentation. Any discrepancies or specific differences should be clearly documented to avoid confusion among users.

resources/language-metavariables/tree-sitter-php/common/test/corpus/literals.txt (1)
  • 1-115: The test cases for PHP literals (booleans, floats, integers, strings, and shell commands) are comprehensive and cover a wide range of syntax variations. This is crucial for ensuring the robustness of the PHP grammar support.
crates/lsp/src/language.rs (2)
  • 24-24: The addition of PHP to the language_id_to_pattern_language function correctly maps the "php" language ID to the PatternLanguage::Php enum. This is essential for enabling PHP support in the language server protocol (LSP) functionalities.
  • 52-52: Similarly, the addition of PHP to the target_language_to_language_id function correctly maps the TargetLanguage::Php enum to the "php" language ID. This ensures consistency in language ID handling across different parts of the LSP implementation.
resources/language-metavariables/tree-sitter-php/bindings/rust/lib.rs (1)
  • 1-65: Ensure that the tree-sitter PHP bindings are consistent with the previously reviewed PHP and PHP-only bindings in terms of functionality, naming conventions, and documentation. Any discrepancies or specific differences should be clearly documented to avoid confusion among users.
resources/language-metavariables/tree-sitter-php/common/test/highlight/keywords.php (1)
  • 1-144: The test file keywords.php provides a comprehensive set of PHP keyword usage examples, covering a wide range of PHP syntax. This is crucial for testing the syntax highlighting capabilities of the PHP grammar. Ensure that all PHP keywords are covered and that the test cases accurately reflect their usage in real-world PHP code.
crates/language/src/php.rs (1)
  • 103-103: The code correctly replaces escaped caret symbols (\\^) with caret symbols (^) in the source_string. This change ensures that escaped characters are properly handled in dynamic snippets, maintaining the integrity of the original text.
.gitmodules (1)
  • 65-67: The addition of tree-sitter-php as a submodule is correctly configured. This is a crucial step in integrating PHP language support into the project.
resources/language-metavariables/tree-sitter-php/php/Makefile (1)
  • 103-108: The Makefile includes a test target that invokes tree-sitter test. This is a good practice for ensuring that the grammar and its modifications are correctly functioning. It's important to regularly run these tests, especially after making changes to the grammar or the build process.
resources/language-metavariables/tree-sitter-php/php_only/Makefile (1)
  • 103-108: The Makefile for the php_only variant also correctly includes a test target. Consistency in testing across different variants of the language parser is crucial for maintaining the quality and reliability of the language support.
resources/language-metavariables/tree-sitter-php/Makefile (1)
  • 109-111: The clean target in the Makefile is well-defined, ensuring that all generated files are removed. This is essential for maintaining a clean build environment and for troubleshooting build issues.
resources/language-metavariables/tree-sitter-php/php/test/corpus/interpolation.txt (1)
  • 231-244: The test case for handling octothorpe (#) immediately after text interpolation is a good addition. It ensures that the parser correctly handles edge cases involving PHP string interpolation syntax.
crates/core/src/pattern/dynamic_snippet.rs (1)
  • 103-103: The update to replace escaped caret symbols (\\^) with caret symbols (^) in dynamic snippets is a necessary improvement. It ensures that special characters are correctly interpreted in the context of dynamic patterns, enhancing the flexibility and usability of dynamic snippets.
CONTRIBUTING.md (1)
  • 56-56: The update in the CONTRIBUTING.md file to specify the new location for adding language implementations (crates/core/languages/src) is clear and correctly guides contributors. This change is important for maintaining consistency in the project structure as new languages are added.
resources/language-metavariables/tree-sitter-php/common/test/corpus/execution_operator.txt (1)
  • 6-6: Ensure that the use of backticks for shell command execution in PHP is correctly tested across different scenarios, including handling of quotes, escape sequences, and variable interpolation.
resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/parser.h (1)
  • 1-230: The parser.h file for the PHP tree-sitter parser correctly defines necessary data structures, enums, and functions for parsing PHP code. Ensure that all definitions align with the PHP language specifications and tree-sitter parsing requirements.
resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/parser.h (1)
  • 1-230: This parser.h file, located in the php_only directory, is identical to the previously reviewed parser.h. Ensure that its placement in a specific directory for PHP does not affect its integration or usage within the project.
resources/language-metavariables/tree-sitter-php/common/test/corpus/bugs.txt (4)
  • 2-2: Ensure that the test case for using self as a constant is accurately representing the PHP behavior and the intended bug scenario.
  • 25-25: Verify that the precedence for the error suppression operator is correctly tested, especially in complex expressions.
  • 52-52: Confirm that the test cases for using expressions as named arguments cover all relevant scenarios and PHP versions where this behavior might differ.
  • 168-168: Check that the handling of closing tags in strings is thoroughly tested, including different contexts and string types.
resources/edit_grammars.mjs (1)
  • 60-61: The addition of 'php' to the allLanguages array correctly extends the script's support to include PHP language grammars. Ensure that all related functionalities, such as grammar copying and building, are properly updated to handle PHP grammars.
crates/gritmodule/src/patterns_directory.rs (4)
  • 29-29: The addition of the php field to the PatternsDirectory struct correctly extends support to include PHP language patterns. Ensure that all related functionalities, such as pattern insertion and retrieval, are properly updated to handle PHP patterns.
  • 114-114: Verify that the method get_language_directory_mut correctly handles PHP language mappings, allowing for mutable access to PHP patterns.
  • 141-141: Ensure that the method get_language_directory correctly returns a reference to the PHP patterns directory when requested.
  • 258-259: Confirm that the merge method correctly handles merging of PHP patterns into the PatternsDirectory, ensuring no data loss or duplication.
resources/language-metavariables/tree-sitter-php/common/test/corpus/types.txt (11)
  • 5-20: The Type names section accurately represents PHP's basic and qualified name type declarations.
  • 26-51: The Primitive types section correctly tests PHP's primitive types including int, callable, iterable, and never.
  • 56-130: The Intersection type section accurately tests PHP's intersection types, reflecting the correct syntax tree structure.
  • 135-236: The Disjunctive Normal Form type section accurately represents complex type declarations in PHP, with correct syntax tree structures.
  • 242-258: The Optional types section correctly tests PHP's optional types, with accurate syntax tree representations.
  • 265-290: The Union types section accurately tests PHP's union types, reflecting the correct syntax tree structure.
  • 297-320: The Mixed type section accurately tests PHP's mixed type, with correct syntax tree representations.
  • 326-346: The Static type section accurately tests PHP's static return type, with correct syntax tree representations.
  • 352-384: The Null type section accurately tests PHP's null type, with correct syntax tree representations.
  • 390-422: The False type section accurately tests PHP's false type, with correct syntax tree representations.
  • 428-460: The True type section accurately tests PHP's true type, with correct syntax tree representations.
resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/array.h (3)
  • 23-115: The Array macros section provides a comprehensive set of operations for managing dynamic arrays in C, with clear documentation and adherence to best practices.
  • 161-253: The Private functions section correctly implements low-level operations for dynamic array management, ensuring safe memory operations and efficient manipulation.
  • 255-274: The Helper functions section efficiently supports sorted array operations, with correct implementations for searching and insertion.
resources/language-metavariables/tree-sitter-php/common/test/corpus/statements.txt (1)
  • 1-465: The test corpus covers a wide range of PHP syntax elements, which is essential for ensuring the robustness of the PHP language support. It's well-structured and includes both code snippets and their expected parse trees, facilitating automated testing and validation of the tree-sitter-php parser's accuracy.
crates/wasm-bindings/src/match_pattern.rs (3)
  • 43-43: The addition of the PHP_LANGUAGE static variable is a necessary step for integrating PHP language support into the wasm bindings. This aligns with the structure used for other languages.
  • 359-359: Including PHP in the pattern_language_to_path function ensures that the PHP parser is correctly loaded when needed. This is consistent with how other languages are handled.
  • 402-402: The update to get_lang_store to include PHP language support is correctly implemented. This change is essential for caching the PHP language parser for efficient reuse.
crates/language/src/language.rs (2)
  • 257-257: The update to dynamically insert the metavariable prefix using self.metavariable_prefix() is a good enhancement for supporting multiple languages with different conventions for metavariables. This change improves the flexibility and maintainability of the codebase.
  • 417-420: The update to use .contains for snippet matching instead of checking for an exact match makes the matching process more forgiving, which can be beneficial for handling snippets with additional whitespace or formatting differences. However, consider adding a comment or documentation to clarify the rationale behind this more permissive matching strategy, ensuring future maintainers understand the intended behavior.
resources/language-metavariables/tree-sitter-php/common/test/corpus/declarations.txt (1)
  • 1-636: The test corpus covers a wide range of PHP constructs and their expected tree-sitter syntax tree representations, which is crucial for validating the PHP language support added in this PR. The PHP code snippets and their corresponding syntax trees appear to be correctly structured and represent a broad spectrum of PHP syntax. This comprehensive coverage is essential for ensuring robust PHP support in the project.
resources/language-metavariables/tree-sitter-php/common/test/corpus/class.txt (11)
  • 7-10: The abstract class definition and its corresponding tree-sitter representation are correctly implemented. However, it's important to ensure that the abstract method b is implemented in any concrete subclass to avoid runtime errors.
  • 43-60: Anonymous classes are correctly defined and represented. Ensure that interfaces B and C, and trait T are defined elsewhere in the test corpus or project to validate their usage here.
  • 154-169: The conditional class definition is correctly implemented. This test case effectively demonstrates PHP's capability to conditionally declare classes. Ensure that the condition (if (true)) varies in other tests to cover more scenarios.
  • 229-256: Typed class constants are correctly demonstrated. This is a feature introduced in PHP 7.4, enhancing type safety for class constants. Ensure that the PHP version targeted by this project supports this feature.
  • 267-277: The final class definition is correctly implemented. This test case effectively demonstrates the usage of the final keyword to prevent class inheritance.
  • 286-294: Implicitly public properties and methods are correctly demonstrated. However, it's recommended to explicitly declare visibility for clarity and consistency, especially in modern PHP codebases.

Consider explicitly declaring visibility for properties and methods to improve code readability and maintainability.

  • 351-385: Property types are correctly demonstrated, showcasing PHP's typed properties feature introduced in PHP 7.4. Ensure that the types used (D, float) are defined or valid PHP types.
  • 396-432: Constructor property promotion is correctly demonstrated. This feature, introduced in PHP 8.0, allows for a more concise syntax for declaring and initializing class properties. Ensure that the PHP version targeted by this project supports this feature.
  • 446-483: Readonly properties are correctly demonstrated. This feature, introduced in PHP 8.1, allows for the declaration of properties that cannot be modified after initialization. Ensure that the PHP version targeted by this project supports this feature.
  • 740-769: Constructor property promotion with the readonly modifier is correctly demonstrated. This combines two features introduced in PHP 8.0 and PHP 8.1, respectively. Ensure that the PHP version targeted by this project supports both features.
  • 804-820: Constants in traits are correctly demonstrated. This test case effectively shows that traits can include constants, which is a feature supported in PHP. Ensure that the trait Test and its constant FLAG_1 are utilized in classes that use this trait.
resources/language-metavariables/tree-sitter-php/common/scanner.h (12)
  • 11-16: The VEC_RESIZE macro correctly resizes a dynamic array and checks for allocation failure. However, it's important to ensure that this macro is used in a context where memory leaks are prevented, especially in error handling paths.
  • 24-28: The VEC_POP macro correctly removes the last element from a dynamic array. Ensure that this macro is used in contexts where it's guaranteed that the array is not empty to avoid underflow.
  • 38-44: The VEC_CLEAR macro correctly clears a dynamic array. It's good practice to also set the capacity to 0 or resize the array to a minimal capacity after clearing to avoid potential memory waste.

Consider resizing the array to a minimal capacity after clearing to optimize memory usage.

  • 70-83: The enumeration for TokenType is well-defined, covering various token types relevant to PHP syntax. Ensure that all these token types are handled appropriately in the scanner logic to correctly tokenize PHP code.
  • 91-100: The string_eq function correctly compares two strings for equality. It's efficient and correctly handles different string lengths. Ensure that this function is used in contexts where null-terminated strings are not expected, as it relies on the length field.
  • 131-147: The serialize function correctly serializes scanner state into a buffer. Ensure that the buffer size checks (TREE_SITTER_SERIALIZATION_BUFFER_SIZE) are accurate and account for all possible serialized data to prevent buffer overflows.
  • 150-171: The deserialize function correctly deserializes scanner state from a buffer. Ensure that the deserialization logic correctly handles all edge cases and that the buffer length is validated to prevent reading beyond the buffer's end.
  • 174-195: The scan_whitespace function correctly consumes whitespace and comments. Ensure that this function is used appropriately in contexts where skipping whitespace and comments is desired, and that it doesn't inadvertently skip meaningful tokens.
  • 201-227: The is_escapable_sequence function correctly identifies escapable sequences within strings. Ensure that this function's logic aligns with the latest PHP string escape sequence rules to accurately tokenize strings.
  • 291-424: The scan_encapsed_part_string function handles scanning parts of encapsed strings, including handling variables and escape sequences. Ensure that this function is thoroughly tested with various string contents to cover all edge cases in PHP string parsing.
  • 438-568: The scan function orchestrates the scanning process based on the current lexer state and valid symbols. It's crucial to ensure that this function correctly handles all PHP syntax elements that require custom scanning logic, and that it's tested with a wide range of PHP code samples.
  • 570-598: The external_scanner_destroy function correctly frees all allocated resources associated with the scanner. Ensure that all dynamically allocated memory within the scanner is freed here to prevent memory leaks.
resources/language-metavariables/tree-sitter-php/php/src/scanner.h (3)
  • 11-16: Consider adding error handling for memory allocation failures in macros like VEC_RESIZE and STRING_RESIZE. Currently, the use of assert(tmp != NULL) will terminate the program on allocation failure. Depending on the application's requirements, it might be more appropriate to return an error code or perform a safe cleanup and exit.

Also applies to: 46-51

  • 85-89: The type definitions for String and HeredocVec are clear and follow common C conventions.

Also applies to: 102-111

  • 1-598: The overall code structure and organization are logical, facilitating understanding of the scanner's functionality. The use of macros for common operations and clear type definitions contribute to the code's readability.
resources/language-metavariables/tree-sitter-php/php_only/src/scanner.h (3)
  • 11-16: Consider adding error handling for memory allocation failures in macros like VEC_RESIZE and STRING_RESIZE. Currently, the use of assert(tmp != NULL) will terminate the program on allocation failure. Depending on the application's requirements, it might be more appropriate to return an error code or perform a safe cleanup and exit.

Also applies to: 46-51

  • 85-89: The type definitions for String and HeredocVec are clear and follow common C conventions.

Also applies to: 102-111

  • 1-598: The overall code structure and organization are logical, facilitating understanding of the scanner's functionality. The use of macros for common operations and clear type definitions contribute to the code's readability.
resources/language-metavariables/tree-sitter-php/common/test/corpus/string.txt (10)
  • 7-7: Ensure that the test case for simple variable access within a string is correctly capturing the intended PHP behavior. This test seems to correctly represent PHP's string interpolation feature.
  • 23-23: This test case is important for ensuring that spaces between { and $ in string interpolation are handled correctly. It's good to see edge cases being tested.
  • 40-70: These examples cover a wide range of complex string interpolation scenarios, including object and array access, function calls, and more. It's crucial to ensure these cases are accurately represented to test the parser's ability to handle PHP's flexible string interpolation syntax.
  • 195-197: Simple variable access within double-quoted strings is correctly tested here. This ensures the parser can handle the most basic form of string interpolation in PHP.
  • 218-221: Testing member and array access within strings is essential for comprehensive coverage of PHP's string interpolation capabilities. These cases appear to be well-formed and should provide valuable validation for the parser.
  • 276-303: Corner cases are crucial for testing the limits and edge behaviors of the parser. This section seems to cover a variety of challenging scenarios, including handling of special characters and complex expressions within strings. It's important to ensure these tests are accurate and reflective of PHP's behavior.
  • 508-603: Heredoc and nowdoc syntaxes are unique to PHP and can be tricky to parse correctly, especially with complex interpolations and edge cases. These tests are vital for ensuring the parser handles these constructs accurately. It's good to see comprehensive coverage here.
  • 795-840: Nowdoc syntax tests are equally important as heredoc, given their differences in interpolation behavior. These tests seem to cover basic to complex nowdoc usage scenarios, ensuring the parser can distinguish and correctly handle nowdoc blocks.
  • 915-925: Testing heredoc and nowdoc identifiers with numbers is a good practice to ensure the parser's robustness in handling identifier variations. This section correctly addresses such cases.
  • 956-961: Unicode escape sequences in strings are an advanced feature that can introduce parsing challenges. These tests are essential for verifying the parser's ability to correctly interpret and handle unicode escape sequences within strings.
crates/language/src/target_language.rs (18)
  • 14-14: Adding Php to the list of imports is necessary for integrating PHP support into the project. This change correctly imports the Php module for use in defining PHP as a target language.
  • 69-69: Including Php in the PatternLanguage enum is a crucial step for recognizing PHP as a supported language in pattern matching functionalities. This addition is correctly implemented.
  • 97-97: Correctly adding Php to the fmt::Display implementation for PatternLanguage ensures that PHP language patterns can be properly displayed as "php". This is a necessary change for user-facing features and logging.
  • 125-125: Integrating Php into the conversion from TargetLanguage to PatternLanguage is essential for ensuring that PHP language patterns are correctly recognized and handled. This change is implemented correctly.
  • 153-153: The addition of Php to the is_initialized method of PatternLanguage is necessary for checking the initialization status of PHP support. This change correctly integrates PHP into the initialization checks.
  • 219-219: Adding Php to the from_string method allows the system to recognize "php" as a valid language string, enabling the creation of PHP language patterns from strings. This addition is correctly implemented.
  • 249-249: Correctly adding PHP file extensions to the get_file_extensions method of PatternLanguage is crucial for recognizing PHP files based on their extensions. This change ensures that PHP files are correctly identified and processed.
  • 276-276: Including Php in the method for getting the default file extension for each language ensures that PHP is treated as a first-class language within the system. This addition is correctly implemented.
  • 300-300: Adding PHP file extensions to the from_extension method is necessary for recognizing PHP files based on their extensions. This change correctly integrates PHP file extension handling into the system.
  • 339-339: Including Php in the enumerate method of PatternLanguage is essential for ensuring that PHP is included in language enumerations, such as in UI dropdowns or language filters. This addition is correctly implemented.
  • 374-374: The addition of Php to the to_target_with_ts_lang method allows for the creation of a TargetLanguage::Php instance with an optional TSLanguage parser. This change is necessary for integrating PHP support into the system's language handling mechanisms.
  • 463-469: Adding PHP file types to the expand_paths function is crucial for ensuring that PHP files are included when expanding paths for language-specific processing. This change correctly integrates PHP file type handling into the path expansion logic.
  • 517-517: Including Php in the TargetLanguage enum is a critical step in adding PHP as a target language for the project. This change correctly defines Php as a variant of TargetLanguage, enabling PHP-specific functionalities.
  • 550-550: Correctly adding Php to the TryFrom<PatternLanguage> implementation for TargetLanguage is necessary for converting PatternLanguage::Php into TargetLanguage::Php. This change is correctly implemented and is essential for language conversion functionalities.
  • 581-581: Including Php in the fmt::Display implementation for TargetLanguage ensures that PHP language instances can be properly displayed as "php". This is a necessary change for user-facing features and logging.
  • 625-625: The addition of Php to the to_module_language method of TargetLanguage is necessary for converting TargetLanguage::Php instances back to PatternLanguage::Php. This change correctly implements the reverse conversion logic.
  • 651-651: Correctly setting the should_pad_snippet method to return false for PHP aligns with the formatting expectations for PHP code snippets. This change ensures that PHP snippets are formatted consistently with other languages.
  • 677-677: Adding Php to the make_single_line_comment method is crucial for generating single-line comments in PHP code. This change correctly implements PHP comment syntax handling, ensuring that comments are formatted correctly in PHP snippets.
crates/core/src/pattern/patterns.rs (2)
  • 485-485: The modification in the condition for node.named_child_count() seems to refine the logic for handling AST nodes. It would be beneficial to add a comment explaining the rationale behind this specific condition to aid future maintainers.
  • 542-552: The refactoring of the logic for handling fields and nodes in the Pattern implementation introduces a clearer distinction between handling single and multiple fields. To ensure this refactoring does not introduce regressions, it would be beneficial to add tests covering these specific scenarios.
resources/language-metavariables/tree-sitter-php/common/test/corpus/expressions.txt (28)
  • 6-6: The dynamic variable name syntax ($$k = $v;) is correctly represented in the tree-sitter output. This syntax allows for variable variable names in PHP, which can be useful but also potentially confusing or error-prone. Consider adding a comment or documentation in the project to explain the use cases and risks associated with dynamic variable names.
  • 64-64: The use of new self(); demonstrates the instantiation of a new instance of the current class. This is a common pattern in PHP, especially in factory methods or when implementing the Singleton pattern. The representation in the tree-sitter output is accurate.
  • 82-83: The syntax for using a unary operation within an if-statement condition (if (!$foo = $bar) {}) is correctly represented. This pattern can be useful for checking the assignment result within a condition, but it might lead to readability issues. Consider adding a comment to clarify the intention.
  • 100-100: Using capitalized logical operators (OR, XOR) is a PHP feature that allows for readability but can lead to confusion with the lower-case logical operators due to their different precedence. The tree-sitter representation captures this syntax correctly. It's worth noting in documentation that the use of capitalized logical operators is discouraged in favor of their lower-case counterparts for consistency and to avoid precedence issues.
  • 140-140: The use of a cast expression with an include statement ((array) include 'some.php';) is a valid PHP syntax for casting the return value of the include statement. This can be useful when including a file that returns an array, ensuring the result is indeed an array. The tree-sitter representation accurately captures this syntax.
  • 162-162: The syntax for using reserved words as function calls, such as new static(...), is correctly represented. This allows for late static binding in PHP, enabling more flexible inheritance patterns. The tree-sitter output accurately reflects this syntax.
  • 181-181: The scoped self-call expression (m::self();) is a unique PHP feature allowing for calling a static method named self on class m. This syntax is correctly captured in the tree-sitter output. It's a less common usage and could benefit from additional documentation or comments for clarity.
  • 198-221: The examples of array destructuring using both list() and [] syntax, including support for trailing commas and skipping arguments, are well-documented and correctly represented in the tree-sitter output. This feature is a powerful part of PHP for working with arrays, and the examples provided cover a good range of use cases.
  • 346-349: The precedence of logical operators (and, or, xor) in assignment expressions is a critical aspect of PHP syntax that can lead to unexpected behaviors due to their lower precedence compared to the assignment operator. The examples provided correctly demonstrate this behavior. It's important to highlight the precedence issue in documentation to prevent logical errors.
  • 411-411: The null-coalescence operator (??) example demonstrates its right associativity correctly. This operator is a useful feature in PHP for providing default values when dealing with null. The tree-sitter output accurately captures this syntax.
  • 429-431: The examples of negation and instanceof within a unary operation are correctly represented. These are common patterns in PHP for type checking and negation. The tree-sitter output accurately reflects these operations.
  • 498-498: The nested assignments ($c = $d[0] = $d[2] = $i;) are correctly represented and demonstrate a useful feature in PHP for assigning multiple variables at once. This pattern can be powerful but should be used with caution to maintain code readability.
  • 518-519: The examples of all binary operation precedence levels are comprehensive and demonstrate the complex interactions between different operators in PHP. This is a critical aspect of the language that can easily lead to bugs if not understood properly. The tree-sitter output accurately captures these precedence levels.
  • 606-606: The concatenation precedence example demonstrates the precedence between the concatenation operator (.) and arithmetic operators. This is an important aspect of PHP syntax to understand to avoid unexpected results. The tree-sitter output correctly captures this behavior.
  • 627-629: The examples of using print_r with arrays and the spread operator (...) for array unpacking are correctly represented. These features are widely used in PHP for debugging and working with arrays. The tree-sitter output accurately reflects these syntaxes.
  • 665-671: The examples of anonymous functions, including the use of the use keyword for capturing variables by reference, are correctly captured. Anonymous functions are a powerful feature in PHP for creating closures. The syntax for specifying the capture by reference should be carefully used to avoid unintended side effects.
  • 716-734: The throw expression examples demonstrate the flexibility of PHP 8's throw expression, allowing it to be used in new contexts such as conditional expressions and logical operations. This enhances the language's expressiveness in error handling. The tree-sitter output accurately captures these new usages.
  • 849-852: The nullsafe operator (?->) examples are correctly represented and demonstrate a significant feature introduced in PHP 8. This operator allows for more concise and safe access to properties and methods on potentially null objects. The tree-sitter output accurately captures this syntax.
  • 903-911: The first-class callable syntax (foo(...);, $this->foo(...);, A::foo(...);) is correctly captured, showcasing a new feature in PHP 8 that simplifies the syntax for using callables. However, the examples marked as invalid but accepted at the parser level (new Foo(...);, #[Foo(...)] function foo() {};) should be clearly documented as such to avoid confusion.
  • 968-973: The match expression example is correctly represented and demonstrates the match expression introduced in PHP 8. This feature provides a more powerful and concise alternative to switch statements. The tree-sitter output accurately captures the syntax and semantics of match expressions.
  • 1036-1041: The arrow function examples (fn(...) => ...;) are correctly captured, showcasing the concise syntax for anonymous functions introduced in PHP 7.4. Arrow functions are useful for creating simple closures with automatic variable capture. The tree-sitter output accurately reflects this syntax.
  • 1130-1130: The function call with named arguments (array_fill(start_index: 0, num: 100, value: $val);) is correctly represented. Named arguments are a feature introduced in PHP 8 that improves code readability and flexibility in function calls. The tree-sitter output accurately captures this syntax.
  • 1153-1153: The precedence between concatenation and shift operators is correctly demonstrated. Understanding operator precedence is crucial to avoid unexpected behaviors in PHP. The tree-sitter output accurately captures this behavior.
  • 1176-1208: The examples of references (=&) in various contexts (assignments, function parameters, foreach loops, etc.) are correctly represented. PHP's reference mechanism allows for aliasing variables and can be powerful but should be used judiciously to avoid complexity and maintainability issues. The tree-sitter output accurately captures these syntaxes.
  • 1457-1458: The empty match expression example demonstrates the syntax for a match expression without any arms. While this is syntactically valid, it's functionally equivalent to throwing a UnhandledMatchError. It's important to ensure that match expressions are used meaningfully.
  • 1480-1480: The dynamic class constant access syntax (Foo::{$bar};) is correctly represented. This feature allows for accessing a class constant dynamically using a variable. It's a powerful feature that can be used for flexible configurations or dynamic behavior based on constant values.
  • 1496-1505: The examples of UTF-8 identifiers and heredoc/nowdoc syntaxes demonstrate PHP's support for multibyte characters in variable names and string literals. This enhances PHP's internationalization capabilities. The tree-sitter output accurately captures these syntaxes.
  • 1531-1534: The yield expressions (yield;, yield $a;, yield from $a;) are correctly represented, showcasing the generator syntax in PHP. Generators provide an efficient way to iterate over data without needing to load everything into memory. The tree-sitter output accurately captures these syntaxes.
resources/language-metavariables/tree-sitter-php/common/define-grammar.js (5)
  • 1-6: Ensure that the license and authorship information is accurate and up-to-date, especially if this file has been significantly modified or if new contributors have been involved in its development.
  • 8-12: The ESLint directives at the top of the file disable certain rules globally. Consider if these rules need to be disabled for the entire file or if they could be applied more selectively to only the necessary sections or lines. Disabling rules globally can sometimes lead to overlooking potential issues.
  • 44-44: The precedence level for GRIT_METAVARIABLE is set very high (100). Ensure that this precedence level does not unintentionally override other important operations in the grammar, especially given the context of integrating PHP support and the potential syntax conflict mentioned regarding PHP variables and Grit metavariables.
  • 1578-1579: The definition of grit_metavariable uses a custom precedence level and a regex pattern to match metavariables starting with µ. Given the potential syntax conflict between PHP variables and Grit metavariables, ensure that this pattern does not clash with valid PHP syntax and that it is consistently used across the project to represent Grit metavariables.
  • 1593-1598: The keyword function is designed to create a case-insensitive regex match for PHP keywords and optionally alias them. This is a critical function for ensuring the grammar correctly identifies PHP keywords. Verify that all PHP keywords are accurately represented and that any new keywords introduced in PHP versions supported by this grammar are included.
crates/core/src/test.rs (3)
  • 12820-12839: The php_no_match test correctly implements a scenario where no match is expected for a given PHP pattern. This approach is consistent with best practices for testing pattern matching functionality.
  • 12842-12864: The php_simple_match test effectively uses the run_test_expected function with TestArgExpected struct to assert a specific expected outcome, aligning with the previously suggested testing approach. This is a good practice for creating clear and maintainable tests.
  • 12883-12883: Proper closure of the php_simple_match test function is confirmed. This ensures that the test is well-structured and follows best practices.

Comment on lines 8144 to 8165
#[test]
fn test_basic_php() {
let pattern = r#"
|language php
|
|`echo $str` => `echo $str;`
|"#
.trim_margin()
.unwrap();

let source = r#"echo "hello world""#.trim_margin().unwrap();
let file = "foo.php";

let context = ExecutionContext::default();
let language: TargetLanguage = PatternLanguage::Php.try_into().unwrap();
// println!("language: {language} pattern: {pattern}");

let pattern = src_to_problem(pattern, language).unwrap();
let results = pattern.execute_file(&RichFile::new(file.to_owned(), source), &context);
// println!("results: {results}");
assert_yaml_snapshot!(results);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of assert_yaml_snapshot! for testing is discouraged as per previous comments. Instead, consider using run_test_expected function with TestArgExpected struct to assert specific expected outcomes, which provides clearer, more maintainable tests.

crates/core/src/pattern/variable.rs Show resolved Hide resolved
Comment on lines +25 to +34

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_php() }
}

/// The content of the [`node-types.json`][] file for this grammar.
///
Copy link
Contributor

Choose a reason for hiding this comment

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

The language function is defined to return the language using tree_sitter_php_only, which seems inconsistent with the module's purpose (support for PHP, not just PHP-only). This might be an error or oversight.

-    unsafe { tree_sitter_php_only() }
+    unsafe { tree_sitter_php() }

Consider correcting this to use tree_sitter_php for the standard PHP language support.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_php() }
}
/// The content of the [`node-types.json`][] file for this grammar.
///
/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_php() }
}
/// The content of the [`node-types.json`][] file for this grammar.
///

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8c77c49 and 16f4d8a.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • crates/wasm-bindings/wasm_parsers/tree-sitter-php_only.wasm is excluded by !**/*.wasm
Files selected for processing (5)
  • crates/core/src/pattern/code_snippet.rs (1 hunks)
  • crates/core/src/test.rs (2 hunks)
  • crates/language/src/php.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js (1 hunks)
  • resources/metavariable-grammars/php-metavariable-grammar.js (1 hunks)
Files not summarized due to errors (1)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1)
  • crates/language/src/php.rs
Additional comments not posted (12)
resources/metavariable-grammars/php-metavariable-grammar.js (3)

1-12: The file header and global configurations are correctly set up and follow best practices for a tree-sitter grammar definition file.


1587-1587: The introduction of µ as a prefix for Grit metavariables is a smart solution to avoid syntax conflicts with PHP variables. This change enhances the flexibility and usability of the grammar for PHP language support.


1601-1652: The helper functions (keyword, commaSep1, commaSep, pipeSep1, ampSep1) are well-implemented and contribute to the readability and maintainability of the grammar definition. They abstract common patterns effectively, making the grammar more concise.

crates/core/src/test.rs (9)

12797-12816: The test function php_no_match is well-structured and follows the pattern of testing for no matches correctly. However, consider adding a brief comment above the test function to describe its purpose and what specific scenario it is testing for PHP pattern matching. This will improve readability and maintainability.


12819-12843: The php_simple_match function demonstrates a simple pattern match and rewrite scenario for PHP. It's clear and concise. To further enhance the test's clarity, consider adding a comment explaining the test's intent, especially how the pattern rewrite is expected to work in this context.


12845-12869: In the php_until test, the use of until in pattern matching is a critical feature to test. The test case seems comprehensive, but adding a comment explaining the specific use case of until in PHP pattern matching, and why it's important, could be beneficial for future maintainability.


12871-12886: The php_quote_snippet_rewrite test function introduces a snippet rewrite test. It's important to ensure that the test covers various edge cases, such as different types of quotes used in PHP. If not already covered, consider adding more test cases to cover these scenarios.


12889-12918: The php_if_statement test function is testing the rewrite within an if statement. This is a good scenario to test. However, ensure that the test also covers edge cases, such as nested if statements and if statements with else branches, to ensure the pattern matching and rewriting logic is robust.


12921-12946: The php_delete_include test function tests the deletion of an include statement. This is a crucial aspect of pattern rewriting. To enhance this test, consider adding more scenarios that include different variations of include and require statements in PHP, such as require_once and include_once, to ensure comprehensive coverage.


12949-12989: The php_function_modifier test function aims to test the modification of a function's visibility and name. It's essential to also test the preservation of function arguments and the function body during the rewrite process. If not already included, consider adding test cases that include functions with arguments and complex bodies to ensure the rewrite logic accurately handles these scenarios.


12992-13011: The php_rewrite_arrow_function test function is testing the rewrite of arrow functions in PHP. This is a modern PHP feature that should be thoroughly tested. Consider adding more test cases to cover arrow functions with multiple arguments, no arguments, and complex expressions to ensure the rewrite logic is comprehensive.


12794-13016: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [13013-13032]

The update to the existing CSS property value testing function is not visible in the provided code snippet. Without the specific changes, it's difficult to provide targeted feedback. However, ensure that any updates to existing tests do not break previously established test cases and that the updates are relevant to the changes introduced in this PR.

@@ -190,6 +190,7 @@ fn process_snippet_content(
if lang.exact_variable_regex().is_match(source.trim()) {
match source.trim() {
"$_" => return Ok(Pattern::Underscore),
"^_" => return Ok(Pattern::Underscore),
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The provided context from the shell scripts does not directly address the original verification task, which was to ensure that the new pattern ^_ is documented and tested across the application. However, the search for references to Pattern::Underscore in the Rust files returned multiple matches across various files in the crates/core/src/pattern directory. This indicates that the Pattern::Underscore enum variant, which is related to the ^_ pattern, is indeed used throughout the application's logic.

The second search attempt, which aimed to find comments or documentation mentioning the ^_ pattern, resulted in a regex parse error due to an incorrect pattern. After correcting the search pattern, the script did not produce any output, suggesting that there might not be explicit comments or documentation within the Rust files that mention the ^_ pattern directly.

Given the context and the results from the executed shell scripts, it appears that while the Pattern::Underscore enum variant is integrated into the application's logic, there might not be explicit comments or documentation within the Rust files that directly mention the ^_ pattern. This could indicate a gap in documentation or comments regarding this specific pattern.

Considering the information gathered, the verification process concludes with the observation that while the Pattern::Underscore is utilized in the application, explicit documentation or comments mentioning the ^_ pattern directly within the Rust files might be lacking or not captured by the search scripts executed.

Analysis chain

The addition of ^_ to return Pattern::Underscore introduces a new pattern matching case. Ensure that this new pattern is consistently handled across all relevant parts of the application, including documentation and tests. It's also important to verify that this change aligns with the intended use cases for pattern matching within the project.


Given the lack of output from the initial search, it's necessary to refine our approach to verify the integration and testing of the new ^_ pattern. We'll search for references to the Pattern::Underscore enum variant and any comments or documentation that specifically mention the ^_ pattern. This should provide a clearer picture of how the new pattern is handled across the application.


The search for references to Pattern::Underscore confirmed its usage across various parts of the application, indicating that the new ^_ pattern is integrated into the application's logic. However, there was an error in the regex pattern used to search for comments or documentation mentioning the ^_ pattern. Let's correct this and perform the search again to ensure comprehensive verification.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new pattern `^_` is documented and tested across the application
rg --type rust '^_'

Length of output: 21



Script:

#!/bin/bash
# Search for references to Pattern::Underscore enum variant
rg 'Pattern::Underscore'

# Search for comments or documentation mentioning the ^_ pattern
rg '//.*\^\_'

Length of output: 1580



Script:

#!/bin/bash
# Corrected search for comments or documentation mentioning the ^_ pattern
rg '//.*\^_'

Length of output: 201083

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 16f4d8a and c432a14.
Files selected for processing (3)
  • crates/core/src/test.rs (2 hunks)
  • crates/language/src/php.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js (1 hunks)
Files not summarized due to errors (1)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1)
  • crates/language/src/php.rs
Additional comments not posted (11)
resources/language-metavariables/tree-sitter-php/common/define-grammar.js (1)

1587-1587: The introduction of the µ prefix for metavariables is a clever solution to avoid syntax conflicts. Ensure that this convention is consistently applied and documented to avoid confusion.

crates/core/src/test.rs (10)

12797-12816: The test function php_no_match correctly sets up a scenario where the provided PHP source code does not match the specified pattern. This is a good practice for ensuring that the pattern matching logic correctly identifies non-matching cases. However, consider adding a brief comment above the test function to describe its purpose and what specific scenario it is testing for. This will improve maintainability and readability for future contributors.


12819-12843: The php_simple_match function demonstrates a basic pattern matching scenario in PHP. It's well-structured and serves as a good example of how to write tests for pattern matching. To further enhance the test's clarity, consider adding inline comments explaining the pattern and expected transformation. This will aid in understanding the test's intent without needing to decipher the pattern syntax.


12845-12869: In the php_until test, the use of the until keyword in the pattern is a sophisticated feature that requires careful testing. This test appears to be correctly implemented. To ensure robustness, consider adding more complex scenarios or edge cases that could potentially break the until logic. This could involve nested function calls or similar constructs that are common in PHP code.


12871-12886: The php_quote_snippet_rewrite test function demonstrates rewriting within quoted PHP code. This is a critical feature for code transformation tasks. The test is concise and to the point. Given the potential complexity of handling quotes in different contexts (e.g., nested quotes, escaped quotes), it might be beneficial to add more tests covering these scenarios to ensure the robustness of the pattern matching and rewriting logic.


12888-12918: The php_if_statement test function is designed to test pattern matching and rewriting within an if statement. This is a common use case and it's important to ensure it works correctly. The test is well-structured, but it might be beneficial to include additional tests covering various forms of if statements in PHP, such as those with else clauses, else if clauses, and nested if statements, to ensure comprehensive coverage.


12920-12946: The php_delete_include function tests the deletion of an include statement in PHP, which is a common refactoring task. This test is straightforward and effectively demonstrates the intended functionality. To enhance the test suite, consider adding tests for similar PHP constructs, such as require, include_once, and require_once, to ensure that the pattern matching logic is capable of handling these variations as well.


12948-12989: The php_function_modifier test function checks the ability to modify function visibility and rename functions within a class. This is a complex transformation that is well tested by this function. However, it would be beneficial to add tests that cover scenarios with different types of class members (e.g., static methods, properties) and visibility modifiers (e.g., protected, public) to ensure that the pattern matching and rewriting logic works correctly in a wider range of scenarios.


12991-13011: The php_rewrite_arrow_function test function focuses on rewriting arrow functions in PHP. This is a relatively new feature in PHP, and it's important to ensure that the pattern matching logic can handle it correctly. The test is well-implemented, but consider adding more tests covering different uses of arrow functions, such as those with multiple parameters or no parameters, to ensure comprehensive coverage.


13013-13033: The php_array test function tests the transformation of array values. This is a common operation and the test is correctly implemented. To further ensure the robustness of the pattern matching logic, consider adding tests that cover associative arrays, nested arrays, and arrays with mixed types of values. This will help ensure that the logic can handle the diverse ways arrays are used in PHP.


12794-13038: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [13035-13054]

The incomplete code fragment related to the css_property_value test function does not provide enough context to review. However, it's important to ensure that tests for other languages, such as CSS in this case, are not negatively impacted by the addition of PHP support. Verify that all existing tests, including those for other languages, pass after these changes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c432a14 and 8a54196.
Files ignored due to path filters (1)
  • crates/wasm-bindings/wasm_parsers/tree-sitter-php_only.wasm is excluded by !**/*.wasm
Files selected for processing (1)
  • resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPhp/php.h (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPhp/php.h
Additional Context Used

@urbit-pilled
Copy link
Contributor Author

-added context snippets
-added more tests
-updated the php grammar with more fields and grit_metavariable placements

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a54196 and 17d80bc.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (6)
  • crates/core/src/pattern/code_snippet.rs (1 hunks)
  • crates/core/src/pattern/patterns.rs (3 hunks)
  • crates/core/src/pattern/variable.rs (1 hunks)
  • crates/core/src/test.rs (2 hunks)
  • crates/language/Cargo.toml (2 hunks)
  • crates/language/src/language.rs (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • crates/core/src/pattern/code_snippet.rs
  • crates/core/src/pattern/patterns.rs
  • crates/core/src/pattern/variable.rs
  • crates/language/src/language.rs
Additional Context Used
Additional comments not posted (12)
crates/language/Cargo.toml (2)

30-30: The addition of tree-sitter-php as an optional dependency is correctly implemented and follows the established pattern for integrating new languages. This change aligns with the PR's objective to introduce PHP support to the project.


69-69: Including tree-sitter-php in the builtin-parser feature is appropriate and ensures that PHP support can be optionally enabled. This change is consistent with the project's modular approach to language support.

crates/core/src/test.rs (10)

12797-12816: The test function php_no_match correctly sets up a scenario where the pattern does not match the source code. However, consider adding a brief comment explaining the purpose of the test and the expected outcome for better maintainability and readability.


12819-12843: In php_simple_match, the test verifies a simple pattern match and rewrite. It's well-structured, but adding a comment explaining the test's intent could enhance clarity and maintainability.


12845-12869: The php_until test function demonstrates the use of until in pattern matching. It's a good practice to include comments explaining complex tests like this one, detailing the specific functionality being tested.


12871-12886: php_quote_snippet_rewrite tests the rewrite functionality with PHP variables. Ensure that the test covers various edge cases, such as variables within different PHP constructs, to fully validate the rewrite logic.


12889-12918: In php_if_statement, the test checks the rewrite within an if statement. This test is crucial for ensuring the rewrite logic works in different PHP syntax contexts. Consider adding more tests around control structures to cover more scenarios.


12921-12946: php_delete_include tests the deletion of an include statement. This is a good example of a specific language feature test. To further improve, verify that the deletion logic does not affect surrounding code, especially in complex PHP files.


12949-12989: The php_function_modifier test function modifies a class method's visibility and name. It's important to ensure that the test covers scenarios where the class has multiple methods, to verify that only the targeted method is modified.


12992-13011: php_rewrite_arrow_function tests the rewrite of arrow functions. Given the variety of contexts arrow functions can be used in PHP, consider adding more comprehensive tests to cover these scenarios thoroughly.


13014-13033: In php_array, the test function rewrites array values. This test is crucial for array handling logic. Ensure comprehensive coverage by including tests for associative, indexed, and nested arrays.


12794-13038: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [13035-13054]

The css_property_value test function appears to be incomplete in the provided code snippet. If this is an existing test related to CSS and not part of the PHP integration, ensure it's correctly implemented and relevant to the PR's scope.

Verification successful

The css_property_value test function is complete, as shown by the script output, which includes the entire function setup and execution. While the direct relevance of this test to the PR's scope cannot be assessed without more context, its inclusion in the test suite suggests it is likely relevant to the project's ongoing development or the specific changes introduced by the PR.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if the css_property_value test function is complete and relevant to the PR.
rg --type rust "fn css_property_value" crates/core/src/test.rs

Length of output: 90



Script:

#!/bin/bash
# Extract the entire content of the css_property_value function to assess its completeness.
rg --type rust --context 30 "fn css_property_value" crates/core/src/test.rs

Length of output: 1304

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 17d80bc and c631247.
Files selected for processing (1)
  • resources/edit_grammars.mjs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • resources/edit_grammars.mjs
Additional Context Used

…ariable-grammar.js to php-common-metavariable-grammar.js
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c631247 and c469d93.
Files selected for processing (2)
  • resources/edit_grammars.mjs (3 hunks)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js (1 hunks)
Files not summarized due to errors (1)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1)
  • resources/edit_grammars.mjs
Additional Context Used
Additional comments not posted (5)
resources/metavariable-grammars/php-common-metavariable-grammar.js (5)

1587-1587: The introduction of Grit metavariables using the µ prefix is a clever solution to distinguish between PHP variables and Grit metavariables. However, ensure that this special handling does not conflict with any valid PHP syntax or naming conventions that might allow the µ character.


1561-1564: Ensure that the regex patterns used for matching PHP identifiers and other syntax elements are optimized to prevent potential ReDoS (Regular Expression Denial of Service) attacks. Specifically, review the regex pattern for PHP identifiers to ensure it does not allow for excessive backtracking or ambiguity.


1-1653: Given the comprehensive nature of the grammar definitions, consider the potential performance implications for parsing large PHP files or complex syntax structures. Review the grammar rules for opportunities to optimize performance without compromising the accuracy of parsing.


1-1653: The code is well-documented and organized, which aids in readability and maintainability. However, consider breaking down the file into smaller, more manageable modules if the grammar definitions continue to grow. This could improve maintainability and make it easier for new contributors to understand the structure of the grammar.


1601-1606: The function keyword is a good example of encapsulating common functionality for defining keywords in the grammar. This approach enhances readability and maintainability by avoiding repetition and making it easier to update keyword handling in the future.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c469d93 and 6fedda7.
Files selected for processing (1)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js (1 hunks)
Files not summarized due to errors (1)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js: Error: Message exceeds token limit
Additional Context Used
Additional comments not posted (6)
resources/metavariable-grammars/php-common-metavariable-grammar.js (6)

1586-1586: The introduction of the grit_metavariable rule using the µ prefix for metavariables is a clever solution to avoid syntax conflicts between PHP variables and Grit metavariables. However, ensure that this special character does not introduce issues in environments where character encoding might be a concern, especially in cross-platform scenarios.


48-50: The dialect check ensures that only supported dialects (php and php_only) can be used with this grammar definition. This is a good practice for maintaining clarity and preventing misuse. However, consider documenting the differences between these dialects and when one should be used over the other for future maintainers and users of the grammar.


111-121: The handling of extras, specifically the inclusion of text_interpolation for the php dialect, demonstrates attention to PHP's syntax nuances. It's important to ensure that all PHP-specific syntax elements are similarly accounted for in the grammar to avoid parsing errors or inaccuracies.


125-140: The program rule's conditional structure based on the dialect is a good approach to handle variations in PHP syntax. However, ensure that the optional closing PHP tag (?>) is correctly handled in all contexts, as its omission can lead to subtle bugs in PHP code, especially in mixed PHP/HTML environments.


1585-1586: The use of a custom precedence level (PREC.GRIT_METAVARIABLE) for the grit_metavariable ensures that these variables are correctly parsed with the intended priority in the grammar. This is crucial for maintaining the correct parse order and avoiding ambiguities in the grammar.


1600-1604: The keyword function provides a flexible way to define keywords in the grammar, with the option to alias the regex to the word. This can greatly simplify the grammar definition and make it more readable. Ensure that all PHP keywords are accurately represented and that the case-insensitivity is consistently applied across the grammar.

@@ -482,7 +483,7 @@ impl Pattern {
}
if node_types[sort as usize].is_empty() {
let content = node.utf8_text(text)?;
if node.named_child_count() == 0
if (node.named_child_count() == 0 || node.named_child_count() == 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just reverted this change, it was related to my attempt to match partial nodes.

Comment on lines +546 to +554
if !field.multiple() {
if nodes_list.len() == 1 {
return Ok((field_id, false, nodes_list.pop().unwrap()));
}
let field_node = node.child_by_field_id(field_id).unwrap();
let field_node_with_source = NodeWithSource::new(field_node.clone(), str::from_utf8(text).unwrap());
return Ok((field_id, false, Pattern::AstLeafNode(AstLeafNode::new(
field_node.kind_id(), field_node_with_source.text(), lang,
)?)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Reason for these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also removed this comment
// assumes that non multiple field has exactly one element

I think the assumption that a node where multiple=false will have exactly 1 node is false, multiple=true means that you can have more than one element so this means multiple=false can have 0 (an unnamed node) or 1 node.

I added the code to handle the case where nodes_list is empty. such as binary_expression-> operator in php. (Where there are unnamed strings, such at * and + instead of named nodes.

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

This looks fine, if you can answer the two questions I have.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6fedda7 and df1a576.
Files ignored due to path filters (1)
  • resources/language-metavariables/tree-sitter-php/Cargo.lock is excluded by !**/*.lock
Files selected for processing (35)
  • resources/language-metavariables/tree-sitter-php/.eslintrc.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.gitattributes (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/bug_report.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/config.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/feature_request.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/pull_request_template.md (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/workflows/ci.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/workflows/lint.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.github/workflows/release.yml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/.npmignore (1 hunks)
  • resources/language-metavariables/tree-sitter-php/Cargo.toml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.h.in (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.pc.in (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/package.json (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/Cargo.toml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/package.json (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/Cargo.toml (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/build.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/lib.rs (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/package.json (1 hunks)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js (1 hunks)
Files skipped from review due to trivial changes (9)
  • resources/language-metavariables/tree-sitter-php/.gitattributes
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/bug_report.yml
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/config.yml
  • resources/language-metavariables/tree-sitter-php/.github/ISSUE_TEMPLATE/feature_request.yml
  • resources/language-metavariables/tree-sitter-php/.github/pull_request_template.md
  • resources/language-metavariables/tree-sitter-php/.npmignore
  • resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.pc.in
  • resources/language-metavariables/tree-sitter-php/package.json
  • resources/language-metavariables/tree-sitter-php/php/Cargo.toml
Files skipped from review as they are similar to previous changes (16)
  • resources/language-metavariables/tree-sitter-php/.gitignore
  • resources/language-metavariables/tree-sitter-php/binding.gyp
  • resources/language-metavariables/tree-sitter-php/bindings/node/binding.cc
  • resources/language-metavariables/tree-sitter-php/bindings/node/index.js
  • resources/language-metavariables/tree-sitter-php/bindings/rust/build.rs
  • resources/language-metavariables/tree-sitter-php/bindings/rust/lib.rs
  • resources/language-metavariables/tree-sitter-php/php/binding.gyp
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/binding.cc
  • resources/language-metavariables/tree-sitter-php/php/bindings/node/index.js
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/build.rs
  • resources/language-metavariables/tree-sitter-php/php/bindings/rust/lib.rs
  • resources/language-metavariables/tree-sitter-php/php_only/binding.gyp
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/binding.cc
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/node/index.js
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/build.rs
  • resources/language-metavariables/tree-sitter-php/php_only/bindings/rust/lib.rs
Additional Context Used
Additional comments not posted (16)
resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.h.in (1)

1-16: The changes in tree-sitter.h.in are well-structured and follow standard practices for C/C++ header files. Using placeholders for parser names is a good approach for templates intended to be processed by build systems or scripts.

resources/language-metavariables/tree-sitter-php/.github/workflows/lint.yml (1)

1-19: The lint.yml GitHub Actions workflow is well-configured for linting with ESLint. It follows best practices for JavaScript projects, including the use of up-to-date actions for checking out the code and setting up Node.js.

resources/language-metavariables/tree-sitter-php/php_only/package.json (1)

1-17: The package.json for the PHP-only grammar is correctly structured, specifying the necessary configuration for Tree-sitter to recognize and handle PHP files. The inclusion of paths to queries and external files is appropriate for syntax highlighting and editor features.

resources/language-metavariables/tree-sitter-php/.eslintrc.js (1)

1-20: The .eslintrc.js configuration is well-defined, extending the Google style guide and customizing rules for indentation and maximum line length. This setup ensures code consistency and adheres to widely recognized coding standards.

resources/language-metavariables/tree-sitter-php/php/package.json (1)

1-20: The package.json for the PHP grammar is correctly structured, specifying the necessary configuration for Tree-sitter. The inclusion of an additional injections file (injections-text.scm) is a good enhancement for supporting more complex syntax highlighting or editor features.

resources/language-metavariables/tree-sitter-php/php_only/Cargo.toml (1)

1-26: The Cargo.toml for the PHP-only grammar is well-configured, specifying the necessary metadata, build script, included files, and dependencies for a Rust package. This setup ensures that the package can be correctly built and packaged for use with Tree-sitter.

resources/language-metavariables/tree-sitter-php/Cargo.toml (1)

1-29: The Cargo.toml for the PHP grammar is well-configured, covering both the PHP and PHP-only grammars. This setup ensures that the package supports a broad range of PHP syntax and features, following best practices for Rust packages in Tree-sitter grammar projects.

resources/language-metavariables/tree-sitter-php/.github/workflows/ci.yml (1)

1-37: The ci.yml GitHub Actions workflow is well-configured for continuous integration, covering a wide range of operating systems and specifying up-to-date versions of Node.js and Python. This setup ensures code quality and compatibility across different environments, following best practices for CI workflows.

resources/language-metavariables/tree-sitter-php/.github/workflows/release.yml (4)

3-9: The workflow is triggered by completed CI runs on the master branch. Consider using more inclusive terminology, such as main, for the primary branch name if it aligns with the project's naming conventions.


20-28: The script fails if no tag is found, which might be too restrictive for initial releases or in cases where tags are managed differently. Consider adding a default behavior or a more descriptive error message to guide the user.


41-58: The version comparison logic is complex and manually implemented. Consider using existing tools or libraries to compare semantic versions to reduce complexity and potential errors.


97-103: The steps to tag versions include deleting and re-creating the tag. This approach might lead to potential race conditions or conflicts if multiple workflows are running concurrently. Consider adding checks or using a more robust tagging strategy.

resources/metavariable-grammars/php-common-metavariable-grammar.js (4)

1587-1587: The introduction of a special token for Grit metavariables using the µ character is a clever solution to distinguish between PHP variables and Grit metavariables. However, ensure that this choice of character does not conflict with any PHP naming conventions or future PHP features. Additionally, consider documenting this choice prominently in both the code and any user-facing documentation to avoid confusion.


1601-1606: The keyword function is well-implemented for creating case-insensitive regex patterns for PHP keywords. However, ensure that all PHP keywords are covered by tests, especially those that might have unusual capitalization patterns. This is crucial for maintaining the accuracy of the grammar definition as the PHP language evolves.


1616-1618: The commaSep1 function for creating rules that match one or more items separated by commas is a common pattern in grammar definitions. Ensure that this function is used consistently throughout the grammar to handle similar patterns, which will aid in maintainability and readability.


1561-1564: The regex pattern for PHP names allows for a wide range of characters, including multi-byte characters due to a known PHP parser behavior. While this is a pragmatic approach, it's important to periodically review this against the official PHP documentation and parser updates to ensure continued compatibility and to avoid inadvertently allowing invalid identifiers.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between df1a576 and fd4e1d6.
Files ignored due to path filters (2)
  • crates/wasm-bindings/wasm_parsers/tree-sitter-php.wasm is excluded by !**/*.wasm
  • crates/wasm-bindings/wasm_parsers/tree-sitter-php_only.wasm is excluded by !**/*.wasm
Files selected for processing (7)
  • crates/core/src/pattern/patterns.rs (3 hunks)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/scanner.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/parser.h (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/scanner.c (1 hunks)
  • resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/parser.h (1 hunks)
  • resources/metavariable-grammars/php-common-metavariable-grammar.js (1 hunks)
Files not summarized due to errors (2)
  • resources/language-metavariables/tree-sitter-php/common/define-grammar.js: Error: Message exceeds token limit
  • resources/metavariable-grammars/php-common-metavariable-grammar.js: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (5)
  • crates/core/src/pattern/patterns.rs
  • resources/language-metavariables/tree-sitter-php/php/src/scanner.c
  • resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/parser.h
  • resources/language-metavariables/tree-sitter-php/php_only/src/scanner.c
  • resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/parser.h
Additional Context Used
Additional comments not posted (8)
resources/language-metavariables/tree-sitter-php/common/define-grammar.js (4)

47-50: The error handling for unknown dialects could be more informative. Consider listing the supported dialects in the error message to improve the developer experience.

-    throw new Error(`Unknown dialect ${dialect}`);
+    throw new Error(`Unknown dialect ${dialect}. Supported dialects are 'php' and 'php_only'.`);

44-44: The introduction of grit_metavariable with a high precedence is a clever solution to handle the syntax conflict between PHP variables and Grit metavariables.


118-120: Conditional inclusion of text_interpolation based on the dialect is a thoughtful approach to handle differences between PHP dialects.


1-1652: The overall structure and organization of the grammar definition are commendable. The clear separation of concerns and the use of helper functions for rule creation contribute to the readability and maintainability of the code.

resources/metavariable-grammars/php-common-metavariable-grammar.js (4)

1587-1587: The introduction of µ as a prefix for metavariables is a clever solution to the syntax conflict between PHP variables and Grit metavariables. However, it's important to ensure that this change is well-documented within the project to avoid confusion for future contributors or users of the project.

Consider adding comprehensive documentation or comments within the codebase explaining the rationale behind using µ for metavariables, including examples of how it resolves the mentioned syntax conflict.


1601-1606: The keyword function is designed to create a regex that matches a given word case-insensitively. This function is crucial for ensuring that the grammar can accurately recognize PHP keywords regardless of their case. However, it's essential to verify that all PHP keywords are correctly handled by this function and that there are no edge cases where a keyword might not be recognized due to unusual casing or similar issues.

Verification successful

Given the task at hand, it's essential to directly verify how the keyword function is implemented and used within the codebase, especially in relation to PHP keywords. The initial script provided a list of PHP keywords but did not automate the verification process regarding their handling by the keyword function. To proceed, we need to inspect the usage of the keyword function and ensure it's designed to handle all PHP keywords correctly, considering case insensitivity and potential edge cases.


The verification process has confirmed that the keyword function is effectively used within the php-common-metavariable-grammar.js file to handle a comprehensive list of PHP keywords. This includes a wide range of keywords covering control structures, type declarations, and other language constructs, indicating a thorough approach to recognizing PHP keywords accurately, regardless of their case. Based on the evidence provided by the script output, there are no indications of missing PHP keywords or improper handling that would lead to recognition issues. The function's design and its integration into the grammar definition appear to be well-executed for the purpose of accurately recognizing PHP keywords.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# List all PHP keywords and ensure they are covered by the keyword function.
echo "Checking PHP keywords coverage..."
# This is a simplified example. In a real scenario, you would compare the list of PHP keywords against those handled by the keyword function.
echo "List of PHP keywords: echo, if, else, while, function, class, try, catch, finally, return, yield"
echo "Please manually verify that all these keywords are correctly handled by the keyword function in the grammar definition."

Length of output: 528



Script:

#!/bin/bash
# Search for the usage of the `keyword` function with PHP keywords as arguments.
echo "Searching for usage of the keyword function with PHP keywords..."
rg "keyword\(.*\)" resources/metavariable-grammars/php-common-metavariable-grammar.js

Length of output: 4156


1616-1618: The commaSep1 function is used to create a rule for matching one or more rules separated by a comma. This is a common pattern in many programming languages, including PHP, for lists of variables, arguments, parameters, etc. It's important to ensure that this function is used consistently throughout the grammar definition to handle comma-separated lists correctly.

The implementation of commaSep1 looks correct and should handle comma-separated lists as expected. Good job on maintaining consistency in the grammar definition.


1640-1641: The pipeSep1 function, which creates a rule for matching one or more rules separated by a pipe (|), is crucial for defining union types and similar constructs in PHP. Given the introduction of union types in PHP 8.0, it's important to ensure that this function and its usage accurately reflect the syntax and semantics of union types in PHP.

Verification successful

The examination of the pipeSep1 function's usage within the codebase, specifically in the context of defining union types and similar constructs in PHP, confirms that it is correctly implemented and applied. The references found in the grammar definitions for union_type, disjunctive_normal_form_type, and type_list accurately reflect the syntax and semantics of union types in PHP. Therefore, the review comment regarding the need to verify the correct usage of pipeSep1 for union types and similar constructs has been successfully .

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the correct usage of pipeSep1 in the context of union types and similar constructs.
echo "Checking usage of pipeSep1 for union types..."
# This is a simplified example. In a real scenario, you would analyze the grammar definition to ensure that pipeSep1 is used correctly for union types and similar constructs.
echo "Please manually verify that pipeSep1 is used correctly to define the syntax and semantics of union types in PHP."

Length of output: 335



Script:

#!/bin/bash
# Search for references to pipeSep1 in the codebase to verify its usage in the context of union types and similar constructs.
echo "Searching for references to pipeSep1..."
rg "pipeSep1" --context 5

Length of output: 6988

@urbit-pilled
Copy link
Contributor Author

ok i think it should finally be ready to merge

@morgante morgante merged commit 43b48f8 into getgrit:main Apr 1, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants