sirop 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: edde04771185a121f37a4a2df66569803c6f5b18d2a6739923c2a58cedacfc24
4
+ data.tar.gz: 364af589b7a6ca122f32447c23dc281b296e6ade1b9f280dca3e6e51b50d456b
5
+ SHA512:
6
+ metadata.gz: 6bb9fc18cefdbe071ba2b1d7f54fd0aa8111f97ffde49c362b4314e92d300e33075711a956384c15ee7880dab8bc85524d63de3ef5625278aa35917fce983066
7
+ data.tar.gz: e35e58fc9ba7d223d68298a3a25c8cb30596a1f548e314298de10730b6ea49456486fff541bee1cca5df3f3b092cd59e98fe3e9634a92be75f1d5b4bf5532c6e
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 2024-02-20 0.1
2
+
3
+ - Find node for a given `Proc` object
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Sirop
2
+
3
+ Sirop is a Ruby code rewriter. More information coming soon...
4
+
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sirop
4
+ class BlockFinder < Prism::BasicVisitor
5
+ attr_accessor :block_node
6
+
7
+ def initialize(proc, lineno)
8
+ @proc = proc
9
+ @lineno = lineno
10
+ end
11
+
12
+ def find(program)
13
+ # p program
14
+ # puts
15
+ catch(@proc) {
16
+ visit(program)
17
+ nil
18
+ }
19
+ end
20
+
21
+ def visit_lambda_node(node)
22
+ if node.location.start_line == @lineno
23
+ throw @proc, node
24
+ else
25
+ visit_child_nodes(node)
26
+ end
27
+ end
28
+
29
+ def visit_call_node(node)
30
+ case node.name
31
+ when :proc, :lambda
32
+ if node.block && node.block.location.start_line == @lineno
33
+ throw @proc, node
34
+ end
35
+ end
36
+ end
37
+
38
+ def method_missing(sym, node, *args)
39
+ visit_child_nodes(node)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module Sirop
2
+ # Sirop version
3
+ VERSION = '0.1'
4
+ end
data/lib/sirop.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prism'
4
+ require 'sirop/block_finder'
5
+
6
+ module Sirop
7
+ class << self
8
+ def find(obj)
9
+ case obj
10
+ when Proc
11
+ find_proc(obj)
12
+ else
13
+ raise ArgumentError, "Invalid object type"
14
+ end
15
+ end
16
+
17
+ def find_proc(proc)
18
+ fn, lineno = proc.source_location
19
+ pr = Prism.parse(IO.read(fn), filepath: fn)
20
+ program = pr.value
21
+
22
+ finder = Sirop::BlockFinder.new(proc, lineno)
23
+ finder.find(program)
24
+ end
25
+
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sirop
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sharon Rosner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prism
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.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.19.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.22.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.22.0
41
+ description:
42
+ email: sharon@noteflakes.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - README.md
47
+ files:
48
+ - CHANGELOG.md
49
+ - README.md
50
+ - lib/sirop.rb
51
+ - lib/sirop/block_finder.rb
52
+ - lib/sirop/version.rb
53
+ homepage: http://github.com/digital-fabric/sirop
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ source_code_uri: https://github.com/digital-fabric/sirop
58
+ documentation_uri: https://www.rubydoc.info/gems/sirop
59
+ homepage_uri: https://github.com/digital-fabric/sirop
60
+ changelog_uri: https://github.com/digital-fabric/sirop/blob/main/CHANGELOG.md
61
+ post_install_message:
62
+ rdoc_options:
63
+ - "--title"
64
+ - Sirop
65
+ - "--main"
66
+ - README.md
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.5.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: 'Sirop: Ruby code rewriter'
84
+ test_files: []