-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Heredocs in ruby are common sources of indentation even though they cannot cause either an "unmatched" or "unexpected" end syntax errors. To help avoid these false positives when parsing source, we first find and parse all heredocs. If the lines that contain the heredocs are valid, they'll be commented-out/hidden early on. This drastically decreases the chance that heredoc based indentation will lead to false positives.
- Loading branch information
Showing
9 changed files
with
678 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module SyntaxErrorSearch | ||
# Takes in a source, and returns blocks containing each heredoc | ||
class HeredocBlockParse | ||
private; attr_reader :code_lines, :lex; public | ||
|
||
def initialize(source:, code_lines: ) | ||
@code_lines = code_lines | ||
@lex = Ripper.lex(source) | ||
end | ||
|
||
def call | ||
blocks = [] | ||
beginning = [] | ||
@lex.each do |(line, col), event, *_| | ||
case event | ||
when :on_heredoc_beg | ||
beginning << line | ||
when :on_heredoc_end | ||
start_index = beginning.pop - 1 | ||
end_index = line - 1 | ||
blocks << CodeBlock.new(lines: code_lines[start_index..end_index]) | ||
end | ||
end | ||
|
||
blocks | ||
end | ||
end | ||
end |
Oops, something went wrong.