Skip to content

Commit

Permalink
feat: add asymmetric property visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Oct 1, 2024
1 parent 74c6b0d commit a041c48
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
15 changes: 11 additions & 4 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,17 @@ module.exports = function defineGrammar(dialect) {
),
),

visibility_modifier: _ => choice(
keyword('public'),
keyword('protected'),
keyword('private'),
visibility_modifier: $ => seq(
choice(
keyword('public'),
keyword('protected'),
keyword('private'),
),
optional(seq(
token.immediate('('),
alias($.name, $.operation),
token.immediate(')'),
)),
),

function_definition: $ => seq(
Expand Down
79 changes: 79 additions & 0 deletions test/corpus/class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,82 @@ class User implements Named {
(name))))
(name)
(compound_statement)))))))

=========================================
Asymmetric Property Visibility
=========================================

<?php

class User {
public private(set) string $foo;
private(set) (Foo&Bar)|null $foo;
private (Foo&Bar)|null $foo;
public protected(set) string $foo;
protected(set) string $foo;
public function __construct(
private(set) string $title,
private(set) Author $author,
private(set) int $pubYear,
) {}
}

---

(program
(php_tag)
(class_declaration
(name)
(declaration_list
(property_declaration
(visibility_modifier)
(visibility_modifier (operation))
(primitive_type)
(property_element
(variable_name (name))))
(property_declaration
(visibility_modifier (operation))
(disjunctive_normal_form_type
(intersection_type
(named_type (name))
(named_type (name)))
(primitive_type))
(property_element
(variable_name (name))))
(property_declaration
(visibility_modifier)
(disjunctive_normal_form_type
(intersection_type
(named_type (name))
(named_type (name)))
(primitive_type))
(property_element
(variable_name (name))))
(property_declaration
(visibility_modifier)
(visibility_modifier (operation))
(primitive_type)
(property_element
(variable_name (name))))
(property_declaration
(visibility_modifier (operation))
(primitive_type)
(property_element
(variable_name (name))))
(method_declaration
(visibility_modifier)
(name)
(formal_parameters
(property_promotion_parameter
(visibility_modifier (operation))
(primitive_type)
(variable_name (name)))
(property_promotion_parameter
(visibility_modifier (operation))
(named_type (name))
(variable_name (name)))
(property_promotion_parameter
(visibility_modifier (operation))
(primitive_type)
(variable_name (name))))
(compound_statement)))))

0 comments on commit a041c48

Please sign in to comment.