airbus-cert / tree-sitter-powershell

Powershell grammar for tree-sitter
MIT License
37 stars 7 forks source link

ternary not supported #7

Open L2jLiga opened 3 months ago

L2jLiga commented 3 months ago

Hello, I've noticed that parser unable to work with ternary expression, could you fix this please?

input:

$variable=$true ?1:0

output:

(program [0, 0] - [0, 19]
  (statement_list [0, 0] - [0, 19]
    (pipeline [0, 0] - [0, 19]
      (assignment_expression [0, 0] - [0, 19]
        (left_assignment_expression [0, 0] - [0, 9]
          (logical_expression [0, 0] - [0, 9]
            (bitwise_expression [0, 0] - [0, 9]
              (comparison_expression [0, 0] - [0, 9]
                (additive_expression [0, 0] - [0, 9]
                  (multiplicative_expression [0, 0] - [0, 9]
                    (format_expression [0, 0] - [0, 9]
                      (range_expression [0, 0] - [0, 9]
                        (array_literal_expression [0, 0] - [0, 9]
                          (unary_expression [0, 0] - [0, 9]
                            (variable [0, 0] - [0, 9])))))))))))
        (assignement_operator [0, 9] - [0, 10])
        (ERROR [0, 10] - [0, 16]
          (variable [0, 10] - [0, 15])
          (ERROR [0, 15] - [0, 16]))
        value: (pipeline [0, 16] - [0, 19]
          (command [0, 16] - [0, 19]
            command_name: (command_name [0, 16] - [0, 19])))))))
citronneur commented 3 months ago

As far as I know there is no ternary operator in powershell

citronneur commented 3 months ago

Thanks @ZeArioch to point me the documentation : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7.4#using-the-ternary-operator-syntax

The example you provide is not supported by Powershell, only ternary operator is allowed following a parenthesis expression... Ok I will try to fix this issue. Thanks @L2jLiga !

L2jLiga commented 2 months ago

Thanks @ZeArioch to point me the documentation : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_if?view=powershell-7.4#using-the-ternary-operator-syntax

Sorry, I totally forgot to provide link to the documentation 😅

The example you provide is not supported by Powershell, only ternary operator is allowed following a parenthesis expression... Ok I will try to fix this issue. Thanks @L2jLiga !

That's actually weird because I've checked provided example in powershell 7.4.4 on Windows 11 in Windows Terminal:

┏[ user from  DESKTOP-JRVT494][ 0.196s][kubernetes-super-admin@kubernetes]
┖[~]
└─Δ $variable=$true ?1:0
┏[ user from  DESKTOP-JRVT494][ 0s][kubernetes-super-admin@kubernetes]
┖[~]
└─Δ echo $variable
1