Skip to content

Refactor _expression rule #16

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 137 additions & 135 deletions grammar.js

Large diffs are not rendered by default.

546 changes: 271 additions & 275 deletions src/grammar.json

Large diffs are not rendered by default.

2,167 changes: 1,848 additions & 319 deletions src/node-types.json

Large diffs are not rendered by default.

123,314 changes: 60,635 additions & 62,679 deletions src/parser.c

Large diffs are not rendered by default.

567 changes: 106 additions & 461 deletions test/corpus/branch.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot accept that

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions test/corpus/classes.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot accept that

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MyClass
(type_identifier))))
(variable)))))


===
Class : string property with attributes
===
Expand Down Expand Up @@ -91,9 +90,8 @@ class MyClass
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal))))))))))))))
(string_literal
(expandable_string_literal)))))))))))))

===
Class : method declaration with parameters
Expand Down Expand Up @@ -135,12 +133,10 @@ class MyClass
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal
(variable)
(variable)))))))))))))))

(string_literal
(expandable_string_literal
(variable)
(variable))))))))))))))

===
Class : mix method and properties declaration
Expand Down Expand Up @@ -196,9 +192,8 @@ class MyClass
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))))
(string_literal
(expandable_string_literal))))))))))
(class_property_definition
(type_literal
(type_spec
Expand All @@ -225,10 +220,9 @@ class MyClass
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal
(variable)
(variable))))))))))))
(string_literal
(expandable_string_literal
(variable)
(variable)))))))))))
(class_method_definition
(simple_name)))))
185 changes: 58 additions & 127 deletions test/corpus/commands.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot accept that

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ Write-Host "CERT"
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))
(string_literal
(expandable_string_literal))))))))

===
Cmdlet that start with a number
Expand Down Expand Up @@ -80,60 +79,33 @@ New-DynamicParam -Name Plugins -type string[] -ValidateSet $(((gci .\plugins\*.p
(command_parameter)
(command_argument_sep)
(array_literal_expression
(unary_expression
(sub_expression
statements: (statement_list
(pipeline
(logical_expression
(bitwise_expression
(comparison_expression
(comparison_expression
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(parenthesized_expression
(pipeline
(logical_expression
(bitwise_expression
(comparison_expression
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(member_access
(parenthesized_expression
(pipeline
(command
command_name: (command_name)
command_elements: (command_elements
(command_argument_sep)
(generic_token)))))
(member_name
(simple_name)))))))))))))))))))))
(comparison_operator)
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))
(unary_expression
(string_literal
(expandable_string_literal))))))))))))))))
(sub_expression
statements: (statement_list
(pipeline
(comparison_expression
(parenthesized_expression
(pipeline
(member_access
(parenthesized_expression
(pipeline
(command
command_name: (command_name)
command_elements: (command_elements
(command_argument_sep)
(generic_token)))))
(member_name
(simple_name)))))
(comparison_operator)
(array_literal_expression
(string_literal
(expandable_string_literal))
(string_literal
(expandable_string_literal))))))))
(command_argument_sep)
(command_parameter)
(command_argument_sep)
(array_literal_expression
(unary_expression
(variable))))))))

(variable)))))))

===
Quoted CmdLet
Expand All @@ -151,9 +123,8 @@ i''ex "pwd"
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))
(string_literal
(expandable_string_literal))))))))

===
Double Quoted CmdLet
Expand All @@ -171,9 +142,8 @@ i""ex "pwd"
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))
(string_literal
(expandable_string_literal))))))))

===
Obfuscated cmdlet and string
Expand All @@ -191,9 +161,8 @@ ie""x'' "p`"`"w''d`"`""
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))
(string_literal
(expandable_string_literal))))))))

===
Native command
Expand All @@ -209,7 +178,6 @@ net.exe
(command
(command_name)))))


===
Unix-like native command
===
Expand Down Expand Up @@ -264,7 +232,6 @@ net use e: \\usrsvr002\smithmark Ue345Ii /user:pdc01\msmith2 /savecred /p:yes
(command_argument_sep)
(generic_token))))))


===
Foreach statement without token separator
===
Expand All @@ -283,41 +250,21 @@ Foreach statement without token separator
(script_block_body
(statement_list
(pipeline
(logical_expression
(bitwise_expression
(comparison_expression
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(parenthesized_expression
(pipeline
(logical_expression
(bitwise_expression
(comparison_expression
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(expression_with_unary_operator
(cast_expression
(type_literal
(type_spec
(type_name
(type_identifier))))
(unary_expression
(expression_with_unary_operator
(cast_expression
(type_literal
(type_spec
(type_name
(type_identifier))))
(unary_expression
(variable)))))))))))))))))))))))))))))))))))))
(parenthesized_expression
(pipeline
(unary_expression
(cast_expression
(type_literal
(type_spec
(type_name
(type_identifier))))
(unary_expression
(cast_expression
(type_literal
(type_spec
(type_name
(type_identifier))))
(variable)))))))))))))))))

===
multiline command line
Expand All @@ -336,9 +283,8 @@ Write-Debug `
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))
(string_literal
(expandable_string_literal))))))))

===
command with argument set by :
Expand All @@ -356,8 +302,7 @@ New-Item $profileDir -ItemType Directory -Force -Verbose:$VerbosePreference > $n
(command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(variable)))
(variable))
(command_argument_sep)
(command_parameter)
(command_argument_sep)
Expand All @@ -368,16 +313,14 @@ New-Item $profileDir -ItemType Directory -Force -Verbose:$VerbosePreference > $n
(command_parameter)
(command_argument_sep)
(array_literal_expression
(unary_expression
(variable)))
(variable))
(command_argument_sep)
(redirection
(file_redirection_operator)
(redirected_file_name
(command_argument_sep)
(array_literal_expression
(unary_expression
(variable))))))))))
(variable)))))))))

===
Diff between argument and array literal
Expand All @@ -392,16 +335,7 @@ $rih2ymeurlleflu = & "New-Object" "System.Net.Sockets.TCPClient"("127.0.0.1", 44
(pipeline
(assignment_expression
(left_assignment_expression
(logical_expression
(bitwise_expression
(comparison_expression
(additive_expression
(multiplicative_expression
(format_expression
(range_expression
(array_literal_expression
(unary_expression
(variable)))))))))))
(variable))
(assignement_operator)
value: (pipeline
(command
Expand All @@ -412,9 +346,8 @@ $rih2ymeurlleflu = & "New-Object" "System.Net.Sockets.TCPClient"("127.0.0.1", 44
command_elements: (command_elements
(command_argument_sep)
(array_literal_expression
(unary_expression
(string_literal
(expandable_string_literal))))
(string_literal
(expandable_string_literal)))
(argument_list
argument_expression_list: (argument_expression_list
(argument_expression
Expand All @@ -425,9 +358,8 @@ $rih2ymeurlleflu = & "New-Object" "System.Net.Sockets.TCPClient"("127.0.0.1", 44
(multiplicative_argument_expression
(format_argument_expression
(range_argument_expression
(unary_expression
(string_literal
(expandable_string_literal)))))))))))
(string_literal
(expandable_string_literal))))))))))
(argument_expression
(logical_argument_expression
(bitwise_argument_expression
Expand All @@ -436,6 +368,5 @@ $rih2ymeurlleflu = & "New-Object" "System.Net.Sockets.TCPClient"("127.0.0.1", 44
(multiplicative_argument_expression
(format_argument_expression
(range_argument_expression
(unary_expression
(integer_literal
(decimal_integer_literal))))))))))))))))))))
(integer_literal
(decimal_integer_literal)))))))))))))))))))
Loading