Skip to content

Also works with missing } #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
obromios opened this issue Dec 1, 2020 · 6 comments
Closed

Also works with missing } #18

obromios opened this issue Dec 1, 2020 · 6 comments

Comments

@obromios
Copy link

obromios commented Dec 1, 2020

Although it is kind of obvious, I was delighted to see this also picks up missing braces i.e

a = ary.map {|x| x**2

It might be worth mentioning this in the Readme.

This would have saved me hours of frustration when I was first learning ruby, and even today, it will still save time, so thank you very much. Hope it ends up in standard ruby.

It would be great if someone put this code into the common editors, e.g. Sublime Text Linter.

@mapreal19
Copy link

This can't go into rubocop?

@schneems
Copy link
Collaborator

schneems commented Dec 3, 2020

This would have saved me hours of frustration when I was first learning ruby, and even today, it will still save time, so thank you very much. Hope it ends up in standard ruby.

Great! There's still some sharp edges that hopefully can be worked out. Namely output for large files is really unwieldy and there's a few indentation patterns that are reasonable that we should better support. Thanks for trying it out!

This can't go into rubocop?

Assuming "this" is this library? I think rubocop would error on this as it's not parseable, but I've no idea what it would do with it. I think probably just give you the same error ruby gives.

@schneems schneems closed this as completed Dec 3, 2020
@schneems
Copy link
Collaborator

schneems commented Dec 3, 2020

As a side note, that this works is kind-of an accident.

$ syntax_search bad.rb

SyntaxSearch: Missing `end` detected

This code has a missing `end`. Ensure that all
syntax keywords (`def`, `do`, etc.) have a matching `end`.

file: /private/tmp/2314b597165519808e4b1d8a07b3129c/bad.rb
simplified:

    ❯ 1  Array().each {|foo| foo += 2

⛄ 2.7.2 🚀  /tmp/2314b597165519808e4b1d8a07b3129c
$ ruby -wc bad.rb
bad.rb:1: syntax error, unexpected end-of-input, expecting '}'

I didn't realize that unexpected end-of-input could be generated via other methods (though it makes total sense), but I'm glad the current solution is generic enough to handle this case :)

@obromios
Copy link
Author

obromios commented Dec 4, 2020

Good software engineering on your part.

By a strange coincidence, right now I am learning the syntax for Arduino language (a C++ dialect), and just spent 10 minutes struggling with exactly this problem (a missing '}' causing a long syntax error at an unrelated place). Looks like this could be of use in other languages.

@mapreal19
Copy link

@schneems Just tried and this is what you get:

image

I wonder if it was possible to include it on rubocop via an extension (sorry, I should have posted this in another issue)

schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
@schneems
Copy link
Collaborator

I'm updating the message to show we have explicit support for | and } as well as end #29

schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 10, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Dec 16, 2020
SyntaxSearch works for other missing keywords other than `end` that would otherwise trigger an `unexpected end` error. This commit adds more explicit banners for these cases.

#18
schneems added a commit that referenced this issue Jan 15, 2022
# This is the 1st commit message:

Move queue logic and engulf logic to a class

The queuing and engulfing logic are tied together. We can bundle the two of them into a single class with a specific interface.
# This is the commit message #2:

WIP A*ish

# This is the commit message #3:

WIP with lex_diff OMG

# This is the commit message #4:

WIP Pull out "grab equal" logic of UpDownExpand

# This is the commit message #5:

WIP move class to proper file location

# This is the commit message #6:

WIP Fix spelling of method

# This is the commit message #7:

WIP LOL search

# This is the commit message #8:

Runs, finds the large code blocks, but is too greedy

# This is the commit message #9:

Move LexDiff to own class, refactor to an array

We're never using the hash keys so we don't need them. We can save memory and time by storing the values as an array.

# This is the commit message #10:

WIP LOL spec

# This is the commit message #11:

Micro optimize lex diff

# This is the commit message #12:

UpDownExpand fix major bug with internal mutability

When calling `line.lex_detect.dup` it was duplicating the outer memory, but not the inner memory. Internally we're using an array and the old array was still being referenced and mutated.

# This is the commit message #13:

LexDiff Huge perf upgrade

Store values in the object instead of an array.

# This is the commit message #14:

WIP playing with fuzzing this into the old algorithm

# This is the commit message #15:

WORKS and is hella fast

# This is the commit message #16:

WIP docs

# This is the commit message #17:

Put a max band on number of iterations

Unbounded while loops scare me, in theory this class should never iterate more than line times, but mistakes happen. When they do I want feedback for the user without disrupting the rest of their program.

# This is the commit message #18:

WIP Cleanup and docs

# This is the commit message #19:

WIP Cleanup and docs

# This is the commit message #20:

Standardrb

# This is the commit message #21:

Standardrb

# This is the commit message #22:

Refactor LexDiff, remove unused methods, add docs
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

No branches or pull requests

3 participants