sirop 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/sirop/injection.rb +11 -0
- data/lib/sirop/prism_ext.rb +24 -0
- data/lib/sirop/sourcifier.rb +54 -36
- data/lib/sirop/version.rb +1 -1
- data/lib/sirop.rb +6 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a44761c6907c2bd7358e0b7d6c4079b8582949121ff32161b508a0950d0032c
|
4
|
+
data.tar.gz: 99cf621e80d420ec1a4245e8fd9efdbb06633614982d804d45f545f0a1966a0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de992959d865f0ace64d1be7b9c0149a10d193f54e2bfa0e9b20dcd2fe70f7bf4fe3ec5984c29a75cf89bc70dc385d29747ba372174bfe4286654b3543e0f946
|
7
|
+
data.tar.gz: '00393520ab9df84615c35a104411d4aad118c07ac4d4212debbf21df536f90883dd924e31e4d9064d4ce7344fa425716c292d4f9fbe3e1fb3b675ccea054fe95'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 2024-04-19 0.3
|
2
|
+
|
3
|
+
- Add support for injecting (prefixed) parameters to a lambda node
|
4
|
+
- Fix whitespace adjustment in DSL compiler
|
5
|
+
- Improve DSL compiler to support embedded string expressions
|
6
|
+
- Correctly handle eval'd proc
|
7
|
+
|
1
8
|
# 2024-02-27 0.2
|
2
9
|
|
3
10
|
- Update README
|
data/lib/sirop/prism_ext.rb
CHANGED
@@ -8,3 +8,27 @@ class Prism::BasicVisitor
|
|
8
8
|
self
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
class Prism::ParametersNode
|
13
|
+
attr_accessor :injected_prefix
|
14
|
+
end
|
15
|
+
|
16
|
+
class Prism::BlockParametersNode
|
17
|
+
attr_accessor :injected_parameters
|
18
|
+
end
|
19
|
+
|
20
|
+
class Prism::LambdaNode
|
21
|
+
# @param params [String] injected parameters
|
22
|
+
# @return [void]
|
23
|
+
def inject_parameters(params)
|
24
|
+
if parameters
|
25
|
+
if parameters.parameters
|
26
|
+
parameters.parameters.injected_prefix = Sirop::Injection.new(params)
|
27
|
+
else
|
28
|
+
parameters.injected_parameters = Sirop::Injection.new(params)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
instance_variable_set(:@parameters, Sirop::Injection.new("(#{params})"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/sirop/sourcifier.rb
CHANGED
@@ -30,11 +30,14 @@ module Sirop
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def adjust_whitespace(loc)
|
33
|
+
return if loc.is_a?(Sirop::Injection)
|
34
|
+
|
33
35
|
if @last_loc_start
|
34
|
-
|
35
|
-
|
36
|
+
line_diff = loc.start_line - @last_loc_end.first
|
37
|
+
if line_diff > 0
|
38
|
+
@buffer << "\n" * line_diff
|
36
39
|
@buffer << ' ' * loc.start_column
|
37
|
-
|
40
|
+
elsif line_diff == 0
|
38
41
|
ofs = loc.start_column - @last_loc_end.last
|
39
42
|
if ofs > 0
|
40
43
|
@buffer << ' ' * ofs
|
@@ -85,38 +88,41 @@ module Sirop
|
|
85
88
|
end
|
86
89
|
|
87
90
|
VISIT_PLANS = {
|
88
|
-
and:
|
89
|
-
assoc:
|
90
|
-
assoc_splat:
|
91
|
-
block:
|
92
|
-
block_argument:
|
93
|
-
block_parameter:
|
94
|
-
block_parameters:
|
95
|
-
break:
|
96
|
-
constant_path:
|
97
|
-
constant_read:
|
98
|
-
else:
|
99
|
-
embedded_statements:
|
100
|
-
false:
|
101
|
-
integer:
|
102
|
-
keyword_rest_parameter:
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
91
|
+
and: [:left, :operator_loc, :right],
|
92
|
+
assoc: :visit_child_nodes,
|
93
|
+
assoc_splat: [:operator_loc, :value],
|
94
|
+
block: [:opening_loc, :parameters, :body, :closing_loc],
|
95
|
+
block_argument: [:operator_loc, :expression],
|
96
|
+
block_parameter: [:operator_loc, :name_loc],
|
97
|
+
block_parameters: [:opening_loc, :injected_parameters, :parameters, :closing_loc],
|
98
|
+
break: [:keyword_loc, :arguments],
|
99
|
+
constant_path: [:parent, :delimiter_loc, :child],
|
100
|
+
constant_read: :emit_verbatim,
|
101
|
+
else: [:else_keyword_loc, :statements],
|
102
|
+
embedded_statements: [:opening_loc, :statements, :closing_loc],
|
103
|
+
false: :emit_verbatim,
|
104
|
+
integer: :emit_verbatim,
|
105
|
+
keyword_rest_parameter: [:operator_loc, :name_loc],
|
106
|
+
keyword_parameter: :emit_verbatim,
|
107
|
+
lambda: [:operator_loc, :parameters, :opening_loc, :body,
|
108
|
+
:closing_loc],
|
109
|
+
local_variable_read: :emit_verbatim,
|
110
|
+
local_variable_write: [:name_loc, :operator_loc, :value],
|
111
|
+
next: [:keyword_loc, :arguments],
|
112
|
+
nil: :emit_verbatim,
|
113
|
+
optional_parameter: [:name_loc, :operator_loc, :value],
|
114
|
+
optional_keyword_parameter: [:name_loc, :value],
|
115
|
+
or: [:left, :operator_loc, :right],
|
116
|
+
parentheses: [:opening_loc, :body, :closing_loc],
|
117
|
+
required_parameter: :emit_verbatim,
|
118
|
+
required_keyword_parameter: :emit_verbatim,
|
119
|
+
rest_parameter: [:operator_loc, :name_loc],
|
120
|
+
splat: [:operator_loc, :expression],
|
121
|
+
statements: :visit_child_nodes,
|
122
|
+
string: :emit_verbatim,
|
123
|
+
symbol: :emit_verbatim,
|
124
|
+
true: :emit_verbatim,
|
125
|
+
yield: [:keyword_loc, :lparen_loc, :arguments, :rparen_loc],
|
120
126
|
}
|
121
127
|
|
122
128
|
VISIT_PLANS.each do |key, plan|
|
@@ -152,9 +158,21 @@ module Sirop
|
|
152
158
|
end
|
153
159
|
|
154
160
|
def visit_parameters_node(node)
|
155
|
-
comma =
|
161
|
+
comma = false
|
162
|
+
# injected_prefix is a custom attribute added by Sirop to the
|
163
|
+
# ParametersNode class (in lib/sirop/prism_ext.rb). It is used
|
164
|
+
# as a way to add a first parameter to a block or method.
|
165
|
+
if node.injected_prefix
|
166
|
+
emit_code(node.injected_prefix)
|
167
|
+
# adjust last_loc_end for proper whitespace after comma
|
168
|
+
@last_loc_end[1] -= 2 if @last_loc_end
|
169
|
+
# binding.irb
|
170
|
+
comma = true
|
171
|
+
end
|
172
|
+
comma = visit_comma_separated_nodes(node.requireds, comma)
|
156
173
|
comma = visit_comma_separated_nodes(node.optionals, comma)
|
157
174
|
comma = visit_comma_separated_nodes(node.posts, comma)
|
175
|
+
comma = visit_comma_separated_nodes(node.keywords, comma)
|
158
176
|
if node.rest
|
159
177
|
emit_comma if comma
|
160
178
|
comma = true
|
data/lib/sirop/version.rb
CHANGED
data/lib/sirop.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'prism'
|
4
|
+
require 'sirop/injection'
|
4
5
|
require 'sirop/prism_ext'
|
5
6
|
require 'sirop/finder'
|
6
7
|
require 'sirop/sourcifier'
|
7
8
|
|
8
9
|
module Sirop
|
10
|
+
class Error < StandardError
|
11
|
+
end
|
12
|
+
|
9
13
|
class << self
|
10
14
|
def to_ast(obj)
|
11
15
|
case obj
|
@@ -43,6 +47,8 @@ module Sirop
|
|
43
47
|
super(node)
|
44
48
|
end
|
45
49
|
end
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
raise Sirop::Error, "Could not get source for proc"
|
46
52
|
end
|
47
53
|
|
48
54
|
def method_ast(method)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sirop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prism
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- lib/sirop.rb
|
51
51
|
- lib/sirop/finder.rb
|
52
|
+
- lib/sirop/injection.rb
|
52
53
|
- lib/sirop/prism_ext.rb
|
53
54
|
- lib/sirop/sourcifier.rb
|
54
55
|
- lib/sirop/version.rb
|