tree-sitter-php icon indicating copy to clipboard operation
tree-sitter-php copied to clipboard

Parsing error

Open mrsdizzie opened this issue 11 months ago • 1 comments

Did you check existing issues?

  • [X] I have read all the tree-sitter docs if it relates to using the parser
  • [X] I have searched the existing issues of tree-sitter-php

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.21.0

Describe the bug

I saw the following valid PHP code in the wild that was parsed incorrectly. I was able to extract the part that wasn't parsed properly into a smaller valid PHP example that is reproducible with tree-sitter cli.

Steps To Reproduce/Bad Parse Tree

isla@Islas-MacBook-Pro ~/source/tree-sitter-php/php (master *%|u=) $ tree-sitter parse test.php
running: "c++" "--version"
exit status: 0
running: "xcrun" "--show-sdk-platform-version" "--sdk" "macosx"
exit status: 0
(program [0, 0] - [10, 0]
  (php_tag [0, 0] - [0, 5])
  (expression_statement [1, 0] - [1, 14]
    (assignment_expression [1, 0] - [1, 13]
      left: (variable_name [1, 0] - [1, 4]
        (name [1, 1] - [1, 4]))
      right: (encapsed_string [1, 7] - [1, 13]
        (string_value [1, 8] - [1, 12]))))
  (ERROR [2, 0] - [10, 0]
    (function_call_expression [2, 4] - [2, 50]
      function: (name [2, 4] - [2, 14])
      arguments: (arguments [2, 14] - [2, 50]
        (argument [2, 15] - [2, 43]
          (string [2, 15] - [2, 43]
            (string_value [2, 16] - [2, 42])))
        (argument [2, 45] - [2, 49]
          (variable_name [2, 45] - [2, 49]
            (name [2, 46] - [2, 49])))))
    (name [3, 7] - [3, 17])
    (comment [3, 19] - [3, 65])
    (string_value [3, 65] - [10, 0])))

Expected Behavior/Parse Tree

Both of the conditionals should be parsed the same

Repro

<?php
$var = "test";
if (preg_match('#([\w\(\)\.\,\;]|[`]{1})$#', $var)
    && preg_match('#^([\w\(\)\.\,\;`]|\\\--[\w]|[`]{1})#', $var) 
) {
    echo "test";
}
?>

mrsdizzie avatar Mar 19 '24 15:03 mrsdizzie