Skip to content

Missing syntax highlighting for regex and SQL #120

Description

@mprz1024

The PHP injections.scm is missing injections to highlight regex and SQL at least in a few easy cases where it materially improves readability for the vast majority of uses. Here's the injections.scm I use:

((text) @injection.content
 (#set! injection.language "html")
 (#set! injection.combined))

(function_call_expression
  function: (name) @func_name
  (#any-of? @func_name "preg_match" "preg_match_all" "preg_replace" "preg_replace_callback" "preg_split" "preg_filter")
  arguments: (arguments
    . ; Anchor operator: forces this to be the first argument
    (argument
      [
        (string)
        (encapsed_string)
      ] @injection.content)
  )
  (#set! injection.language "regex")
)

(
  [
    (string)
    (encapsed_string)
  ] @injection.content
  (#match? @injection.content "^['\"]/")
  (#set! injection.language "regex")
)

(
  [
    (string (string_content) @injection.content)
    (encapsed_string (string_content) @injection.content)
  ]
  (#match? @injection.content "^\\s*(SELECT|WHERE|INSERT|REPLACE|UPDATE|DELETE|CREATE|ALTER|DROP|WITH)\\s")
  (#set! injection.language "sql")
)

(
  [
    (heredoc_body)
    (nowdoc_body)
  ] @injection.content
  (#match? @injection.content "^\\s*(SELECT|WHERE|INSERT|REPLACE|UPDATE|DELETE|CREATE|ALTER|DROP|WITH)\\s")
  (#set! injection.language "sql")
)

((comment) @injection.content
  (#match? @injection.content "^/\\*\\*[^*]")
  (#set! injection.language "phpdoc"))

((comment) @injection.content
 (#set! injection.language "comment"))

((heredoc_body) (heredoc_end) @injection.language) @injection.content

((nowdoc_body) (heredoc_end) @injection.language) @injection.content

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions