class SyntaxTree::Parser
def on_unary(operator, statement)
Experimental RBS support (using type sampling data from the type_fusion project).
def on_unary: (Symbol operator, SyntaxTree::Int statement) -> untyped
This signature was generated using 2 samples from 1 application.
on_unary: (:not operator, untyped statement) -> Not
:call-seq:
def on_unary(operator, statement) if operator == :not # We have somewhat special handling of the not operator since if it has # parentheses they don't get reported as a paren node for some reason. beginning = consume_keyword(:not) ending = statement || beginning parentheses = source[beginning.location.end_char] == "(" if parentheses consume_token(LParen) ending = consume_token(RParen) end Not.new( statement: statement, parentheses: parentheses, location: beginning.location.to(ending.location) ) else # Special case instead of using find_token here. It turns out that # if you have a range that goes from a negative number to a negative # number then you can end up with a .. or a ... that's higher in the # stack. So we need to explicitly disallow those operators. index = tokens.rindex do |token| token.is_a?(Op) && token.location.start_char < statement.location.start_char && !%w[.. ...].include?(token.value) end beginning = tokens.delete_at(index) Unary.new( operator: operator[0], # :+@ -> "+" statement: statement, location: beginning.location.to(statement.location) ) end end