Skip to content

Support endless method definition #75

@schneems

Description

@schneems
def square(x) = x * x
irb(main):002:0> Ripper.lex("def square(x) = x * x")
=>
[[[1, 0], :on_kw, "def", FNAME],
 [[1, 3], :on_sp, " ", FNAME],
 [[1, 4], :on_ident, "square", ENDFN],
 [[1, 10], :on_lparen, "(", BEG|LABEL],
 [[1, 11], :on_ident, "x", ARG],
 [[1, 12], :on_rparen, ")", ENDFN],
 [[1, 13], :on_sp, " ", BEG],
 [[1, 14], :on_op, "=", BEG],
 [[1, 15], :on_sp, " ", BEG],
 [[1, 16], :on_ident, "x", END|LABEL],
 [[1, 17], :on_sp, " ", END|LABEL],
 [[1, 18], :on_op, "*", BEG],
 [[1, 19], :on_sp, " ", BEG],
 [[1, 20], :on_ident, "x", END|LABEL]]

Will be interpreted by dead_end as a keyword but not an end:

irb(main):010:0> line = DeadEnd::CodeLine.new(line: "def square(x) = x * x", index: 0)
=>
#<DeadEnd::CodeLine:0x00007fd387985e60
...
irb(main):011:0> line.is_kw?
=> true
irb(main):012:0> line.is_end?
=> false

I think the appropriate thing to do would be to treat this line as both a keyword and an end. However, there might be other logic that wouldn't expect a kw and end on the same line. If we don't

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions