-
Notifications
You must be signed in to change notification settings - Fork 89
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: Added support for php with test cases #120
Conversation
WalkthroughThis update integrates PHP programming language support extensively into the project. It covers adding PHP language-specific functionalities, patterns, tests, and tree-sitter grammar support across various project components. The changes ensure PHP is fully incorporated as a target language for pattern matching and syntax highlighting, enhancing the project's language diversity. Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 16
Review Status
Configuration used: CodeRabbit UI
Files ignored due to path filters (11)
Cargo.lock
is excluded by!**/*.lock
crates/wasm-bindings/wasm_parsers/tree-sitter-php.wasm
is excluded by!**/*.wasm
resources/language-metavariables/tree-sitter-php/Cargo.lock
is excluded by!**/*.lock
resources/language-metavariables/tree-sitter-php/bindings/go/go.mod
is excluded by!**/*.mod
resources/language-metavariables/tree-sitter-php/build/Release/obj.target/tree_sitter_php_binding/bindings/node/binding.o
is excluded by!**/*.o
resources/language-metavariables/tree-sitter-php/build/Release/obj.target/tree_sitter_php_binding/php/src/parser.o
is excluded by!**/*.o
resources/language-metavariables/tree-sitter-php/build/Release/obj.target/tree_sitter_php_binding/php/src/scanner.o
is excluded by!**/*.o
resources/language-metavariables/tree-sitter-php/build/Release/obj.target/tree_sitter_php_binding/php_only/src/parser.o
is excluded by!**/*.o
resources/language-metavariables/tree-sitter-php/build/Release/obj.target/tree_sitter_php_binding/php_only/src/scanner.o
is excluded by!**/*.o
resources/language-metavariables/tree-sitter-php/tree-sitter-php_base.wasm
is excluded by!**/*.wasm
resources/language-submodules/tree-sitter-php/bindings/go/go.mod
is excluded by!**/*.mod
Files selected for processing (104)
- crates/core/src/snapshots/marzano_core__test__basic_php.snap.new (1 hunks)
- crates/core/src/test.rs (2 hunks)
- crates/gritmodule/src/patterns_directory.rs (5 hunks)
- crates/language/Cargo.toml (2 hunks)
- crates/language/src/lib.rs (1 hunks)
- crates/language/src/php.rs (1 hunks)
- crates/language/src/target_language.rs (19 hunks)
- crates/lsp/src/language.rs (2 hunks)
- crates/wasm-bindings/src/match_pattern.rs (3 hunks)
- resources/edit_grammars.mjs (2 hunks)
- resources/language-metavariables/tree-sitter-php/.editorconfig (1 hunks)
- resources/language-metavariables/tree-sitter-php/.eslintrc.js (1 hunks)
- resources/language-metavariables/tree-sitter-php/Cargo.toml (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/c/tree-sitter-php_base.h (1 hunks)
- resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter-php_base.pc.in (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/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_base/init.py (1 hunks)
- resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php_base/init.pyi (1 hunks)
- resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php_base/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/TreeSitterPhpBase/php_base.h (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Makefile (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/bindings/node/binding.o.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php/src/parser.o.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php/src/scanner.o.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php_only/src/parser.o.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php_only/src/scanner.o.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/tree_sitter_php_binding.node.d (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/binding.Makefile (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/config.gypi (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/gyp-mac-tool (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/node_gyp_bins/python3 (1 hunks)
- resources/language-metavariables/tree-sitter-php/build/tree_sitter_php_binding.target.mk (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/grammar.js (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/grammar.js (1 hunks)
- resources/language-metavariables/tree-sitter-php/php/package.json (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/test/corpus/interpolation.txt (1 hunks)
- resources/language-metavariables/tree-sitter-php/php_only/grammar.js (1 hunks)
- resources/language-metavariables/tree-sitter-php/php_only/package.json (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/language-metavariables/tree-sitter-php/php_only/test/corpus/php_only.txt (1 hunks)
- resources/language-metavariables/tree-sitter-php/pyproject.toml (1 hunks)
- resources/language-metavariables/tree-sitter-php/queries/highlights.scm (1 hunks)
- resources/language-metavariables/tree-sitter-php/queries/injections-text.scm (1 hunks)
- resources/language-metavariables/tree-sitter-php/queries/injections.scm (1 hunks)
- resources/language-metavariables/tree-sitter-php/queries/tags.scm (1 hunks)
- resources/language-metavariables/tree-sitter-php/setup.py (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/grammar.json (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/node-types.json (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/parser.c (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/tree_sitter/alloc.h (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/tree_sitter/array.h (1 hunks)
- resources/language-metavariables/tree-sitter-php/src/tree_sitter/parser.h (1 hunks)
- resources/language-submodules/tree-sitter-php/.editorconfig (1 hunks)
- resources/language-submodules/tree-sitter-php/.eslintrc.js (1 hunks)
- resources/language-submodules/tree-sitter-php/.gitattributes (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/bug_report.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/config.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/feature_request.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/pull_request_template.md (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/workflows/ci.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/workflows/lint.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.github/workflows/release.yml (1 hunks)
- resources/language-submodules/tree-sitter-php/.gitignore (1 hunks)
Files not processed due to max files limit (29)
- resources/language-submodules/tree-sitter-php/Cargo.toml
- resources/language-submodules/tree-sitter-php/LICENSE
- resources/language-submodules/tree-sitter-php/Makefile
- resources/language-submodules/tree-sitter-php/Package.swift
- resources/language-submodules/tree-sitter-php/README.md
- resources/language-submodules/tree-sitter-php/binding.gyp
- resources/language-submodules/tree-sitter-php/bindings/c/tree-sitter-php_base.h
- resources/language-submodules/tree-sitter-php/bindings/c/tree-sitter-php_base.pc.in
- resources/language-submodules/tree-sitter-php/bindings/c/tree-sitter.h.in
- resources/language-submodules/tree-sitter-php/bindings/c/tree-sitter.pc.in
- resources/language-submodules/tree-sitter-php/bindings/go/binding.go
- resources/language-submodules/tree-sitter-php/bindings/go/binding_test.go
- resources/language-submodules/tree-sitter-php/bindings/node/binding.cc
- resources/language-submodules/tree-sitter-php/bindings/node/index.d.ts
- resources/language-submodules/tree-sitter-php/bindings/node/index.js
- resources/language-submodules/tree-sitter-php/bindings/node/php.js
- resources/language-submodules/tree-sitter-php/bindings/node/php_only.js
- resources/language-submodules/tree-sitter-php/bindings/python/tree_sitter_php_base/init.py
- resources/language-submodules/tree-sitter-php/bindings/python/tree_sitter_php_base/init.pyi
- resources/language-submodules/tree-sitter-php/bindings/python/tree_sitter_php_base/binding.c
- resources/language-submodules/tree-sitter-php/bindings/rust/README.md
- resources/language-submodules/tree-sitter-php/bindings/rust/build.rs
- resources/language-submodules/tree-sitter-php/bindings/rust/lib.rs
- resources/language-submodules/tree-sitter-php/bindings/swift/TreeSitterPHP/php.h
- resources/language-submodules/tree-sitter-php/bindings/swift/TreeSitterPhpBase/php_base.h
- resources/language-submodules/tree-sitter-php/common/define-grammar.js
- resources/language-submodules/tree-sitter-php/common/scanner.h
- resources/language-submodules/tree-sitter-php/common/test/corpus/bugs.txt
- resources/language-submodules/tree-sitter-php/common/test/corpus/class.txt
Files not summarized due to errors (1)
- resources/language-metavariables/tree-sitter-php/php/grammar.js: Error: Message exceeds token limit
Files skipped from review due to trivial changes (21)
- crates/language/src/lib.rs
- resources/language-metavariables/tree-sitter-php/.editorconfig
- resources/language-metavariables/tree-sitter-php/LICENSE
- resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter-php_base.pc.in
- resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.pc.in
- 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_base/init.py
- resources/language-metavariables/tree-sitter-php/build/binding.Makefile
- resources/language-metavariables/tree-sitter-php/build/config.gypi
- resources/language-metavariables/tree-sitter-php/common/test/corpus/literals.txt
- resources/language-metavariables/tree-sitter-php/php/Cargo.toml
- resources/language-metavariables/tree-sitter-php/pyproject.toml
- resources/language-metavariables/tree-sitter-php/src/tree_sitter/alloc.h
- resources/language-submodules/tree-sitter-php/.editorconfig
- resources/language-submodules/tree-sitter-php/.gitattributes
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/bug_report.yml
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/config.yml
- resources/language-submodules/tree-sitter-php/.github/ISSUE_TEMPLATE/feature_request.yml
- resources/language-submodules/tree-sitter-php/.github/pull_request_template.md
- resources/language-submodules/tree-sitter-php/.gitignore
Additional Context Used
Learnings (1)
resources/language-metavariables/tree-sitter-php/common/test/corpus/class.txt (1)
Readonly classes were introduced in PHP 8.2.
Additional comments not posted (129)
resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php_base/__init__.pyi (1)
1-1
: Thelanguage
function lacks documentation. In stub files, it's particularly important to document the purpose and usage of functions to aid developers in understanding the interface.resources/language-metavariables/tree-sitter-php/build/node_gyp_bins/python3 (1)
1-1
: Specifying a hard-coded path to the Python binary can lead to portability issues. Consider using environment variables or a configuration file to specify the Python interpreter path, making the build process more flexible and adaptable to different environments.resources/language-metavariables/tree-sitter-php/queries/injections-text.scm (1)
1-3
: The injection rules for setting the language to "html" appear correct. However, it's important to verify that these rules do not unintentionally override other injections or cause conflicts, especially in mixed-language files.resources/language-metavariables/tree-sitter-php/php_only/grammar.js (1)
1-3
: The modular approach to defining the grammar for "php_only" is good for maintainability. However, consider if the namingphp_only
accurately reflects the scope of this grammar module, especially if it's intended to support full PHP grammar.resources/language-metavariables/tree-sitter-php/src/node-types.json (1)
7-10
: The "hello" node type is unusual. Please verify its purpose and ensure it serves a meaningful role in the grammar. If it's a placeholder or example, consider removing it or documenting its intended use.resources/language-metavariables/tree-sitter-php/common/test/highlight/types.php (1)
1-9
: The syntax highlighting comments for built-in and custom types are a good practice for testing. Ensure that the test coverage is comprehensive and includes a wide range of PHP types to verify the syntax highlighter's behavior thoroughly.resources/language-metavariables/tree-sitter-php/bindings/node/index.js (1)
5-7
: Silently catching and ignoring errors when loadingnode-types.json
could hide potential issues. Consider logging the error or handling it in a way that provides more information to developers.resources/language-metavariables/tree-sitter-php/grammar.js (1)
7-10
: The grammar definition for "php_base" currently includes a placeholder rule forsource_file
. Ensure that the actual grammar rules are added to provide comprehensive PHP support. If this is a work in progress, consider documenting the current state and planned additions.resources/language-metavariables/tree-sitter-php/queries/injections.scm (1)
1-10
: The changes ininjections.scm
correctly define tree-sitter queries for handling PHP comments, heredoc, and nowdoc syntax. This is essential for enabling syntax highlighting and other language-specific features in PHP files. The use of@injection.content
and@injection.language
is appropriate for these contexts.resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter-php_base.h (1)
1-16
: The header filetree-sitter-php_base.h
is correctly structured with proper header guards and includes a clear declaration of thetree_sitter_php_base
function. This setup is essential for integrating PHP support into the project's C bindings.resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPhpBase/php_base.h (1)
1-16
: The Swift bindings header filephp_base.h
is correctly set up with appropriate header guards and a clear declaration fortree_sitter_php_base
. This ensures the PHP language support can be integrated into the project's Swift bindings.resources/language-metavariables/tree-sitter-php/php_only/package.json (1)
1-12
: Thepackage.json
file for PHP-only bindings is correctly structured, with valid JSON syntax and appropriate paths to the main entry point and tree-sitter query files. This configuration is crucial for the project's Node.js bindings to recognize and support PHP.resources/language-metavariables/tree-sitter-php/bindings/swift/TreeSitterPHP/php.h (1)
1-17
: The Swift bindings header filephp.h
is well-structured, with proper header guards and clear declarations fortree_sitter_php
andtree_sitter_php_only
. These declarations are essential for integrating full PHP support into the project's Swift bindings.resources/language-metavariables/tree-sitter-php/bindings/c/tree-sitter.h.in (1)
1-16
: The template header filetree-sitter.h.in
is correctly structured for generating C bindings for specific languages, with appropriate use of placeholders (@UPPER_PARSERNAME@
,@PARSERNAME@
) and header guards. This setup facilitates the addition of new language support, including PHP, to the project.resources/language-metavariables/tree-sitter-php/common/test/highlight/literals.php (1)
1-19
: The PHP test fileliterals.php
is well-prepared, containing a variety of syntax examples crucial for testing the project's syntax highlighting capabilities for PHP. The inclusion of heredoc, nowdoc, constants, and built-in constants ensures comprehensive coverage.resources/language-submodules/tree-sitter-php/.github/workflows/lint.yml (1)
1-19
: The GitHub Actions workflow filelint.yml
is correctly set up for linting the PHP language support code. It specifies appropriate triggers forpush
andpull_request
events and outlines the steps for checking out the code, installing dependencies, and running ESLint. This setup ensures code quality and consistency.resources/language-metavariables/tree-sitter-php/src/grammar.json (1)
1-20
: The grammar definition provided ingrammar.json
is minimal, likely serving as a starting point for PHP support. Ensure that this aligns with the project's goals for PHP language support and that there are plans for further development to expand this grammar to cover more PHP language constructs.resources/language-metavariables/tree-sitter-php/bindings/go/binding.go (1)
1-13
: The Go bindings for the PHP grammar are correctly set up, with appropriate CGO flags and the inclusion ofparser.c
. Ensure that the parser and any external scanners (if applicable) are fully integrated and that the naming conventions for theLanguage
function align with those used across other language bindings in the project.resources/language-metavariables/tree-sitter-php/php/package.json (1)
1-15
: The Node.js package configuration for the PHP grammar is correctly set up, with appropriate paths to syntax highlighting and injection files. Ensure that all referenced files exist and are correctly placed relative to thispackage.json
file.resources/language-metavariables/tree-sitter-php/bindings/go/binding_test.go (1)
1-15
: The test for loading the PHP grammar using Go bindings is correctly implemented. Ensure that this test is integrated into the project's continuous integration (CI) pipeline to automatically verify the grammar loading.resources/language-metavariables/tree-sitter-php/php/binding.gyp (1)
1-19
: The build configuration for the Node.js bindings of the PHP grammar is correctly set up, with appropriate include directories, sources, and C flags. Ensure that the build process is tested and works as expected, especially if there are external scanners or additional source files not mentioned here.resources/language-metavariables/tree-sitter-php/.eslintrc.js (1)
1-20
: The ESLint configuration for the PHP grammar project is correctly set up, aligning with modern JavaScript project standards. Ensure that this configuration aligns with the project's coding standards and that all team members are aware of these settings to maintain code consistency.resources/language-submodules/tree-sitter-php/.eslintrc.js (1)
1-20
: The ESLint configuration for this part of the PHP grammar project is correctly set up and consistent with the previous configuration reviewed. Ensure that these settings are in line with the project's coding standards and that there is consistency across different parts of the project.resources/language-metavariables/tree-sitter-php/php/bindings/node/index.js (1)
1-19
: The module export and error handling for requiring the compiled Node.js bindings for the PHP grammar are correctly implemented. Ensure that the compiled bindings andnode-types.json
are correctly generated during the build process and that the paths used here align with the project's directory structure.resources/language-metavariables/tree-sitter-php/binding.gyp (1)
14-14
: The comment about adding an external scanner if the language has one is helpful for future maintainers. If you plan to use an external scanner, remember to update this section accordingly.resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/tree_sitter_php_binding.node.d (1)
1-1
: It's unusual for build artifacts like this file to be included in a pull request, as they are typically generated during the build process and not manually edited. Ensure that including this file was intentional.resources/language-metavariables/tree-sitter-php/bindings/node/index.d.ts (1)
1-28
: The TypeScript definitions are well-structured and effectively use TypeScript features to represent the tree-sitter nodes and language information. This should provide a solid foundation for TypeScript developers working with the PHP grammar.resources/language-metavariables/tree-sitter-php/php/src/scanner.c (1)
1-17
: The implementation of the external scanner for PHP adheres to tree-sitter's external scanner API and follows good practices for consistency and maintainability. This should ensure reliable parsing and scanning of PHP code.resources/language-metavariables/tree-sitter-php/bindings/node/binding.cc (1)
1-20
: The Node.js binding for the PHP grammar is well-implemented using N-API, with clear and straightforward exports. The use of type tagging enhances type safety, making this a solid foundation for integrating the PHP grammar into Node.js applications.resources/language-metavariables/tree-sitter-php/php_only/src/scanner.c (1)
1-17
: The implementation of the external scanner for the PHP-only grammar is consistent with tree-sitter's external scanner API and follows good practices, similar to thescanner.c
for PHP. This consistency is beneficial for maintainability and reliability.resources/language-metavariables/tree-sitter-php/Cargo.toml (1)
1-29
: TheCargo.toml
file is well-configured, providing complete and informative package metadata, appropriate inclusion of components, and correctly specified dependencies. This configuration should ensure a smooth build process and integration of the tree-sitter PHP grammar into Rust projects.resources/language-metavariables/tree-sitter-php/Package.swift (1)
1-29
: ThePackage.swift
file is correctly configured, ensuring that the tree-sitter PHP grammar can be smoothly integrated into Swift projects. The specification of sources, resources, and C settings is appropriate and follows Swift packaging best practices.resources/language-metavariables/tree-sitter-php/bindings/python/tree_sitter_php_base/binding.c (1)
1-27
: The Python binding setup for the tree-sitter PHP grammar looks correct and follows the standard approach for creating Python C extensions. The method_binding_language
properly exposes the tree-sitter PHP language grammar to Python. Ensure that the corresponding Python package setup includes this module correctly for it to be accessible from Python code.resources/language-submodules/tree-sitter-php/.github/workflows/ci.yml (1)
1-37
: The CI workflow configuration is well-structured and covers a good range of operating systems. It's beneficial to ensure that the Node.js and Python versions specified are aligned with the project's requirements and compatibility. Additionally, consider caching dependencies (npm install
) to speed up the CI runs.resources/language-metavariables/tree-sitter-php/README.md (1)
1-15
: The README provides a concise overview of the tree-sitter PHP grammar and includes useful badges for quick access to resources. Ensure that all links and badges are up-to-date and accurately reflect the project's current status. Regarding the hint about a possible spelling mistake, it appears to be a false positive. The use of exclamation marks in badges is standard and not excessive.resources/language-metavariables/tree-sitter-php/common/test/highlight/keywords.php (1)
1-56
: The test file for syntax highlighting covers a wide range of PHP keywords, types, and class references, which is excellent for ensuring the highlighting functionality works as expected. It might be beneficial to add more complex PHP constructs or edge cases to further ensure the robustness of the syntax highlighting.resources/language-metavariables/tree-sitter-php/bindings/rust/build.rs (1)
1-29
: The Rust build script is correctly set up to compile the C sources for the PHP grammar. It's good practice to specify compiler flags that suppress warnings only when necessary. Ensure that all included directories and source files are essential for the build process to keep it efficient. Additionally, consider documenting the reason for suppressing specific warnings to maintain clarity for future maintainers.resources/language-metavariables/tree-sitter-php/php/bindings/node/binding.cc (1)
1-28
: The Node.js bindings for the tree-sitter PHP grammar are correctly set up using the Nan library. The grammar is properly exposed under the name "php", making it accessible for Node.js applications. Ensure that the binding is tested across different Node.js versions for compatibility.resources/language-metavariables/tree-sitter-php/queries/tags.scm (1)
1-40
: The semantic tagging definitions intags.scm
cover a broad range of PHP syntax elements, which is essential for enabling advanced editor features like code navigation and symbol search. Ensure that the tags are consistently applied across different PHP constructs and consider adding more specific tags for PHP 8 features to enhance support for newer PHP versions.resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php/src/parser.o.d (1)
1-5
: The build dependency file forparser.o
correctly specifies the command and dependencies for building the Node.js bindings. It's tailored for a macOS environment, as indicated by the macOS-specific compiler flags. Ensure that similar dependency files or configurations are available and correct for other platforms the project supports to maintain cross-platform compatibility.resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php_only/src/parser.o.d (1)
1-1
: Ensure cross-platform compatibility for the build command. Consider parameterizing or conditionally applying platform-specific flags (-mmacosx-version-min=10.15 -arch x86_64
) to support building on other operating systems.resources/language-metavariables/tree-sitter-php/php/bindings/rust/build.rs (1)
16-20
: Consider adding comments to explain the conditions under which the commented-out blocks for external scanners (C and C++) should be enabled. This documentation will help future developers understand when and why to use these blocks.resources/language-metavariables/tree-sitter-php/build/Release/.deps/Release/obj.target/tree_sitter_php_binding/php/src/scanner.o.d (1)
1-1
: Consider making the build process more flexible by avoiding hardcoded paths specific to a user's environment (e.g.,/Users/james/Library/Caches/node-gyp/18.12.1/...
). This change will enhance the portability and ease of building the project on different machines.resources/language-metavariables/tree-sitter-php/bindings/rust/README.md (1)
36-36
: Consider changing "in the [tree-sitter discussions] page" to "on the [tree-sitter discussions] page" for grammatical correctness.resources/language-metavariables/tree-sitter-php/setup.py (1)
17-22
: The custom wheel tagging to target a specific ABI ("cp38", "abi3"
) is a good practice for ensuring broader compatibility. Consider adding comments to document the rationale behind this choice for future maintainers.resources/language-metavariables/tree-sitter-php/php/bindings/rust/lib.rs (1)
36-41
: Consider adding comments to explain the conditions under which the commented-out constants for queries (HIGHLIGHTS_QUERY, INJECTIONS_QUERY, LOCALS_QUERY, TAGS_QUERY) should be enabled. This documentation will help future developers understand when and why to use these constants.resources/language-metavariables/tree-sitter-php/package.json (1)
1-81
: Thepackage.json
fortree-sitter-php
is well-structured and includes all necessary metadata for an npm package. It specifies dependencies, devDependencies, and scripts correctly. Thetree-sitter
configuration for PHP is also appropriately defined. Ensure that the version numbers for dependencies are up-to-date and compatible with the project's requirements.crates/lsp/src/language.rs (2)
24-24
: Added support for PHP inlanguage_id_to_pattern_language
function. This correctly maps the "php" language ID to its correspondingPatternLanguage
enum variant.
52-52
: Added support for PHP intarget_language_to_language_id
function. This correctly maps theTargetLanguage::Php
variant to the "php" language ID.resources/language-metavariables/tree-sitter-php/bindings/rust/lib.rs (1)
1-61
: The Rust bindings fortree-sitter-php
are correctly implemented. The use ofunsafe
blocks is necessary for calling the external C functions provided by the tree-sitter grammar. Constants for node types and queries are appropriately defined. Ensure that the paths ininclude_str!
macros are correct and that the files exist at those paths.resources/language-metavariables/tree-sitter-php/queries/highlights.scm (1)
1-124
: The syntax highlighting queries for PHP are comprehensive, covering a wide range of syntax elements including variables, functions, types, and keywords. Ensure that these queries are tested with various PHP code snippets to verify their correctness and completeness.crates/language/Cargo.toml (2)
30-30
: Addedtree-sitter-php
as an optional dependency. Ensure that the path specified is correct and that the version oftree-sitter-php
is compatible with the project's requirements.
68-68
: Includedtree-sitter-php
in thebuiltin-parser
feature. This correctly enables PHP support when thebuiltin-parser
feature is enabled.crates/language/src/php.rs (1)
1-106
: The implementation of thePhp
struct and theLanguage
trait for PHP is correct and follows Rust best practices. The functions for getting language-specific information are appropriately defined. Ensure that the snippet context strings cover common PHP usage scenarios and that the test case is expanded to cover more PHP syntax elements.resources/language-submodules/tree-sitter-php/.github/workflows/release.yml (1)
1-103
: The GitHub Actions workflow for releasingtree-sitter-php
is well-structured and includes all necessary steps for the release process. Ensure that the version check logic correctly identifies when a version bump has occurred and that the NPM and Crates.io publishing steps are configured with the correct credentials. Also, verify that the tagging step correctly handles existing tags.resources/language-metavariables/tree-sitter-php/Makefile (1)
1-113
: The Makefile fortree-sitter-php
is correctly set up to build the library, generate bindings, and install the library and bindings. Ensure that the version number and paths are correct and that the OS-specific configurations are appropriately handled. Also, verify that the library and bindings are tested on the target platforms.resources/language-metavariables/tree-sitter-php/src/parser.c (1)
1-175
: The implementation of the Tree-sitter parser for PHP inparser.c
appears to be correctly structured and follows the necessary conventions for defining symbols, lexer states, and parse actions. The code is readable and maintainable. Good job on keeping the code clean and well-documented.resources/language-metavariables/tree-sitter-php/php/test/corpus/interpolation.txt (1)
1-244
: The test cases for PHP interpolation ininterpolation.txt
are comprehensive and well-structured, covering a wide range of scenarios. This thorough testing ensures the parser's robust handling of PHP code. Great work on maintaining clarity and consistency in the test file.resources/language-metavariables/tree-sitter-php/common/test/corpus/execution_operator.txt (1)
1-190
: The test cases for the execution operator in PHP withinexecution_operator.txt
are comprehensive and well-structured, covering a broad spectrum of scenarios. This ensures the parser's accurate handling of execution operators in PHP code. Excellent work on maintaining clarity and consistency in the test file.resources/language-metavariables/tree-sitter-php/php/src/tree_sitter/parser.h (1)
1-230
: Theparser.h
file for the Tree-sitter PHP parser is well-structured, providing clear definitions for structures, enums, and macros necessary for the parser's operation. The code is maintainable and adheres to best practices in C programming. Good job on keeping the code organized and readable.resources/language-metavariables/tree-sitter-php/php_only/src/tree_sitter/parser.h (1)
1-230
: Theparser.h
file in thephp_only/src/tree_sitter/
directory appears to be a duplicate of the one reviewed earlier. While the file itself is well-structured and follows best practices, it's important to verify that this duplication is intentional and necessary for the project's structure. If not, consider consolidating to a singleparser.h
to reduce maintenance overhead.resources/language-metavariables/tree-sitter-php/src/tree_sitter/parser.h (1)
1-230
: Theparser.h
file in this directory is another instance similar to the ones previously reviewed. While the file is well-structured, the duplication ofparser.h
across different directories should be verified for necessity to ensure maintainability and reduce potential confusion.resources/language-metavariables/tree-sitter-php/build/tree_sitter_php_binding.target.mk (1)
53-61
: The makefile correctly defines the build process for the Tree-sitter PHP binding, including compiler flags and linking options for both debug and release builds. However, the hardcoded paths inINCS_Debug
andINCS_Release
could limit the portability of the build process. Consider using relative paths or variables that can be set externally to enhance portability.Also applies to: 107-116
resources/language-metavariables/tree-sitter-php/common/test/corpus/bugs.txt (5)
5-22
: The test case for usingself
as a constant is well-formed and correctly tests the parser's ability to handle unusual but valid PHP code. However, it's important to remember thatself
has special meaning in PHP when used within class contexts. This test case is valid since it's outside a class context, but adding a comment to clarify this might help maintainers understand the intent and scope of the test.
28-49
: This test case correctly demonstrates the precedence of the error suppression operator in PHP. It's a good practice to include such edge cases in the test suite to ensure the parser accurately reflects PHP's behavior. No changes are needed here.
55-165
: The extensive testing of named arguments using PHP reserved keywords is thorough and covers a wide range of potential edge cases. This is crucial for ensuring the parser can handle named arguments correctly, especially with PHP's evolving syntax. Given the introduction of readonly classes in PHP 8.2, consider adding a test case forreadonly
as a named argument to ensure future compatibility.
171-210
: The handling of PHP closing tags within strings and heredoc/nowdoc syntax is correctly tested here. These scenarios are important to cover due to their potential to cause parsing errors if not handled properly. The test cases are well-constructed and should remain as is.
216-232
: This test case demonstrates the parser's ability to handle comments within a binary expression, which is a subtle but important aspect of PHP syntax. It's good to see such nuanced cases being tested, ensuring the parser's robustness. No changes are needed here.crates/core/src/snapshots/marzano_core__test__basic_php.snap.new (1)
1-66
: The snapshot file correctly represents a structured test case, including both original and rewritten states. This aligns well with the PR's objective of adding PHP support and ensuring its functionality through testing.crates/gritmodule/src/patterns_directory.rs (5)
29-29
: The addition of thephp
field to thePatternsDirectory
struct is correctly implemented. This change is essential for storing and handling PHP patterns, aligning with the PR's objective of adding PHP support.
84-84
: The initialization of thephp
field in thePatternsDirectory::new
method is correctly done, ensuring that PHP patterns can be stored and managed effectively.
114-114
: The update toget_language_directory_mut
method to include a case forPatternLanguage::Php
ensures that PHP patterns can be modified as needed, which is crucial for the dynamic handling of patterns.
141-141
: The inclusion ofPatternLanguage::Php
in theget_language_directory
method ensures that PHP patterns can be retrieved correctly, facilitating their use in pattern matching and other operations.
258-259
: The update to themerge
method to include thephp
field ensures that PHP patterns can be merged from anotherPatternsDirectory
instance, maintaining consistency and completeness of pattern data.resources/edit_grammars.mjs (2)
60-60
: The inclusion ofphp
in theallLanguages
array is correctly done, ensuring that PHP is considered in the grammar editing process. This is a necessary step for integrating PHP support into the project.
289-304
: The addition of a build script for PHP correctly implements the necessary steps for handling PHP grammar, including copying metavariable grammar and scanner files, generating tree-sitter grammar, and handling output node types and wasm parser. This ensures that PHP support is properly integrated into the project's grammar editing process.resources/language-metavariables/tree-sitter-php/common/test/corpus/types.txt (1)
1-461
: The test cases intypes.txt
cover a comprehensive range of PHP type features, including primitive types, intersection types, disjunctive normal form types, optional types, union types, mixed type, static type, null type, false type, and true type. These tests are crucial for verifying the parser's ability to handle PHP's type system correctly.resources/language-metavariables/tree-sitter-php/common/test/corpus/statements.txt (1)
1-445
: The test cases instatements.txt
cover a comprehensive range of PHP statement constructs, including if statements, while statements, for statements, switch statements, include statement, do-while statements, try statements, foreach statements, and more. These tests are essential for verifying the parser's ability to handle PHP's statement syntax correctly.resources/language-metavariables/tree-sitter-php/src/tree_sitter/array.h (2)
40-40
: Usingassert
for bounds checking inarray_get
only provides safety in debug builds. Consider implementing additional runtime checks for release builds to prevent out-of-bounds access.
163-168
: The file uses custom memory management functions (ts_malloc
,ts_realloc
,ts_free
). It's important to ensure these functions handle memory allocation failures gracefully and maintain consistency in memory management across the project.crates/wasm-bindings/src/match_pattern.rs (3)
43-43
: The addition of thePHP_LANGUAGE
constant is a necessary step for integrating PHP support into the system. This constant follows the established pattern for language support within the file, ensuring consistency.
367-367
: The update topattern_language_to_path
function to include a case forPatternLanguage::Php
is crucial for enabling the system to locate and use the PHP parser. This change is consistent with the handling of other languages and is necessary for the integration of PHP support.
410-410
: The addition ofPatternLanguage::Php
to theget_lang_store
function ensures that the PHP language parser can be cached and reused efficiently. This is an important update for performance and consistency with the handling of other languages.resources/language-metavariables/tree-sitter-php/common/test/corpus/class.txt (1)
778-797
: The addition of tests forreadonly class
is noted. However, it's important to mention thatreadonly
classes were introduced in PHP 8.2. Ensure that the testing environment or documentation specifies the PHP version requirement to avoid confusion or errors in environments running earlier PHP versions.resources/language-metavariables/tree-sitter-php/common/scanner.h (1)
91-92
: Creating a new string initializes its capacity to 16 and allocates memory accordingly. This is a good practice for avoiding frequent reallocations for small strings. However, consider making the initial capacity configurable or based on typical use cases to optimize memory usage and performance.crates/language/src/target_language.rs (15)
24-24
: The addition ofPhp
to the import list is correct and necessary for integrating PHP support into the project.
77-77
: AddingPhp
to thePatternLanguage
enum is a crucial step for recognizing PHP as a valid language option within the project.
106-106
: Correctly updating thefmt::Display
implementation forPatternLanguage
to includePhp
ensures that PHP is properly represented as a string when needed.
134-134
: Properly mappingTargetLanguage::Php(_)
toPatternLanguage::Php
in theFrom<&TargetLanguage>
implementation is essential for the correct functioning of language-specific features.
162-162
: EnsuringPhp
is initialized correctly in theis_initialized
method ofPatternLanguage
is important for managing language-specific initializations.
258-258
: Adding PHP file extensions to theget_file_extensions
method ofPatternLanguage
is necessary for correctly identifying PHP files in the project.
285-285
: Correctly setting the default file extension for PHP in theget_default_extension
method ofPatternLanguage
ensures that PHP files are handled appropriately.
309-309
: Adding PHP to thefrom_extension
method ofPatternLanguage
is crucial for recognizing PHP files based on their extension.
473-475
: Ensuring PHP file types are selected in theexpand_paths
function when PHP is a target language is important for correctly processing PHP files in the project.
523-523
: AddingPhp(Php)
to theTargetLanguage
enum is essential for supporting PHP as a target language in the project.
556-556
: Correctly handling PHP in theTryFrom<PatternLanguage>
implementation forTargetLanguage
is crucial for converting between pattern and target languages.
587-587
: Updating thefmt::Display
implementation forTargetLanguage
to includePhp
ensures that PHP is properly represented as a string when needed.
631-631
: EnsuringTargetLanguage::Php(_)
correctly maps toPatternLanguage::Php
in theto_module_language
method is important for maintaining consistency between pattern and target languages.
657-657
: Correctly setting theshould_pad_snippet
method for PHP ensures that PHP snippets are handled appropriately in the context of the project.
683-683
: Updating themake_single_line_comment
method to include PHP ensures that single-line comments are correctly generated for PHP code snippets.resources/language-metavariables/tree-sitter-php/build/gyp-mac-tool (6)
1-7
: The shebang line correctly specifies Python 3, ensuring compatibility with Python 3 environments. This is important for maintaining forward compatibility as Python 2 is deprecated.
27-31
: Themain
function correctly dispatches arguments to theMacTool
class and handles the exit code. This structure is clear and maintainable.
50-76
: The methodExecCopyBundleResource
handles various types of resources with specific logic for each. The use ofshutil
for file operations is appropriate. However, the comment on lines 57-59 suggests an inconsistency in handling file attributes between directory and file copies. It would be beneficial to address this TODO for consistency.
89-111
: The conditional block handlingXCODE_VERSION_ACTUAL
and deployment targets uses environment variables without validation. Ensure that these environment variables are sanitized upstream or add checks to prevent potential misuse or errors due to unexpected values.
148-158
: The use ofCoreFoundation
for handling.strings
files is macOS-specific and relies on system libraries. This approach is efficient but limits the portability of the script. If cross-platform compatibility is a goal, consider alternatives that do not rely on macOS-specific features.
693-698
: The standalone functionWriteHmap
is well-documented and implements a specific functionality related to header maps. This function demonstrates good separation of concerns by isolating this logic from the main class.resources/language-metavariables/tree-sitter-php/common/test/corpus/expressions.txt (4)
498-498
: The line498
demonstrates nested assignments within array subscript expressions. While this is syntactically correct in PHP, it's important to ensure that the intention is clear and that there are no unintended side effects, especially with complex expressions involving array subscripts.Please verify that the nested assignments are intentional and review their impact on code readability and maintainability.
518-519
: Lines518-519
contain complex expressions with multiple operators, including binary operations, assignments, and type casting. It's crucial to ensure that the operator precedence is correctly understood and that parentheses are used where necessary to clarify the order of operations.
606-606
: The expression on line606
demonstrates concatenation followed by addition. In PHP, the concatenation operator.
has the same precedence as+
, and both are left-associative. This can lead to unexpected results if not carefully handled.Please verify the intended order of operations in this expression and consider adding parentheses for clarity.
1153-1153
: The expression on line1153
demonstrates the precedence between concatenation and shift operators. It's important to ensure that the intended order of operations is clear, as operator precedence can affect the result.Please verify the intended order of operations in this expression and consider adding parentheses for clarity.
resources/language-metavariables/tree-sitter-php/common/define-grammar.js (5)
46-49
: The dialect check ensures that only 'php' or 'php_only' are accepted as valid dialects. This is a good practice for validating input parameters and preventing unexpected behavior. However, consider documenting the expected dialects and their differences or intended use cases to provide clarity for future contributors or users of this grammar definition.
51-1573
: The grammar definition is comprehensive and covers a wide range of PHP syntax. It's well-structured and follows a consistent pattern for defining rules, which aids in readability and maintainability. However, given the extensive nature of this file, consider splitting it into smaller, more focused modules if the tree-sitter grammar allows for such modularization. This could improve maintainability and make it easier to navigate and understand specific parts of the PHP grammar.
1584-1589
: Thekeyword
function provides a flexible way to define keywords in a case-insensitive manner and optionally alias them. This is a clever use of regular expressions and the tree-sitteralias
function to simplify grammar rule definitions. Ensure that all keywords defined using this function are indeed intended to be case-insensitive, as this aligns with PHP's handling of keywords but might not be appropriate for all tokens.
1599-1601
: ThecommaSep1
function is a useful utility for defining grammar rules that require one or more occurrences of a rule separated by commas. This pattern is common in many programming languages, and encapsulating it in a helper function reduces repetition and enhances readability. Good job on abstracting common patterns into reusable functions.
1545-1548
: The regex pattern for PHP names is designed to accommodate a wide range of characters, including multi-byte characters. This is a thoughtful approach to align with PHP's behavior regarding identifiers. However, it's important to ensure that this broad character range does not inadvertently allow invalid identifiers according to PHP's specification. Consider adding tests specifically targeting edge cases around identifier names to ensure compliance with PHP's rules.resources/language-metavariables/tree-sitter-php/php/grammar.js (3)
44-44
: The introduction ofgrit_metavariable
with a precedence value of 100 is notable. Ensure that this addition aligns with the project's goals for PHP support and that the precedence value does not conflict with existing language constructs.
1527-1527
: The usage ofgrit_metavariable
invariable_name
rule suggests a flexible approach to variable naming. Confirm that this flexibility is intended and properly documented, especially regarding how it interacts with PHP's variable naming rules.
1667-1667
: The definition ofgrit_metavariable
using a token with a specific pattern (µ...
,/µ[a-zA-Z_][a-zA-Z0-9_]*/
) is an interesting addition. Ensure that the use of this metavariable is clearly documented, including its purpose and how it should be used within the grammar.crates/core/src/test.rs (11)
2819-2845
: The testphp_include_to_require
correctly demonstrates the transformation frominclude
torequire
in PHP. However, it's important to ensure that the test covers edge cases, such as when theinclude
statement is within a conditional or loop, to fully validate the transformation logic.Consider adding more comprehensive test cases to cover edge cases and ensure the transformation logic is robust.
2847-2871
: Thephp_extends_component_snippet
test is well-structured and tests class extension in PHP. It's crucial to also verify that the transformation handles more complex inheritance scenarios, such as multiple levels of inheritance or the use of interfaces.Please verify that the transformation logic correctly handles complex inheritance scenarios and consider adding additional test cases if necessary.
2891-2915
: Thephp_switch_statement
test effectively checks the transformation of a switch statement. Ensure that the test also covers scenarios with multiple cases, default cases, and nested switch statements to fully validate the transformation logic.Consider expanding the test to include more complex switch statement scenarios.
2917-2938
: Thephp_while_loop
test is correctly implemented. To further ensure the robustness of the transformation logic, consider adding tests for while loops with complex conditions and nested loops.Please verify the transformation logic for while loops with complex conditions and nested loops, adding additional test cases as needed.
2940-2962
: Thephp_for_loop
test checks the basic for loop transformation. It would be beneficial to also test for loops with more complex initialization, condition, and increment expressions.Consider adding test cases for for loops with complex expressions to ensure comprehensive coverage.
2964-2985
: Thephp_foreach_loop
test is well-implemented. To enhance the test coverage, consider including foreach loops that iterate over associative arrays and use both key and value.Please verify the transformation logic for foreach loops over associative arrays and consider adding relevant test cases.
2987-3006
: Thephp_function_snippet
test correctly tests function definition in PHP. It's important to also test functions with various types of parameters (e.g., type-hinted, default values) and return types to ensure the transformation logic is comprehensive.Consider adding test cases for functions with different parameter and return types.
3008-3027
: Thephp_if_statement_snippet
test is well-structured. To ensure thorough testing, consider adding tests for if statements with else and else if branches, as well as nested if statements.Please verify the transformation logic for if statements with additional branches and nested conditions, adding more test cases as necessary.
3030-3044
: Thephp_function_call_snippet
test checks a basic function call. It would be beneficial to also test function calls with multiple arguments, named arguments (PHP 8+), and function calls within expressions.Consider expanding the test to include more complex function call scenarios.
3046-3061
: Thephp_assignment_snippet
test is correctly implemented. To further ensure the robustness of the transformation logic, consider adding tests for assignments involving complex expressions and compound assignment operators.Please verify the transformation logic for complex assignments and consider adding additional test cases as needed.
3063-3084
: Thephp_test_conditional_snippet
test demonstrates a transformation from an if statement to a single-line expression. Ensure that the test covers scenarios with more complex conditions and nested if statements to fully validate the transformation logic.Consider adding more comprehensive test cases to cover complex and nested conditions.
(name)))) | ||
body: (compound_statement))) | ||
) | ||
) | ||
|
||
|
||
======================================= | ||
Enums | ||
======================================= | ||
|
||
<?php | ||
|
||
enum A {} | ||
enum B implements Bar, Baz { | ||
} | ||
enum C: int implements Bar {} | ||
|
||
enum Suit: string | ||
{ | ||
case Hearts = 'H'; | ||
case Diamonds; | ||
case Clubs = "C"; | ||
case Spades = <<<TXT | ||
S | ||
TXT; | ||
|
||
// Fulfills the interface contract. | ||
public function color(): string { | ||
return match($this) { | ||
Suit::Hearts, Suit::Diamonds => 'Red', | ||
Suit::Clubs, Suit::Spades => 'Black', | ||
}; | ||
} | ||
} | ||
|
||
--- | ||
|
||
(program | ||
(php_tag) | ||
(enum_declaration | ||
(name) | ||
(enum_declaration_list) | ||
) | ||
(enum_declaration | ||
(name) | ||
(class_interface_clause | ||
(name) | ||
(name) | ||
) | ||
(enum_declaration_list) | ||
) | ||
(enum_declaration | ||
(name) | ||
(primitive_type) | ||
(class_interface_clause (name)) | ||
(enum_declaration_list) | ||
) | ||
(enum_declaration | ||
(name) | ||
(primitive_type) | ||
(enum_declaration_list | ||
(enum_case (name) (string (string_value))) | ||
(enum_case (name)) | ||
(enum_case (name) (encapsed_string (string_value))) | ||
(enum_case (name) (heredoc (heredoc_start) (heredoc_body (string_value)) (heredoc_end))) | ||
(comment) | ||
(method_declaration | ||
(visibility_modifier) | ||
(name) | ||
(formal_parameters) | ||
(primitive_type) | ||
(compound_statement | ||
(return_statement | ||
(match_expression | ||
(parenthesized_expression | ||
(variable_name (name)) | ||
) | ||
(match_block | ||
(match_conditional_expression | ||
(match_condition_list | ||
(class_constant_access_expression (name) (name)) | ||
(class_constant_access_expression (name) (name)) | ||
) | ||
(string (string_value)) | ||
) | ||
(match_conditional_expression | ||
(match_condition_list | ||
(class_constant_access_expression (name) (name)) | ||
(class_constant_access_expression (name) (name)) | ||
) | ||
(string (string_value)) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases provided in declarations.txt
cover a wide range of PHP language constructs, ensuring comprehensive testing of the project's PHP support. This includes interface declarations, class declarations, function parameters, and more. It's important to ensure these tests are kept up-to-date with the latest PHP features, such as readonly classes introduced in PHP 8.2, to maintain compatibility and correctness.
Would you like to add test cases for readonly classes, introduced in PHP 8.2, to ensure coverage of this new feature?
crates/core/src/test.rs
Outdated
#[test] | ||
fn php_equals_zero_snippet_test() { | ||
run_test_match({ | ||
TestArg { | ||
pattern: r#" | ||
|engine marzano(0.1) | ||
|language php | ||
|`exit($a);`"# | ||
.trim_margin() | ||
.unwrap(), | ||
source: r#"<?php | ||
|exit(1); | ||
|?>"#.to_string(), | ||
} | ||
}) | ||
.unwrap(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The php_equals_zero_snippet_test
seems to be misnamed or the test content does not match the intended purpose. The test name suggests testing equality comparison, but the test content is about the exit
function.
Please correct the test name or content to accurately reflect the test's purpose.
@@ -12915,4 +13183,4 @@ | |||
.unwrap(), | |||
}) | |||
.unwrap(); | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears there's an incomplete test function at the end of the file. This could be an accidental inclusion or an unfinished test case.
Please complete or remove the unfinished test function to maintain code cleanliness and avoid potential confusion.
def Dispatch(self, args): | ||
"""Dispatches a string command to a method.""" | ||
if len(args) < 1: | ||
raise Exception("Not enough arguments") | ||
|
||
method = "Exec%s" % self._CommandifyName(args[0]) | ||
return getattr(self, method)(*args[1:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dispatch
method uses a dynamic method resolution strategy based on the first argument. While this is flexible, it could potentially lead to security concerns if untrusted input is passed as arguments. Consider validating the args[0]
against a list of allowed commands before proceeding.
# Go through all the environment variables and replace them as variables in | ||
# the file. | ||
IDENT_RE = re.compile(r"[_/\s]") | ||
for key in os.environ: | ||
if key.startswith("_"): | ||
continue | ||
evar = "${%s}" % key | ||
evalue = os.environ[key] | ||
lines = lines.replace(lines, evar, evalue) | ||
|
||
# Xcode supports various suffices on environment variables, which are | ||
# all undocumented. :rfc1034identifier is used in the standard project | ||
# template these days, and :identifier was used earlier. They are used to | ||
# convert non-url characters into things that look like valid urls -- | ||
# except that the replacement character for :identifier, '_' isn't valid | ||
# in a URL either -- oops, hence :rfc1034identifier was born. | ||
evar = "${%s:identifier}" % key | ||
evalue = IDENT_RE.sub("_", os.environ[key]) | ||
lines = lines.replace(lines, evar, evalue) | ||
|
||
evar = "${%s:rfc1034identifier}" % key | ||
evalue = IDENT_RE.sub("-", os.environ[key]) | ||
lines = lines.replace(lines, evar, evalue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method for replacing environment variables in ExecCopyInfoPlist
could lead to unintended replacements due to the use of lines.replace(lines, evar, evalue)
, which seems incorrect. The intended operation is likely lines.replace(evar, evalue)
. Additionally, this method does not handle cases where environment variables are not found, potentially leaving unresolved placeholders.
- lines = lines.replace(lines, evar, evalue)
+ lines = lines.replace(evar, evalue)
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.
# Go through all the environment variables and replace them as variables in | |
# the file. | |
IDENT_RE = re.compile(r"[_/\s]") | |
for key in os.environ: | |
if key.startswith("_"): | |
continue | |
evar = "${%s}" % key | |
evalue = os.environ[key] | |
lines = lines.replace(lines, evar, evalue) | |
# Xcode supports various suffices on environment variables, which are | |
# all undocumented. :rfc1034identifier is used in the standard project | |
# template these days, and :identifier was used earlier. They are used to | |
# convert non-url characters into things that look like valid urls -- | |
# except that the replacement character for :identifier, '_' isn't valid | |
# in a URL either -- oops, hence :rfc1034identifier was born. | |
evar = "${%s:identifier}" % key | |
evalue = IDENT_RE.sub("_", os.environ[key]) | |
lines = lines.replace(lines, evar, evalue) | |
evar = "${%s:rfc1034identifier}" % key | |
evalue = IDENT_RE.sub("-", os.environ[key]) | |
lines = lines.replace(lines, evar, evalue) | |
# Go through all the environment variables and replace them as variables in | |
# the file. | |
IDENT_RE = re.compile(r"[_/\s]") | |
for key in os.environ: | |
if key.startswith("_"): | |
continue | |
evar = "${%s}" % key | |
evalue = os.environ[key] | |
lines = lines.replace(evar, evalue) | |
# Xcode supports various suffices on environment variables, which are | |
# all undocumented. :rfc1034identifier is used in the standard project | |
# template these days, and :identifier was used earlier. They are used to | |
# convert non-url characters into things that look like valid urls -- | |
# except that the replacement character for :identifier, '_' isn't valid | |
# in a URL either -- oops, hence :rfc1034identifier was born. | |
evar = "${%s:identifier}" % key | |
evalue = IDENT_RE.sub("_", os.environ[key]) | |
lines = lines.replace(evar, evalue) | |
evar = "${%s:rfc1034identifier}" % key | |
evalue = IDENT_RE.sub("-", os.environ[key]) | |
lines = lines.replace(evar, evalue) |
#define VEC_POP(vec) \ | ||
{ \ | ||
STRING_FREE(VEC_BACK((vec)).word); \ | ||
(vec).len--; \ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The VEC_POP
macro frees the string word
within the Heredoc
struct but does not explicitly set the pointer to NULL
after freeing. This could potentially lead to use-after-free errors if not handled carefully elsewhere in the code.
- STRING_FREE(VEC_BACK((vec)).word);
+ STRING_FREE(VEC_BACK((vec)).word);
+ VEC_BACK((vec)).word.data = NULL;
+ VEC_BACK((vec)).word.len = 0;
+ VEC_BACK((vec)).word.cap = 0;
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.
#define VEC_POP(vec) \ | |
{ \ | |
STRING_FREE(VEC_BACK((vec)).word); \ | |
(vec).len--; \ | |
} | |
#define VEC_POP(vec) \ | |
{ \ | |
STRING_FREE(VEC_BACK((vec)).word); \ | |
VEC_BACK((vec)).word.data = NULL; \ | |
VEC_BACK((vec)).word.len = 0; \ | |
VEC_BACK((vec)).word.cap = 0; \ | |
(vec).len--; \ | |
} |
static HeredocVec vec_new() { | ||
HeredocVec vec = {0, 0, NULL}; | ||
vec.data = calloc(1, sizeof(Heredoc)); | ||
vec.cap = 1; | ||
return vec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When creating a new HeredocVec
, memory is allocated for a single Heredoc
element even if it might not be immediately used. This could be optimized by delaying allocation until an element is actually pushed onto the vector.
- vec.data = calloc(1, sizeof(Heredoc));
- vec.cap = 1;
+ vec.data = NULL; // Allocate on first push
+ vec.cap = 0;
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.
static HeredocVec vec_new() { | |
HeredocVec vec = {0, 0, NULL}; | |
vec.data = calloc(1, sizeof(Heredoc)); | |
vec.cap = 1; | |
return vec; | |
static HeredocVec vec_new() { | |
HeredocVec vec = {0, 0, NULL}; | |
vec.data = NULL; // Allocate on first push | |
vec.cap = 0; | |
return vec; |
static inline void *external_scanner_create() { | ||
Scanner *scanner = calloc(1, sizeof(Scanner)); | ||
scanner->open_heredocs = vec_new(); | ||
return scanner; | ||
} | ||
|
||
static inline unsigned external_scanner_serialize(void *payload, char *buffer) { | ||
Scanner *scanner = (Scanner *)payload; | ||
return serialize(scanner, buffer); | ||
} | ||
|
||
static inline void external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { | ||
Scanner *scanner = (Scanner *)payload; | ||
deserialize(scanner, buffer, length); | ||
} | ||
|
||
static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { | ||
Scanner *scanner = (Scanner *)payload; | ||
return scan(scanner, lexer, valid_symbols); | ||
} | ||
|
||
static inline void external_scanner_destroy(void *payload) { | ||
Scanner *scanner = (Scanner *)payload; | ||
for (size_t i = 0; i < scanner->open_heredocs.len; i++) { | ||
STRING_FREE(scanner->open_heredocs.data[i].word); | ||
} | ||
VEC_FREE(scanner->open_heredocs) | ||
free(scanner); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external_scanner_destroy
function correctly frees the memory allocated for the scanner and its components. It's good practice to also set the pointer to NULL
after freeing to prevent potential use-after-free errors.
free(scanner);
+ scanner = NULL;
Note: This change assumes scanner
is passed by reference to the function, which is not the case here. The suggestion is more about the general practice of setting freed pointers to NULL
in the calling context.
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.
static inline void *external_scanner_create() { | |
Scanner *scanner = calloc(1, sizeof(Scanner)); | |
scanner->open_heredocs = vec_new(); | |
return scanner; | |
} | |
static inline unsigned external_scanner_serialize(void *payload, char *buffer) { | |
Scanner *scanner = (Scanner *)payload; | |
return serialize(scanner, buffer); | |
} | |
static inline void external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { | |
Scanner *scanner = (Scanner *)payload; | |
deserialize(scanner, buffer, length); | |
} | |
static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { | |
Scanner *scanner = (Scanner *)payload; | |
return scan(scanner, lexer, valid_symbols); | |
} | |
static inline void external_scanner_destroy(void *payload) { | |
Scanner *scanner = (Scanner *)payload; | |
for (size_t i = 0; i < scanner->open_heredocs.len; i++) { | |
STRING_FREE(scanner->open_heredocs.data[i].word); | |
} | |
VEC_FREE(scanner->open_heredocs) | |
free(scanner); | |
} | |
static inline void *external_scanner_create() { | |
Scanner *scanner = calloc(1, sizeof(Scanner)); | |
scanner->open_heredocs = vec_new(); | |
return scanner; | |
} | |
static inline unsigned external_scanner_serialize(void *payload, char *buffer) { | |
Scanner *scanner = (Scanner *)payload; | |
return serialize(scanner, buffer); | |
} | |
static inline void external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { | |
Scanner *scanner = (Scanner *)payload; | |
deserialize(scanner, buffer, length); | |
} | |
static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { | |
Scanner *scanner = (Scanner *)payload; | |
return scan(scanner, lexer, valid_symbols); | |
} | |
static inline void external_scanner_destroy(void *payload) { | |
Scanner *scanner = (Scanner *)payload; | |
for (size_t i = 0; i < scanner->open_heredocs.len; i++) { | |
STRING_FREE(scanner->open_heredocs.data[i].word); | |
} | |
VEC_FREE(scanner->open_heredocs) | |
free(scanner); | |
} |
============================== | ||
If statement | ||
============================== | ||
|
||
if ($a==0) { | ||
echo "bad"; | ||
} elseif ($a==3) { | ||
echo "bad"; | ||
} else { | ||
echo "good"; | ||
} | ||
|
||
--- | ||
|
||
(program | ||
(if_statement | ||
condition: (parenthesized_expression (binary_expression | ||
left: (variable_name (name)) | ||
right: (integer))) | ||
body: (compound_statement (echo_statement (encapsed_string (string_value)))) | ||
alternative: (else_if_clause | ||
condition: (parenthesized_expression (binary_expression | ||
left: (variable_name (name)) | ||
right: (integer))) | ||
body: (compound_statement (echo_statement (encapsed_string (string_value))))) | ||
alternative: (else_clause | ||
body: (compound_statement (echo_statement (encapsed_string (string_value))))))) | ||
|
||
========================================= | ||
Class | ||
========================================= | ||
|
||
class A { | ||
public function a() {} | ||
abstract public function b(); | ||
} | ||
|
||
--- | ||
|
||
(program | ||
(class_declaration | ||
(name) | ||
(declaration_list | ||
(method_declaration | ||
(visibility_modifier) | ||
(name) | ||
(formal_parameters) | ||
(compound_statement) | ||
) | ||
(method_declaration | ||
(abstract_modifier) | ||
(visibility_modifier) | ||
(name) | ||
(formal_parameters) | ||
) | ||
) | ||
) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding test cases for readonly classes, introduced in PHP 8.2, to ensure comprehensive coverage of PHP features.
Would you like me to help by adding some test cases for readonly classes?
endif | ||
|
||
quiet_cmd_regen_makefile = ACTION Regenerating $@ | ||
cmd_regen_makefile = cd $(srcdir); /usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/james/Library/Caches/node-gyp/18.12.1" "-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/james/Library/Caches/node-gyp/18.12.1/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/james/node_modules/tree-sitter-php" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/james/node_modules/tree-sitter-php/build/config.gypi -I/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/james/Library/Caches/node-gyp/18.12.1/include/node/common.gypi "--toplevel-dir=." binding.gyp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command cmd_regen_makefile
contains hard-coded paths, which could affect the portability and flexibility of the build process. Consider using variables for paths like node-gyp
directory and node
version to make the build process more adaptable to different environments.
* 'main' of https://github.com/digital-phoenix/gritql: fix: update typescript wasm (#119) feat: Css in vue (#108)
There was a problem hiding this 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
Files selected for processing (1)
- crates/core/src/test.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/core/src/test.rs
Additional Context Used
Hey @digital-phoenix I see you've also thrown your hat in the ring ⚔️. Perhaps you didn't see it but @morgante posted this comment 2 days ago on another PR:
Once I saw that, it didn't make sense (for me at least) to continue working on my PR since they'd only be paying out one bounty. At that point, the only thing left was for @morgante to assign the issue to the author of that PR. Grit is definitely one of the more exciting COSS projects to join Algora and I'm hoping there's plenty of work like this to go round. |
There was a problem hiding this 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
Files selected for processing (1)
- crates/language/src/php.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/language/src/php.rs
feat: Added support for php with test cases
/claim #48
Summary by CodeRabbit
New Features
PatternsDirectory
.Documentation
Tests