Skip to content

Commit

Permalink
chore: add fields to unary_op_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 31, 2024
1 parent 6eefa47 commit ab2d6e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 102 deletions.
8 changes: 4 additions & 4 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,10 @@ module.exports = function defineGrammar(dialect) {
$.cast_expression,
),

unary_op_expression: $ => prec.left(
PREC.NEG,
seq(choice('+', '-', '~', '!'), $._expression),
),
unary_op_expression: $ => prec.left(PREC.NEG, seq(
field('operator', choice('+', '-', '~', '!')),
field('argument', $._expression),
)),

error_suppression_expression: $ => prec(PREC.INC, seq('@', $._expression)),

Expand Down
123 changes: 33 additions & 90 deletions common/test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ $a ** $c = $b;
(echo_statement
(binary_expression
left: (variable_name (name))
right: (unary_op_expression (variable_name (name)))))
right: (unary_op_expression
argument: (variable_name (name)))))
(expression_statement
(binary_expression
left: (variable_name (name))
Expand Down Expand Up @@ -85,11 +86,11 @@ if (!$foo = $bar) {
(program
(php_tag)
(if_statement
(parenthesized_expression (unary_op_expression
(assignment_expression
(variable_name (name))
(variable_name (name)))))
(compound_statement)))
condition: (parenthesized_expression (unary_op_expression
argument: (assignment_expression
left: (variable_name (name))
right: (variable_name (name)))))
body: (compound_statement)))

===============================
Capitalized logical operators
Expand Down Expand Up @@ -434,16 +435,15 @@ Associativity of negation
(php_tag)
(expression_statement
(binary_expression
(unary_op_expression
(integer))
(unary_op_expression
(integer))))
left: (unary_op_expression
argument: (integer))
right: (unary_op_expression
argument: (integer))))
(expression_statement
(unary_op_expression
(binary_expression
(variable_name
(name))
(name)))))
argument: (binary_expression
left: (variable_name (name))
right: (name)))))

====================================
Augmented assignment
Expand Down Expand Up @@ -740,162 +740,105 @@ throw $exception ??= new Exception();
(throw_expression
(object_creation_expression
(name)
(arguments (argument (name)))
)
)
)
(arguments (argument (name))))))
(expression_statement
(assignment_expression
left: (variable_name (name))
right: (conditional_expression
condition: (unary_op_expression
(function_call_expression
argument: (function_call_expression
function: (name)
arguments: (arguments (argument (variable_name (name))))
)
)
arguments: (arguments (argument (variable_name (name))))))
body: (function_call_expression
function: (name)
arguments: (arguments (argument (variable_name (name))))
)
arguments: (arguments (argument (variable_name (name)))))
alternative: (throw_expression
(object_creation_expression
(name)
(arguments)
)
)
)
)
)
(arguments))))))
(expression_statement
(binary_expression
left: (variable_name (name))
right: (throw_expression
(object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(binary_expression
left: (variable_name (name))
right: (throw_expression
(object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(binary_expression
left: (variable_name (name))
right: (throw_expression
(object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(binary_expression
left: (variable_name (name))
right: (throw_expression
(object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(throw_expression
(member_call_expression
object: (variable_name (name))
name: (name)
arguments: (arguments)
)
)
)
arguments: (arguments))))
(expression_statement
(throw_expression
(scoped_call_expression
scope: (relative_scope)
name: (name)
arguments: (arguments)
)
)
)
arguments: (arguments))))
(expression_statement
(throw_expression
(conditional_expression
condition: (variable_name (name))
body: (object_creation_expression
(name)
(arguments)
)
(arguments))
alternative: (object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(throw_expression
(binary_expression
left: (variable_name (name))
right: (object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(throw_expression
(assignment_expression
left: (variable_name (name))
right: (object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(throw_expression
(conditional_expression
condition: (binary_expression
left: (variable_name (name))
right: (variable_name (name))
)
right: (variable_name (name)))
body: (object_creation_expression
(name)
(arguments)
)
(arguments))
alternative: (object_creation_expression
(name)
(arguments)
)
)
)
)
(arguments)))))
(expression_statement
(throw_expression
(augmented_assignment_expression
left: (variable_name (name))
right: (object_creation_expression
(name)
(arguments)
)
)
)
)
)
(arguments))))))

===============================================
Nullsafe operator
Expand Down
11 changes: 3 additions & 8 deletions php/test/corpus/interpolation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,10 @@ if ( ! function_exists('xml_parser_create') ) {
(if_statement
condition: (parenthesized_expression
(unary_op_expression
(function_call_expression
argument: (function_call_expression
function: (name)
arguments: (arguments (argument (string (string_value))))
)
)
)
body: (compound_statement (echo_statement (variable_name (name))))
)
)
arguments: (arguments (argument (string (string_value)))))))
body: (compound_statement (echo_statement (variable_name (name))))))

=====================================
Closing tags before the first PHP tag
Expand Down

0 comments on commit ab2d6e2

Please sign in to comment.