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

Parsing error #234

Closed
2 tasks done
mrsdizzie opened this issue Mar 19, 2024 · 1 comment · Fixed by #237
Closed
2 tasks done

Parsing error #234

mrsdizzie opened this issue Mar 19, 2024 · 1 comment · Fixed by #237
Labels

Comments

@mrsdizzie
Copy link

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • 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 mrsdizzie added the bug label Mar 19, 2024
@calebdw
Copy link
Collaborator

calebdw commented Mar 19, 2024

This has to do with the \\ in the string

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

Successfully merging a pull request may close this issue.

2 participants