raka 0.5.0 → 0.7.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/VERSION +1 -1
- data/lib/raka/token.rb +33 -9
- data/lib/raka.rb +4 -2
- 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: 31017f34773fa0278274d9064dbc812eaf5e4e4d9ec1e5eb32c7001e6201dba1
|
4
|
+
data.tar.gz: 757d80aca83452fc44a1d39e25f03755b75233e7ed7570c1fb5e114d3c04a59c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39995d7c20c08d01446efaaa650652454f4d352292dd5f34c26cf28b9e59f52d7ab793a0e9c4cbc6d74d3151495883e5127f4d70a9b4791b80c29a91abae481f
|
7
|
+
data.tar.gz: d321708efcd445841f724b911a9f9622a887ea0c4b1309d26e2c042b4d82b71498b6ae70c67deaa372a76868e02aca7248e3815ea8025329650bdc6a46a47a37
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/raka/token.rb
CHANGED
@@ -9,8 +9,7 @@ end
|
|
9
9
|
|
10
10
|
# Context to preserve during the token chaining
|
11
11
|
class Context
|
12
|
-
attr_reader :ext
|
13
|
-
attr_reader :scopes
|
12
|
+
attr_reader :ext, :scopes
|
14
13
|
|
15
14
|
def initialize(ext, scopes = [])
|
16
15
|
@ext = ext
|
@@ -36,6 +35,7 @@ class Token
|
|
36
35
|
@inline_scope = inline_scope
|
37
36
|
@options = {}
|
38
37
|
@options[:input_exts] = input_exts
|
38
|
+
@compiler_options = @compiler.instance_variable_get(:@options)
|
39
39
|
end
|
40
40
|
|
41
41
|
def _options_
|
@@ -53,7 +53,7 @@ class Token
|
|
53
53
|
# xxx? is for minimal match
|
54
54
|
out_pattern = %r{^((?<scope>\S+)/)?}.source
|
55
55
|
out_pattern += %r{(?<target_scope>#{@inline_scope})/}.source unless @inline_scope.nil?
|
56
|
-
out_pattern += /(?<stem>(\S+))(?<ext>\.[
|
56
|
+
out_pattern += /(?<stem>(\S+))(?<ext>\.[^.]+)$/.source
|
57
57
|
info = Regexp.new(out_pattern).match(output)
|
58
58
|
res = Hash[info.names.zip(info.captures)]
|
59
59
|
unless info[:scope].nil?
|
@@ -153,23 +153,47 @@ class Token
|
|
153
153
|
end
|
154
154
|
|
155
155
|
# These two methods indicate that this is a pattern token
|
156
|
-
def [](pattern)
|
156
|
+
def [](pattern, options = {})
|
157
157
|
symbol = @chain.pop.to_s
|
158
158
|
# if the pattern contains child pattern like percent_(\d+), we change the capture to
|
159
159
|
# named capture so that it can be captured later. The name is symbol with the index, like func0
|
160
|
-
pattern = pattern.gsub(/\(\S+?\)/).with_index { |m, i| "(?<#{symbol}#{i}>#{m})" }
|
160
|
+
pattern = pattern.to_s.gsub(/\(\S+?\)/).with_index { |m, i| "(?<#{symbol}#{i}>#{m})" }
|
161
|
+
|
162
|
+
# merge global pattern defaults with provided options
|
163
|
+
options = @compiler_options&.pattern_options&.merge(options)
|
164
|
+
|
165
|
+
# build the pattern based on match mode
|
166
|
+
refined_pattern = case options[:match_mode]
|
167
|
+
when 'exact'
|
168
|
+
pattern.to_s
|
169
|
+
when 'prefix'
|
170
|
+
"#{pattern}\\w*"
|
171
|
+
else
|
172
|
+
raise "Invalid match_mode: #{match_mode}. Use 'exact' or 'prefix'"
|
173
|
+
end
|
161
174
|
|
162
175
|
# if the symbol is _, \S+ will be put in chain, it indicates not to capture,
|
163
176
|
# so just replace it with the refined pattern
|
164
177
|
if symbol == Pattern::ANY # match-everything and not bound
|
165
|
-
@chain.push
|
178
|
+
@chain.push refined_pattern
|
166
179
|
else
|
167
|
-
@chain.push "(?<#{symbol}>(#{
|
180
|
+
@chain.push "(?<#{symbol}>(#{refined_pattern}))"
|
168
181
|
end
|
169
182
|
self
|
170
183
|
end
|
171
184
|
|
172
|
-
def []=(pattern,
|
173
|
-
|
185
|
+
def []=(pattern, *args)
|
186
|
+
case args.length
|
187
|
+
when 1
|
188
|
+
# Standard: txt._[:pattern] = value
|
189
|
+
value = args[0]
|
190
|
+
@compiler.compile(self[pattern], value)
|
191
|
+
when 2
|
192
|
+
# With options: txt._[:pattern, {match_mode: 'exact'}] = value
|
193
|
+
options, value = args
|
194
|
+
@compiler.compile(self[pattern, options], value)
|
195
|
+
else
|
196
|
+
raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 2 or 3)"
|
197
|
+
end
|
174
198
|
end
|
175
199
|
end
|
data/lib/raka.rb
CHANGED
@@ -46,8 +46,10 @@ class Raka
|
|
46
46
|
type_aliases: {},
|
47
47
|
scopes: [],
|
48
48
|
lang: ['lang/shell'],
|
49
|
-
user_lang: []
|
49
|
+
user_lang: [],
|
50
|
+
pattern_options: { match_mode: 'prefix' }
|
50
51
|
}
|
52
|
+
options[:pattern_options] = defaults[:pattern_options].merge(options[:pattern_options] || {})
|
51
53
|
@options = options = OpenStruct.new(defaults.merge(options))
|
52
54
|
|
53
55
|
create_logger options.log_level || (ENV['LOG_LEVEL'] || Logger::INFO).to_i
|
@@ -58,7 +60,7 @@ class Raka
|
|
58
60
|
end
|
59
61
|
# specify root of scopes in options, scopes will append to each root
|
60
62
|
@scopes = options.scopes.empty? ? [] : [options.scopes]
|
61
|
-
@options.lang.each { |path| load File
|
63
|
+
@options.lang.each { |path| load File.join(File.dirname(__FILE__), "raka/#{path}/impl.rb") }
|
62
64
|
@options.user_lang.each { |path| load path.to_s + '.rb' }
|
63
65
|
|
64
66
|
# These are where the dsl starts
|