syntax_search 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +13 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -5
- data/README.md +39 -20
- data/assets/syntax_search.gif +0 -0
- data/lib/syntax_search.rb +23 -15
- data/lib/syntax_search/around_block_scan.rb +91 -0
- data/lib/syntax_search/block_expand.rb +78 -0
- data/lib/syntax_search/code_block.rb +16 -165
- data/lib/syntax_search/code_frontier.rb +40 -201
- data/lib/syntax_search/code_search.rb +45 -20
- data/lib/syntax_search/display_invalid_blocks.rb +24 -13
- data/lib/syntax_search/heredoc_block_parse.rb +30 -0
- data/lib/syntax_search/parse_blocks_from_indent_line.rb +56 -0
- data/lib/syntax_search/version.rb +1 -1
- data/lib/syntax_search/who_dis_syntax_error.rb +32 -0
- data/syntax_search.gemspec +0 -2
- metadata +12 -18
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxErrorSearch
|
4
|
+
# Takes in a source, and returns blocks containing each heredoc
|
5
|
+
class HeredocBlockParse
|
6
|
+
private; attr_reader :code_lines, :lex; public
|
7
|
+
|
8
|
+
def initialize(source:, code_lines: )
|
9
|
+
@code_lines = code_lines
|
10
|
+
@lex = Ripper.lex(source)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
blocks = []
|
15
|
+
beginning = []
|
16
|
+
@lex.each do |(line, col), event, *_|
|
17
|
+
case event
|
18
|
+
when :on_heredoc_beg
|
19
|
+
beginning << line
|
20
|
+
when :on_heredoc_end
|
21
|
+
start_index = beginning.pop - 1
|
22
|
+
end_index = line - 1
|
23
|
+
blocks << CodeBlock.new(lines: code_lines[start_index..end_index])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
blocks
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxErrorSearch
|
4
|
+
# This class is responsible for generating initial code blocks
|
5
|
+
# that will then later be expanded.
|
6
|
+
#
|
7
|
+
# The biggest concern when guessing about code blocks, is accidentally
|
8
|
+
# grabbing one that contains only an "end". In this example:
|
9
|
+
#
|
10
|
+
# def dog
|
11
|
+
# begonn # mispelled `begin`
|
12
|
+
# puts "bark"
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# The following lines would be matched (from bottom to top):
|
17
|
+
#
|
18
|
+
# 1) end
|
19
|
+
#
|
20
|
+
# 2) puts "bark"
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# 3) begonn
|
24
|
+
# puts "bark"
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# At this point it has no where else to expand, and it will yield this inner
|
28
|
+
# code as a block
|
29
|
+
class ParseBlocksFromIndentLine
|
30
|
+
attr_reader :code_lines
|
31
|
+
|
32
|
+
def initialize(code_lines: )
|
33
|
+
@code_lines = code_lines
|
34
|
+
end
|
35
|
+
|
36
|
+
# Builds blocks from bottom up
|
37
|
+
def each_neighbor_block(target_line)
|
38
|
+
scan = AroundBlockScan.new(code_lines: code_lines, block: CodeBlock.new(lines: target_line))
|
39
|
+
.skip(:empty?)
|
40
|
+
.skip(:hidden?)
|
41
|
+
.scan_while {|line| line.indent >= target_line.indent }
|
42
|
+
|
43
|
+
neighbors = @code_lines[scan.before_index..scan.after_index]
|
44
|
+
|
45
|
+
until neighbors.empty?
|
46
|
+
lines = [neighbors.pop]
|
47
|
+
while (block = CodeBlock.new(lines: lines)) && block.invalid? && neighbors.any?
|
48
|
+
lines.prepend neighbors.pop
|
49
|
+
end
|
50
|
+
|
51
|
+
yield block if block
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxErrorSearch
|
4
|
+
# Determines what type of syntax error is in the source
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# puts WhoDisSyntaxError.new("def foo;").call.error_symbol
|
9
|
+
# # => :missing_end
|
10
|
+
class WhoDisSyntaxError < Ripper
|
11
|
+
attr_reader :error, :run_once, :error_symbol
|
12
|
+
|
13
|
+
def call
|
14
|
+
@run_once ||= begin
|
15
|
+
parse
|
16
|
+
true
|
17
|
+
end
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_parse_error(msg)
|
22
|
+
@error = msg
|
23
|
+
if @error.match?(/unexpected end-of-input/)
|
24
|
+
@error_symbol = :missing_end
|
25
|
+
elsif @error.match?(/unexpected `end'/) || @error.match?(/expecting end-of-input/)
|
26
|
+
@error_symbol = :unmatched_end
|
27
|
+
else
|
28
|
+
@error_symbol = :nope
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/syntax_search.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- schneems
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: parser
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: When you get an "unexpected end" in your syntax this gem helps you find
|
28
14
|
it
|
29
15
|
email:
|
@@ -34,27 +20,35 @@ extensions: []
|
|
34
20
|
extra_rdoc_files: []
|
35
21
|
files:
|
36
22
|
- ".circleci/config.yml"
|
23
|
+
- ".github/workflows/check_changelog.yml"
|
37
24
|
- ".gitignore"
|
38
25
|
- ".rspec"
|
39
26
|
- ".travis.yml"
|
27
|
+
- CHANGELOG.md
|
40
28
|
- CODE_OF_CONDUCT.md
|
41
29
|
- Gemfile
|
42
30
|
- Gemfile.lock
|
43
31
|
- LICENSE.txt
|
44
32
|
- README.md
|
45
33
|
- Rakefile
|
34
|
+
- assets/syntax_search.gif
|
46
35
|
- bin/console
|
47
36
|
- bin/setup
|
48
37
|
- exe/syntax_search
|
49
38
|
- lib/syntax_search.rb
|
39
|
+
- lib/syntax_search/around_block_scan.rb
|
50
40
|
- lib/syntax_search/auto.rb
|
41
|
+
- lib/syntax_search/block_expand.rb
|
51
42
|
- lib/syntax_search/code_block.rb
|
52
43
|
- lib/syntax_search/code_frontier.rb
|
53
44
|
- lib/syntax_search/code_line.rb
|
54
45
|
- lib/syntax_search/code_search.rb
|
55
46
|
- lib/syntax_search/display_invalid_blocks.rb
|
56
47
|
- lib/syntax_search/fyi.rb
|
48
|
+
- lib/syntax_search/heredoc_block_parse.rb
|
49
|
+
- lib/syntax_search/parse_blocks_from_indent_line.rb
|
57
50
|
- lib/syntax_search/version.rb
|
51
|
+
- lib/syntax_search/who_dis_syntax_error.rb
|
58
52
|
- syntax_search.gemspec
|
59
53
|
homepage: https://github.com/zombocom/syntax_search.git
|
60
54
|
licenses:
|
@@ -77,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
71
|
- !ruby/object:Gem::Version
|
78
72
|
version: '0'
|
79
73
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.1.4
|
81
75
|
signing_key:
|
82
76
|
specification_version: 4
|
83
77
|
summary: Find syntax errors in your source in a snap
|