Skip to content

Conversation

@schneems
Copy link
Collaborator

@schneems schneems commented Dec 11, 2020

[close #32] Improve trailing end results

When the last keyword in a given logical "block" is missing the end then it's unclear if the missing end came from the surrounding block, or from the last keyword. Example:

class Dog
  def bark
    puts "woof"
end

Before this patch the output of this code will be:

    ❯ 1  class Dog

With this patch the output of this code will be:

    ❯ 1  class Dog
    ❯ 2    def bark
    ❯ 4  end

There's some key realizations to get to this point. First, while the output of the "before" case only looks like it's one line, it's actually a much larger block that holds down to line 4 but everything else is hidden. Second: We can detect for this scenario using lexing but starting at the last end of the problem block and working backwards to find a mismatched keyword.

@schneems schneems marked this pull request as draft December 11, 2020 21:47
@schneems schneems force-pushed the schneems/internal-context branch from bce58af to 462f0b7 Compare December 28, 2020 17:19
@schneems schneems changed the title Schneems/internal context [close #32] Improve trailing end results Dec 28, 2020
@schneems schneems marked this pull request as ready for review December 28, 2020 17:26
This was moved to `spec/integration/exe_cli_spec.rb`
When the last keyword in a given logical "block" is missing the `end` then it's unclear if the missing end came from the surrounding block, or from the last keyword. Example:

```ruby
class Dog
  def bark
    puts "woof"
end
```

Before this patch the output of this code will be:

```
    ❯ 1  class Dog
``

With this patch the output of this code will be:

```
    ❯ 1  class Dog
    ❯ 2    def bark
    ❯ 4  end
```

There's some key realizations to get to this point. First, while the output of the "before" case only looks like it's one line, it's actually a much larger block that holds down to line 4 but everything else is hidden. Second: We can detect for this scenario using lexing but starting at the last end of the problem block and working backwards to find a mismatched keyword.
@schneems schneems force-pushed the schneems/internal-context branch from 462f0b7 to 4b8bdf3 Compare December 28, 2020 17:28
@schneems schneems merged commit 6d587d1 into main Dec 28, 2020
@schneems schneems deleted the schneems/internal-context branch December 28, 2020 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trailing missing end bad results

2 participants