syntax_search 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +13 -0
- data/CHANGELOG.md +24 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -5
- data/README.md +28 -15
- data/assets/syntax_search.gif +0 -0
- data/exe/syntax_search +1 -0
- data/lib/syntax_search.rb +23 -14
- data/lib/syntax_search/around_block_scan.rb +193 -0
- data/lib/syntax_search/block_expand.rb +74 -0
- data/lib/syntax_search/capture_code_context.rb +62 -0
- data/lib/syntax_search/code_block.rb +24 -165
- data/lib/syntax_search/code_frontier.rb +40 -201
- data/lib/syntax_search/code_line.rb +42 -1
- data/lib/syntax_search/code_search.rb +60 -20
- data/lib/syntax_search/display_code_with_line_numbers.rb +56 -0
- data/lib/syntax_search/display_invalid_blocks.rb +46 -45
- data/lib/syntax_search/heredoc_block_parse.rb +30 -0
- data/lib/syntax_search/lex_all.rb +58 -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 +13 -17
@@ -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.
|
4
|
+
version: 0.2.0
|
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-07 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,6 +20,7 @@ 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"
|
@@ -44,18 +31,27 @@ files:
|
|
44
31
|
- LICENSE.txt
|
45
32
|
- README.md
|
46
33
|
- Rakefile
|
34
|
+
- assets/syntax_search.gif
|
47
35
|
- bin/console
|
48
36
|
- bin/setup
|
49
37
|
- exe/syntax_search
|
50
38
|
- lib/syntax_search.rb
|
39
|
+
- lib/syntax_search/around_block_scan.rb
|
51
40
|
- lib/syntax_search/auto.rb
|
41
|
+
- lib/syntax_search/block_expand.rb
|
42
|
+
- lib/syntax_search/capture_code_context.rb
|
52
43
|
- lib/syntax_search/code_block.rb
|
53
44
|
- lib/syntax_search/code_frontier.rb
|
54
45
|
- lib/syntax_search/code_line.rb
|
55
46
|
- lib/syntax_search/code_search.rb
|
47
|
+
- lib/syntax_search/display_code_with_line_numbers.rb
|
56
48
|
- lib/syntax_search/display_invalid_blocks.rb
|
57
49
|
- lib/syntax_search/fyi.rb
|
50
|
+
- lib/syntax_search/heredoc_block_parse.rb
|
51
|
+
- lib/syntax_search/lex_all.rb
|
52
|
+
- lib/syntax_search/parse_blocks_from_indent_line.rb
|
58
53
|
- lib/syntax_search/version.rb
|
54
|
+
- lib/syntax_search/who_dis_syntax_error.rb
|
59
55
|
- syntax_search.gemspec
|
60
56
|
homepage: https://github.com/zombocom/syntax_search.git
|
61
57
|
licenses:
|