aboutsummaryrefslogtreecommitdiffstats
path: root/queries/php
diff options
context:
space:
mode:
authortk-shirasaka <tk.shirasaka@gmail.com>2024-01-20 21:34:49 +0900
committerGitHub <noreply@github.com>2024-01-20 12:34:49 +0000
commit64b3d5e5698d485a4f197ffbe85a4b6c29e16325 (patch)
treedf6723ec690b4b4dad98cdcbffaa99c3a66b4587 /queries/php
parentfix(highlights): use `markup.raw.delimiter` for fences (diff)
downloadnvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar.gz
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar.bz2
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar.lz
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar.xz
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.tar.zst
nvim-treesitter-64b3d5e5698d485a4f197ffbe85a4b6c29e16325.zip
feat: add the php_only parser included in tree-sitter-php (#5876)
Add parser `php_only` for PHP files without HTML embedded. Make queries for combined parser `php` inherit from `php_only` (no extensions needed). --------- Co-authored-by: shirasaka <tk.shirasaka@gmail>
Diffstat (limited to 'queries/php')
-rw-r--r--queries/php/folds.scm17
-rw-r--r--queries/php/highlights.scm374
-rw-r--r--queries/php/indents.scm39
-rw-r--r--queries/php/injections.scm45
-rw-r--r--queries/php/locals.scm87
5 files changed, 5 insertions, 557 deletions
diff --git a/queries/php/folds.scm b/queries/php/folds.scm
index 56eb33e77..f32463888 100644
--- a/queries/php/folds.scm
+++ b/queries/php/folds.scm
@@ -1,16 +1 @@
-[
- (if_statement)
- (switch_statement)
- (while_statement)
- (do_statement)
- (for_statement)
- (foreach_statement)
- (try_statement)
- (function_definition)
- (class_declaration)
- (interface_declaration)
- (trait_declaration)
- (enum_declaration)
- (function_static_declaration)
- (method_declaration)
-] @fold
+; inherits: php_only
diff --git a/queries/php/highlights.scm b/queries/php/highlights.scm
index cbc7e1839..f32463888 100644
--- a/queries/php/highlights.scm
+++ b/queries/php/highlights.scm
@@ -1,373 +1 @@
-; Variables
-(variable_name) @variable
-
-; Constants
-((name) @constant
- (#lua-match? @constant "^_?[A-Z][A-Z%d_]*$"))
-
-((name) @constant.builtin
- (#lua-match? @constant.builtin "^__[A-Z][A-Z%d_]+__$"))
-
-(const_declaration
- (const_element
- (name) @constant))
-
-; Types
-[
- (primitive_type)
- (cast_type)
- (bottom_type)
-] @type.builtin
-
-(named_type
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-(class_declaration
- name: (name) @type)
-
-(base_clause
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-(enum_declaration
- name: (name) @type)
-
-(interface_declaration
- name: (name) @type)
-
-(namespace_use_clause
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-(namespace_aliasing_clause
- (name) @type.definition)
-
-(class_interface_clause
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-(scoped_call_expression
- scope:
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-(class_constant_access_expression
- .
- [
- (name) @type
- (qualified_name
- (name) @type)
- ]
- (name) @constant)
-
-(trait_declaration
- name: (name) @type)
-
-(use_declaration
- (name) @type)
-
-(binary_expression
- operator: "instanceof"
- right:
- [
- (name) @type
- (qualified_name
- (name) @type)
- ])
-
-; Functions, methods, constructors
-(array_creation_expression
- "array" @function.builtin)
-
-(list_literal
- "list" @function.builtin)
-
-(method_declaration
- name: (name) @function.method)
-
-(function_call_expression
- function:
- (qualified_name
- (name) @function.call))
-
-(function_call_expression
- (name) @function.call)
-
-(scoped_call_expression
- name: (name) @function.call)
-
-(member_call_expression
- name: (name) @function.method.call)
-
-(function_definition
- name: (name) @function)
-
-(nullsafe_member_call_expression
- name: (name) @function.method)
-
-(method_declaration
- name: (name) @constructor
- (#eq? @constructor "__construct"))
-
-(object_creation_expression
- [
- (name) @constructor
- (qualified_name
- (name) @constructor)
- ])
-
-; Parameters
-[
- (simple_parameter)
- (variadic_parameter)
-] @variable.parameter
-
-(argument
- (name) @variable.parameter)
-
-; Member
-(property_element
- (variable_name) @property)
-
-(member_access_expression
- name:
- (variable_name
- (name)) @property)
-
-(member_access_expression
- name: (name) @property)
-
-; Variables
-(relative_scope) @variable.builtin
-
-((variable_name) @variable.builtin
- (#eq? @variable.builtin "$this"))
-
-; Namespace
-(namespace_definition
- name:
- (namespace_name
- (name) @module))
-
-(namespace_name_as_prefix
- (namespace_name
- (name) @module))
-
-; Attributes
-(attribute_list) @attribute
-
-; Conditions ( ? : )
-(conditional_expression) @keyword.conditional
-
-; Directives
-(declare_directive
- [
- "strict_types"
- "ticks"
- "encoding"
- ] @variable.parameter)
-
-; Basic tokens
-[
- (string)
- (encapsed_string)
- (heredoc_body)
- (nowdoc_body)
- (shell_command_expression) ; backtick operator: `ls -la`
-] @string
-
-(escape_sequence) @string.escape
-
-[
- (heredoc_start)
- (heredoc_end)
-] @label
-
-(nowdoc
- "'" @label)
-
-(boolean) @boolean
-
-(null) @constant.builtin
-
-(integer) @number
-
-(float) @number.float
-
-(comment) @comment @spell
-
-(named_label_statement) @label
-
-; Keywords
-[
- "and"
- "as"
- "instanceof"
- "or"
- "xor"
-] @keyword.operator
-
-[
- "fn"
- "function"
-] @keyword.function
-
-[
- "break"
- "class"
- "clone"
- "declare"
- "default"
- "echo"
- "enddeclare"
- "enum"
- "extends"
- "global"
- "goto"
- "implements"
- "insteadof"
- "interface"
- "namespace"
- "new"
- "trait"
- "unset"
-] @keyword
-
-[
- "abstract"
- "const"
- "final"
- "private"
- "protected"
- "public"
- "readonly"
- "static"
-] @type.qualifier
-
-[
- "return"
- "yield"
-] @keyword.return
-
-[
- "case"
- "else"
- "elseif"
- "endif"
- "endswitch"
- "if"
- "switch"
- "match"
- "??"
-] @keyword.conditional
-
-[
- "continue"
- "do"
- "endfor"
- "endforeach"
- "endwhile"
- "for"
- "foreach"
- "while"
-] @keyword.repeat
-
-[
- "catch"
- "finally"
- "throw"
- "try"
-] @keyword.exception
-
-[
- "include_once"
- "include"
- "require_once"
- "require"
- "use"
-] @keyword.import
-
-[
- ","
- ";"
- ":"
- "\\"
-] @punctuation.delimiter
-
-[
- (php_tag)
- "?>"
- "("
- ")"
- "["
- "]"
- "{"
- "}"
- "#["
-] @punctuation.bracket
-
-[
- "="
- "."
- "-"
- "*"
- "/"
- "+"
- "%"
- "**"
- "~"
- "|"
- "^"
- "&"
- "<<"
- ">>"
- "<<<"
- "->"
- "?->"
- "=>"
- "<"
- "<="
- ">="
- ">"
- "<>"
- "=="
- "!="
- "==="
- "!=="
- "!"
- "&&"
- "||"
- ".="
- "-="
- "+="
- "*="
- "/="
- "%="
- "**="
- "&="
- "|="
- "^="
- "<<="
- ">>="
- "??="
- "--"
- "++"
- "@"
- "::"
-] @operator
+; inherits: php_only
diff --git a/queries/php/indents.scm b/queries/php/indents.scm
index a81faed62..f32463888 100644
--- a/queries/php/indents.scm
+++ b/queries/php/indents.scm
@@ -1,38 +1 @@
-[
- (array_creation_expression)
- (compound_statement)
- (declaration_list)
- (binary_expression)
- (return_statement)
- (arguments)
- (formal_parameters)
- (enum_declaration_list)
- (switch_block)
- (match_block)
- (case_statement)
-] @indent.begin
-
-[
- ")"
- "}"
- "]"
-] @indent.branch
-
-(comment) @indent.auto
-
-(compound_statement
- "}" @indent.end)
-
-(ERROR
- "(" @indent.align
- .
- (_)
- (#set! indent.open_delimiter "(")
- (#set! indent.close_delimiter ")"))
-
-(ERROR
- "[" @indent.align
- .
- (_)
- (#set! indent.open_delimiter "[")
- (#set! indent.close_delimiter "]"))
+; inherits: php_only
diff --git a/queries/php/injections.scm b/queries/php/injections.scm
index 0c9d25ce6..141f65eaa 100644
--- a/queries/php/injections.scm
+++ b/queries/php/injections.scm
@@ -1,47 +1,4 @@
+; inherits: php_only
((text) @injection.content
(#set! injection.language "html")
(#set! injection.combined))
-
-((comment) @injection.content
- (#set! injection.language "phpdoc"))
-
-((heredoc
- (heredoc_body) @injection.content
- (heredoc_end) @injection.language
- (#set! injection.include-children)
- (#downcase! @injection.language)))
-
-((nowdoc
- (nowdoc_body) @injection.content
- (heredoc_end) @injection.language
- (#set! injection.include-children)
- (#downcase! @injection.language)))
-
-; regex
-((function_call_expression
- function: (_) @_preg_func_identifier
- arguments:
- (arguments
- .
- (argument
- (_
- (string_value) @injection.content))))
- (#set! injection.language "regex")
- (#lua-match? @_preg_func_identifier "^preg_"))
-
-; bash
-((function_call_expression
- function: (_) @_shell_func_identifier
- arguments:
- (arguments
- .
- (argument
- (_
- (string_value) @injection.content))))
- (#set! injection.language "bash")
- (#any-of? @_shell_func_identifier "shell_exec" "escapeshellarg" "escapeshellcmd" "exec" "passthru" "proc_open" "shell_exec" "system"))
-
-(expression_statement
- (shell_command_expression
- (string_value) @injection.content)
- (#set! injection.language "bash"))
diff --git a/queries/php/locals.scm b/queries/php/locals.scm
index 8d509b37c..f32463888 100644
--- a/queries/php/locals.scm
+++ b/queries/php/locals.scm
@@ -1,86 +1 @@
-; Scopes
-;-------
-((class_declaration
- name: (name) @local.definition.type) @local.scope
- (#set! definition.type.scope "parent"))
-
-((method_declaration
- name: (name) @local.definition.method) @local.scope
- (#set! definition.method.scope "parent"))
-
-((function_definition
- name: (name) @local.definition.function) @local.scope
- (#set! definition.function.scope "parent"))
-
-(anonymous_function_creation_expression
- (anonymous_function_use_clause
- (variable_name
- (name) @local.definition.var))) @local.scope
-
-; Definitions
-;------------
-(simple_parameter
- (variable_name
- (name) @local.definition.var))
-
-(foreach_statement
- (pair
- (variable_name
- (name) @local.definition.var)))
-
-(foreach_statement
- (variable_name
- (name) @local.reference
- (#set! reference.kind "var"))
- (variable_name
- (name) @local.definition.var))
-
-(property_declaration
- (property_element
- (variable_name
- (name) @local.definition.field)))
-
-(namespace_use_clause
- (qualified_name
- (name) @local.definition.type))
-
-; References
-;------------
-(named_type
- (name) @local.reference
- (#set! reference.kind "type"))
-
-(named_type
- (qualified_name) @local.reference
- (#set! reference.kind "type"))
-
-(variable_name
- (name) @local.reference
- (#set! reference.kind "var"))
-
-(member_access_expression
- name: (name) @local.reference
- (#set! reference.kind "field"))
-
-(member_call_expression
- name: (name) @local.reference
- (#set! reference.kind "method"))
-
-(function_call_expression
- function:
- (qualified_name
- (name) @local.reference
- (#set! reference.kind "function")))
-
-(object_creation_expression
- (qualified_name
- (name) @local.reference
- (#set! reference.kind "type")))
-
-(scoped_call_expression
- scope:
- (qualified_name
- (name) @local.reference
- (#set! reference.kind "type"))
- name: (name) @local.reference
- (#set! reference.kind "method"))
+; inherits: php_only