Skip to content

Commit

Permalink
Add reserved operator knowledge to OperatotProperties
Browse files Browse the repository at this point in the history
- is-reserved-operator    return whether given op name is reserved
- reserved-operator-hint  return hint for reserved operator name
  • Loading branch information
lizmat committed Aug 29, 2023
1 parent c4674f7 commit c21f4b6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Raku/ast/operator-properties.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ class OperatorProperties {
!! nqp::substr(self.bracket-openers,$index,1)
}

#-------------------------------------------------------------------------------
# Reserved operators

# Return hash with reserved operator names and optional hints for errors
method reserved-operators-lookup() {
my constant RESERVED := nqp::hash(
'infix:sym<=>', "",
'infix:sym<:=>', "",
'infix:sym<::=>', "",
'infix:sym<~~>', "(consider implementing an ACCEPTS method)",
'prefix:sym<|>', ""
)
}

# Return whether given operator name is reserved
method is-reserved-operator(str $operator) {
nqp::existskey(self.reserved-operators-lookup,$operator)
}

# Return hint to be added to error message if reserved
method reserved-operator-hint(str $operator) {
nqp::atkey(self.reserved-operators-lookup,$operator)
}

#-------------------------------------------------------------------------------
# Methods that can be run on both an instance and a type object. Note that
# when calle on a type object, an "empty" representation of that function
Expand Down

0 comments on commit c21f4b6

Please sign in to comment.