ffast 0.0.9 → 0.1.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/lib/fast.rb +17 -20
- data/lib/fast/experiment.rb +5 -5
- data/lib/fast/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b1063b0bb3b8dcc82515f0b10fc24601c6b322979d0a53eb6e65fa6f3ab439c
|
4
|
+
data.tar.gz: b984df89b42bb0f21c2f91567d37fe10e336fb489fdea3ad8ff5ae658dc1de34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf2973bf7e616dbd7fe1866abda708afd1e667ee2938d74f3204d26f228b8f235b017f6729cc083651627aee97ac924d6042ef73248e8d5bcd4491065f18ade
|
7
|
+
data.tar.gz: b6c77021c7db79ed8e7382e168409cfbc2c66b94681b6ba8fbcd6ec0842aedf3fe431ce894034640a2dfe2b22a8cf22884498d2b40df674e6a697aa16dd1282d
|
data/lib/fast.rb
CHANGED
@@ -95,7 +95,9 @@ module Fast
|
|
95
95
|
end
|
96
96
|
|
97
97
|
# Replaces content based on a pattern.
|
98
|
-
# @param
|
98
|
+
# @param [Astrolabe::Node] ast with the current AST to search.
|
99
|
+
# @param [String] pattern with the expression to be targeting nodes.
|
100
|
+
# @param [Proc] replacement gives the [Rewriter] context in the block.
|
99
101
|
# @example
|
100
102
|
# Fast.replace?(Fast.ast("a = 1"),"lvasgn") do |node|
|
101
103
|
# replace(node.location.name, 'variable_renamed')
|
@@ -115,9 +117,7 @@ module Fast
|
|
115
117
|
rewriter.rewrite(buffer, ast)
|
116
118
|
end
|
117
119
|
|
118
|
-
# Replaces the source of an {#ast_from_file} with
|
119
|
-
# based on a search.
|
120
|
-
# @return [String] with the content of the new file
|
120
|
+
# Replaces the source of an {Fast#ast_from_file} with
|
121
121
|
# and the same source if the pattern does not match.
|
122
122
|
def replace_file(file, pattern, &replacement)
|
123
123
|
ast = ast_from_file(file)
|
@@ -125,7 +125,7 @@ module Fast
|
|
125
125
|
end
|
126
126
|
|
127
127
|
# Search with pattern directly on file
|
128
|
-
# @return Array<Astrolabe::Node> that matches the pattern
|
128
|
+
# @return [Array<Astrolabe::Node>] that matches the pattern
|
129
129
|
def search_file(pattern, file)
|
130
130
|
node = ast_from_file(file)
|
131
131
|
search node, pattern
|
@@ -133,7 +133,7 @@ module Fast
|
|
133
133
|
|
134
134
|
# Capture elements from searches in files. Keep in mind you need to use `$`
|
135
135
|
# in the pattern to make it work.
|
136
|
-
# @return Array<Object> captured from the pattern matched in the file
|
136
|
+
# @return [Array<Object>] captured from the pattern matched in the file
|
137
137
|
def capture_file(pattern, file)
|
138
138
|
node = ast_from_file(file)
|
139
139
|
capture node, pattern
|
@@ -155,7 +155,7 @@ module Fast
|
|
155
155
|
end
|
156
156
|
|
157
157
|
# Return only captures from a search
|
158
|
-
# @return Array<Object> with all captured elements.
|
158
|
+
# @return [Array<Object>] with all captured elements.
|
159
159
|
# If the result is only a single capture, it will return the single element.
|
160
160
|
def capture(node, pattern)
|
161
161
|
res =
|
@@ -227,8 +227,8 @@ module Fast
|
|
227
227
|
result
|
228
228
|
end
|
229
229
|
|
230
|
-
# @return Array<String> with all ruby files from arguments.
|
231
|
-
# @param
|
230
|
+
# @return [Array<String>] with all ruby files from arguments.
|
231
|
+
# @param files can be file paths or directories.
|
232
232
|
# When the argument is a folder, it recursively fetches all `.rb` files from it.
|
233
233
|
def ruby_files_from(*files)
|
234
234
|
directories = files.select(&File.method(:directory?))
|
@@ -314,11 +314,6 @@ module Fast
|
|
314
314
|
# ExpressionParser empowers the AST search in Ruby.
|
315
315
|
# All classes inheriting Fast::Find have a grammar shortcut that is processed here.
|
316
316
|
#
|
317
|
-
# Exclamation Mark to negate: `!(int _)` is equivalent to a `not integer` node.
|
318
|
-
# Curly Braces allows [Any]: `({int float} _)` or `{(int _) (float _)}`.
|
319
|
-
# Square Braquets allows [All]: [(int _) !(int 0)] # all integer less zero.
|
320
|
-
# Dollar sign can be used to capture values: `(${int float} _)` will capture the node type.
|
321
|
-
#
|
322
317
|
# @example find a simple int node
|
323
318
|
# Fast.expression("int")
|
324
319
|
# # => #<Fast::Find:0x00007ffae39274e0 @token="int">
|
@@ -620,7 +615,8 @@ module Fast
|
|
620
615
|
end
|
621
616
|
|
622
617
|
# Matches any of the internal expressions. Works like a **OR** condition.
|
623
|
-
#
|
618
|
+
# @example Matchig int or float
|
619
|
+
# Fast.expression("{int float}")
|
624
620
|
class Any < Find
|
625
621
|
def match?(node)
|
626
622
|
token.any? { |expression| Fast.match?(node, expression) }
|
@@ -717,8 +713,8 @@ module Fast
|
|
717
713
|
|
718
714
|
# Find search captures recursively.
|
719
715
|
#
|
720
|
-
# @return Array<Object> of captures from the expression
|
721
|
-
# @return true in case of no captures in the expression
|
716
|
+
# @return [Array<Object>] of captures from the expression
|
717
|
+
# @return [true] in case of no captures in the expression
|
722
718
|
# @see Fast::Capture
|
723
719
|
# @see Fast::FindFromArgument
|
724
720
|
def find_captures(fast = @fast)
|
@@ -748,9 +744,10 @@ module Fast
|
|
748
744
|
end
|
749
745
|
end
|
750
746
|
|
751
|
-
#
|
752
|
-
#
|
753
|
-
# @return [void]
|
747
|
+
# Prepare token with previous captures
|
748
|
+
# @param [FindWithCapture] token set the current captures
|
749
|
+
# @return [void]
|
750
|
+
# @see [FindWithCapture#previous_captures]
|
754
751
|
def prepare_token(token)
|
755
752
|
case token
|
756
753
|
when Fast::FindWithCapture
|
data/lib/fast/experiment.rb
CHANGED
@@ -109,20 +109,20 @@ module Fast
|
|
109
109
|
@expression = expression
|
110
110
|
end
|
111
111
|
|
112
|
-
# @param
|
112
|
+
# @param block yields the node that matches and return the block in the
|
113
113
|
# instance context of a [Fast::Rewriter]
|
114
114
|
def edit(&block)
|
115
115
|
@replacement = block
|
116
116
|
end
|
117
117
|
|
118
|
-
# @param [String] that will be combined to find the {#files}
|
118
|
+
# @param [String] files_or_folders that will be combined to find the {#files}
|
119
119
|
def lookup(files_or_folders)
|
120
120
|
@files_or_folders = files_or_folders
|
121
121
|
end
|
122
122
|
|
123
123
|
# It calls the block after the replacement and use the result
|
124
124
|
# to drive the {Fast::ExperimentFile#ok_experiments} and {Fast::ExperimentFile#fail_experiments}.
|
125
|
-
# @param
|
125
|
+
# @param block yields a temporary file with the content replaced in the current round.
|
126
126
|
def policy(&block)
|
127
127
|
@ok_if = block
|
128
128
|
end
|
@@ -359,10 +359,10 @@ module Fast
|
|
359
359
|
end
|
360
360
|
done!
|
361
361
|
end
|
362
|
-
|
362
|
+
|
363
363
|
# Writes a new file with partial replacements based on the current combination.
|
364
364
|
# Raise error if no changes was made with the given combination indices.
|
365
|
-
# @param [Array<Integer>]
|
365
|
+
# @param [Array<Integer>] combination to be replaced.
|
366
366
|
def run_partial_replacement_with(combination)
|
367
367
|
content = partial_replace(*combination)
|
368
368
|
experimental_file = experimental_filename(combination)
|
data/lib/fast/version.rb
CHANGED