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

fix digit escape in highlight regex for constants #112

Merged
merged 1 commit into from
Oct 17, 2021
Merged

fix digit escape in highlight regex for constants #112

merged 1 commit into from
Oct 17, 2021

Conversation

the-mikedavis
Copy link
Contributor

Checklist: (:heavy_check_mark:)
  • All tests pass in CI (they pass locally but I can't get the Actions CI running right now 🤔)
  • There are sufficient tests for the new fix/feature (added one)
  • Grammar rules have not been renamed unless absolutely necessary (N/A)
  • The conflicts section hasn't grown too much (N/A)
  • The parser size hasn't grown too much (N/A)

This is the same idea as tree-sitter/tree-sitter-java#90, the \d should be \\d to become the digit escape.

This one is a bit more straightforward: the query currently misconstrues constants with digits in them as constructors (because of the rule below it).

pi.php

<?php
define("PI", 3);
define("PI_314", 3.14);
echo PI;
echo PI_314;
?>

query1.scm

((name) @constant
 (#match? @constant "^_?[A-Z][A-Z\d_]+$"))

query2.scm

((name) @constant
 (#match? @constant "^_?[A-Z][A-Z\\d_]+$"))

reproduction

$ tree-sitter query query1.scm pi.php
pi.php
  pattern: 0
    capture: constant, start: (3, 5), text: "PI"

$ tree-sitter query query2.scm pi.php
pi.php
  pattern: 0
    capture: constant, start: (3, 5), text: "PI"
  pattern: 0
    capture: constant, start: (4, 5), text: "PI_314"

@maxbrunsfeld
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants