airbus-cert / tree-sitter-powershell

Powershell grammar for tree-sitter
MIT License
39 stars 9 forks source link

String Literal Detection Issue When String Contains Keywords #11

Open jconnor0426 opened 3 months ago

jconnor0426 commented 3 months ago

Hey all!

I found an issue using Treesitter python bindings with this PowerShell library.

Example PowerShell Script:

$groups = "ABC123"
if (-not ($groups -Contains "Domain Admins")) {
    exit
}

This results in a tree that has ERRORs around the the string "Domain Admins" as it trys to parse the in within Domain as if that was the keyword in. Screenshot 2024-08-09 5 25 26 PM

jconnor0426 commented 3 months ago

The full tree output when running treesitter parse on the example script:

(program [0, 0] - [3, 1]
  (statement_list [0, 0] - [3, 1]
    (pipeline [0, 0] - [0, 18]
      (assignment_expression [0, 0] - [0, 18]
        (left_assignment_expression [0, 0] - [0, 7]
          (logical_expression [0, 0] - [0, 7]
            (bitwise_expression [0, 0] - [0, 7]
              (comparison_expression [0, 0] - [0, 7]
                (additive_expression [0, 0] - [0, 7]
                  (multiplicative_expression [0, 0] - [0, 7]
                    (format_expression [0, 0] - [0, 7]
                      (range_expression [0, 0] - [0, 7]
                        (array_literal_expression [0, 0] - [0, 7]
                          (unary_expression [0, 0] - [0, 7]
                            (variable [0, 0] - [0, 7])))))))))))
        (assignement_operator [0, 8] - [0, 9])
        value: (pipeline [0, 10] - [0, 18]
          (logical_expression [0, 10] - [0, 18]
            (bitwise_expression [0, 10] - [0, 18]
              (comparison_expression [0, 10] - [0, 18]
                (additive_expression [0, 10] - [0, 18]
                  (multiplicative_expression [0, 10] - [0, 18]
                    (format_expression [0, 10] - [0, 18]
                      (range_expression [0, 10] - [0, 18]
                        (array_literal_expression [0, 10] - [0, 18]
                          (unary_expression [0, 10] - [0, 18]
                            (string_literal [0, 10] - [0, 18]
                              (expandable_string_literal [0, 10] - [0, 18]))))))))))))))
    (if_statement [1, 0] - [3, 1]
      condition: (pipeline [1, 4] - [1, 44]
        (logical_expression [1, 4] - [1, 44]
          (bitwise_expression [1, 4] - [1, 44]
            (comparison_expression [1, 4] - [1, 44]
              (additive_expression [1, 4] - [1, 44]
                (multiplicative_expression [1, 4] - [1, 44]
                  (format_expression [1, 4] - [1, 44]
                    (range_expression [1, 4] - [1, 44]
                      (array_literal_expression [1, 4] - [1, 44]
                        (unary_expression [1, 4] - [1, 44]
                          (expression_with_unary_operator [1, 4] - [1, 44]
                            (unary_expression [1, 9] - [1, 44]
                              (parenthesized_expression [1, 9] - [1, 44]
                                (pipeline [1, 10] - [1, 17]
                                  (logical_expression [1, 10] - [1, 17]
                                    (bitwise_expression [1, 10] - [1, 17]
                                      (comparison_expression [1, 10] - [1, 17]
                                        (additive_expression [1, 10] - [1, 17]
                                          (multiplicative_expression [1, 10] - [1, 17]
                                            (format_expression [1, 10] - [1, 17]
                                              (range_expression [1, 10] - [1, 17]
                                                (array_literal_expression [1, 10] - [1, 17]
                                                  (unary_expression [1, 10] - [1, 17]
                                                    (variable [1, 10] - [1, 17])))))))))))
                                (ERROR [1, 18] - [1, 43]
                                  (simple_name [1, 19] - [1, 27])
                                  (ERROR [1, 29] - [1, 33])
                                  (ERROR [1, 35] - [1, 39])
                                  (ERROR [1, 41] - [1, 42])))))))))))))))
      (statement_block [1, 46] - [3, 1]
        statement_list: (statement_list [2, 4] - [2, 8]
          (flow_control_statement [2, 4] - [2, 8]))))))
citronneur commented 2 months ago

Hello @jconnor0426 I was not able to reproduce your error with the last version of the parser. Could you please retry please?