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.
@@ -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
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SyntaxErrorSearch
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -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
@@ -25,6 +25,4 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
-
29
- spec.add_dependency "parser"
30
28
  end
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.1
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-11-11 00:00:00.000000000 Z
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: