Skip to content

Ruby scanner can't parse complex method definitions #82

Open
@nathany

Description

@nathany
Contributor

Ruby scanner has problems to recognize method names in more complex forms of singleton method definition.

I have made a test case.

# simple method definitions

def method param1, param2
  # code
end

def method(args, *rest, &block)
  # code
end

def
method(param1, param2)
  # code
end

def \
method(param1, param2)
  # code
end

def # comment
method(param1, param2)
  # code
end

def [];end
def def;end
def end?;end
def a(*) end
def !; end  # Ruby 1.9

# singleton methods

def Class.method
end

def self.method
end

def object.method
end

def $~.method
end

def nil.method
end
def true.method
end
def false.method
end
def __FILE__.method
end
def __LINE__.method
end
def __ENCODING__.method
end
def __ENCODING__.method
end

def @instance_variable.method
end

def @class_variable.method
end

def (Module::Class).method
end

def (complex.expression).method
end

def (complex.expression + another(complex(expression))).method
end

# crazy

def (class Foo
  def initialize(args)
    def yet_another_method; end
  end
end).method(args, *rest, &block)
end

# wrong
def foo.bar.quux
end

The simple cases are working now. Support for def (expression).method is still missing, but possible now that the state handling has been cleaned up.

I just realized we can even have recursive expression singleton method declarations - so the parenthesis nesting depth really has to be saved in the state, not in a local variable.

I still want to get this obscure thing working, but it's not as important as other features in 1.0. So, I postpone the rest of this ticket to 1.1.

From Redmine: http://odd-eyed-code.org/issues/147

Activity

korny

korny commented on Mar 10, 2013

@korny
Member

Another obscure feature that I really want for the Ruby scanner, but it's not important enough to delay 1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nathany@korny

        Issue actions

          Ruby scanner can't parse complex method definitions · Issue #82 · rubychan/coderay