statsailr 0.7.1 → 0.7.5
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/README.md +21 -20
- data/lib/statsailr/block_builder/sts_block.rb +106 -4
- data/lib/statsailr/block_builder/sts_block_parse_proc_opts.rb +14 -8
- data/lib/statsailr/block_to_r/sts_lazy_func_gen.rb +44 -0
- data/lib/statsailr/parser/sts_parse.output +397 -264
- data/lib/statsailr/parser/sts_parse.ry +19 -7
- data/lib/statsailr/parser/sts_parse.tab.rb +269 -145
- data/lib/statsailr/scanner/sts_scanner.rb +30 -51
- data/lib/statsailr/sts_build_exec.rb +57 -24
- data/lib/statsailr/version.rb +1 -1
- metadata +2 -2
@@ -9,49 +9,8 @@ SQ_STR_PATTERN = /'(\\'|[^'\n])*'/
|
|
9
9
|
DQ_STR_PATTERN = /"(\\"|[^"\n])*"/
|
10
10
|
end
|
11
11
|
|
12
|
-
module STSScannerSupport
|
13
|
-
def interpret_escape_sequences(str)
|
14
|
-
# This deals with escape sequences in double quoted string literals
|
15
|
-
# The behavior should be same as libsailr (or datasailr)
|
16
|
-
new_str = ""
|
17
|
-
str_array = str.split(//)
|
18
|
-
idx = 0
|
19
|
-
while( idx < str_array.size) do
|
20
|
-
c = str_array[idx]
|
21
|
-
if(c == "\\")
|
22
|
-
idx = idx + 1
|
23
|
-
c = str_array[idx]
|
24
|
-
raise "Tokenizer error: double quoted string literal should never end with \\" if idx >= str_array.size
|
25
|
-
case c
|
26
|
-
when 't'
|
27
|
-
new_str << "\t"
|
28
|
-
when 'n'
|
29
|
-
new_str << "\n"
|
30
|
-
when 'r'
|
31
|
-
new_str << "\r"
|
32
|
-
when "\\"
|
33
|
-
new_str << "\\"
|
34
|
-
when "\'"
|
35
|
-
new_str << "\'"
|
36
|
-
when "\""
|
37
|
-
new_str << "\""
|
38
|
-
when '?'
|
39
|
-
new_str << '?'
|
40
|
-
else
|
41
|
-
new_str << c
|
42
|
-
end
|
43
|
-
else
|
44
|
-
new_str << c
|
45
|
-
end
|
46
|
-
idx = idx + 1
|
47
|
-
end
|
48
|
-
return new_str
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
12
|
class STSScanner
|
53
13
|
include ::STSConstants
|
54
|
-
include ::STSScannerSupport
|
55
14
|
|
56
15
|
# Initialization & Terminating methods
|
57
16
|
|
@@ -151,9 +110,9 @@ class STSScanner
|
|
151
110
|
when scan(INT_PATTERN)
|
152
111
|
tokens << [:NUMBER, matched.to_i ]
|
153
112
|
when scan(SQ_STR_PATTERN)
|
154
|
-
tokens << [:
|
113
|
+
tokens << [:SQ_STRING, matched[Range.new(1, -2)] ]
|
155
114
|
when scan(DQ_STR_PATTERN)
|
156
|
-
tokens << [:
|
115
|
+
tokens << [:DQ_STRING, matched[Range.new(1, -2)] ]
|
157
116
|
when scan(/[ \t]/)
|
158
117
|
#ignore
|
159
118
|
else
|
@@ -221,6 +180,8 @@ class STSScanner
|
|
221
180
|
|
222
181
|
def scan_proc_special()
|
223
182
|
case
|
183
|
+
when scan(/\=\=/)
|
184
|
+
return :P_DEQ
|
224
185
|
when scan(/\=/)
|
225
186
|
return :P_EQ
|
226
187
|
when scan(/\*/)
|
@@ -229,14 +190,32 @@ class STSScanner
|
|
229
190
|
return :P_PLUS
|
230
191
|
when scan(/\-/)
|
231
192
|
return :P_MINUS
|
232
|
-
when scan(
|
233
|
-
return :
|
193
|
+
when scan(/%%/)
|
194
|
+
return :P_INTDEV
|
195
|
+
when scan(/%\/%/)
|
196
|
+
return :P_MOD
|
234
197
|
when scan(/\%in\%/)
|
235
198
|
return :P_IN
|
236
|
-
when scan(
|
237
|
-
return :
|
199
|
+
when scan(/&&/)
|
200
|
+
return :P_DAND
|
201
|
+
when scan(/\|\|/)
|
202
|
+
return :P_DOR
|
203
|
+
when scan(/&/)
|
204
|
+
return :P_AND
|
205
|
+
when scan(/\|/)
|
206
|
+
return :P_OR
|
207
|
+
when scan(/>/)
|
208
|
+
return :P_LT
|
209
|
+
when scan(/</)
|
210
|
+
return :P_ST
|
211
|
+
when scan(/>=/)
|
212
|
+
return :P_LTE
|
213
|
+
when scan(/<=/)
|
214
|
+
return :P_STE
|
215
|
+
when scan(/\^/)
|
216
|
+
return :P_HAT
|
238
217
|
when scan(/\~/)
|
239
|
-
return :
|
218
|
+
return :P_TILDE
|
240
219
|
when scan(/\:/)
|
241
220
|
return :P_COLON
|
242
221
|
when scan(/\(/)
|
@@ -265,9 +244,9 @@ class STSScanner
|
|
265
244
|
when scan(INT_PATTERN)
|
266
245
|
tokens << [:NUMBER, matched.to_i ]
|
267
246
|
when scan(SQ_STR_PATTERN)
|
268
|
-
tokens << [:
|
247
|
+
tokens << [:SQ_STRING, matched[Range.new(1, -2)] ]
|
269
248
|
when scan(DQ_STR_PATTERN)
|
270
|
-
tokens << [:
|
249
|
+
tokens << [:DQ_STRING, matched[Range.new(1, -2)] ]
|
271
250
|
when type = scan_proc_special()
|
272
251
|
tokens << [ type , matched ]
|
273
252
|
when scan(/[ \t]/) # Separators
|
@@ -279,7 +258,7 @@ class STSScanner
|
|
279
258
|
@scanner.unscan
|
280
259
|
break
|
281
260
|
when scan(/\//) # slash to start options
|
282
|
-
tokens << [:
|
261
|
+
tokens << [:P_SLASH, matched]
|
283
262
|
else
|
284
263
|
scan(/.*\n/)
|
285
264
|
raise "Current PROC line cannot be tokenized." + matched
|
@@ -3,8 +3,8 @@ require "statsailr/sts_output/output_manager"
|
|
3
3
|
require "statsailr/block_to_r/proc_setting_support/proc_setting_manager.rb"
|
4
4
|
|
5
5
|
module StatSailr
|
6
|
-
def self.initR()
|
7
|
-
RBridge.init_embedded_r()
|
6
|
+
def self.initR( unlimited_cstack )
|
7
|
+
RBridge.init_embedded_r( unlimited_cstack: unlimited_cstack )
|
8
8
|
puts "R program initialized"
|
9
9
|
end
|
10
10
|
|
@@ -26,34 +26,54 @@ def self.initial_setting_for_r(device_info)
|
|
26
26
|
RBridge.exec_function_no_return(attach_widget_func)
|
27
27
|
@new_device_info = { "file_output" => false, "dev_off_required" => false }
|
28
28
|
|
29
|
-
when "cairoraster" # (e.g.) ["CairoRaster", {"width" => 800, "height" => 600, "
|
29
|
+
when "cairoraster" # (e.g.) ["CairoRaster", {"width" => 800, "height" => 600 }, {"file_output_opt" => {"dir_path"=> dir_to_save , "prefix"=> "plot", "type" => "png"} }]
|
30
30
|
puts "Use Cairo function in Cairo library"
|
31
31
|
if ! device_info[1].is_a?(Hash)
|
32
32
|
raise "The second element of device info needs to be Hash"
|
33
33
|
end
|
34
|
-
cairo_info = device_info[1]
|
35
|
-
|
34
|
+
cairo_info = device_info[1].dup
|
35
|
+
file_output_opt = device_info[2]["file_output_opt"]
|
36
|
+
if ! ["png", "jpeg"].include? file_output_opt["type"]
|
36
37
|
raise "only png or jpeg is supported for type"
|
37
38
|
else
|
38
|
-
case
|
39
|
+
case file_output_opt["type"]
|
39
40
|
when "png"
|
40
41
|
# load png library
|
41
42
|
lib_func = RBridge.create_library_function("png")
|
42
43
|
RBridge.exec_function_no_return(lib_func)
|
43
44
|
when "jpeg"
|
44
45
|
# use default jpeg device
|
46
|
+
lib_func = RBridge.create_library_function("jpeg")
|
47
|
+
RBridge.exec_function_no_return(lib_func)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
lib_func = RBridge.create_library_function("Cairo")
|
48
51
|
RBridge.exec_function_no_return(lib_func)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
|
53
|
+
@new_device_info = { "file_output" => true, "dev_off_required" => true ,"file_output_opt" => file_output_opt,
|
54
|
+
"dev_control" => {
|
55
|
+
"new" => lambda {
|
56
|
+
RBridge.exec_function_no_return(
|
57
|
+
RBridge.create_function_call("Cairo",
|
58
|
+
{ "width" => RBridge.create_intvec([ cairo_info["width"] ]),
|
59
|
+
"height" => RBridge.create_intvec([ cairo_info["height"] ]),
|
60
|
+
"type" => RBridge.create_strvec([ "raster" ]) }))
|
61
|
+
},
|
62
|
+
"off" => lambda {
|
63
|
+
RBridge.exec_function_no_return(
|
64
|
+
RBridge.create_function_call("dev.off", {}))
|
65
|
+
},
|
66
|
+
"get_size" => lambda {
|
67
|
+
{:width => cairo_info["width"], :height => cairo_info["height"]}
|
68
|
+
},
|
69
|
+
"set_size" => lambda {|width, height|
|
70
|
+
cairo_info["width"] = width
|
71
|
+
cairo_info["height"] = height
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
@new_device_info["dev_control"]["new"].call()
|
76
|
+
|
57
77
|
else
|
58
78
|
puts "Unknown device type: #{device_type}"
|
59
79
|
end
|
@@ -122,6 +142,7 @@ end
|
|
122
142
|
|
123
143
|
|
124
144
|
def self.build_exec( script , initR_beforeExec: false , endR_afterExec: false , block_idx_start: 1, set_working_dir: nil, device_info: nil,
|
145
|
+
unlimited_cstack: false,
|
125
146
|
output_mngr: Output::OutputManager.new(capture: false),
|
126
147
|
procs_gem: "statsailr_procs_base" )
|
127
148
|
|
@@ -138,7 +159,7 @@ output_mngr.move_up()
|
|
138
159
|
if tokens.empty?
|
139
160
|
puts "Input token is empty"
|
140
161
|
if initR_beforeExec
|
141
|
-
initR()
|
162
|
+
initR( unlimited_cstack )
|
142
163
|
initial_setting_for_r( device_info )
|
143
164
|
|
144
165
|
output_mngr.move_to_new_node("Load PROCs")
|
@@ -179,7 +200,7 @@ gram_nodes.each(){|node|
|
|
179
200
|
require_relative("block_to_r/sts_block_to_r.rb")
|
180
201
|
|
181
202
|
if initR_beforeExec
|
182
|
-
initR()
|
203
|
+
initR( unlimited_cstack )
|
183
204
|
initial_setting_for_r( device_info )
|
184
205
|
|
185
206
|
output_mngr.move_to_new_node("Load PROCs")
|
@@ -252,17 +273,29 @@ blocks.each(){|blk|
|
|
252
273
|
else
|
253
274
|
if @new_device_info["file_output"] == true
|
254
275
|
# The plot needs to be saved on disk.
|
255
|
-
|
276
|
+
file_output_opt = @new_device_info["file_output_opt"]
|
256
277
|
temp_path = ""
|
257
|
-
temp_file = Tempfile.new( [
|
278
|
+
temp_file = Tempfile.new( [file_output_opt["prefix"] , "." + file_output_opt["type"] ] , file_output_opt["dir_path"] )
|
258
279
|
temp_path = temp_file.path
|
259
280
|
temp_file.close(true)
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
281
|
+
|
282
|
+
if ["png", "jpeg" ].include? file_output_opt["type"]
|
283
|
+
# writePNG( image=Cairo.capture( device=dev.cur() ), target="./plot.png" )
|
284
|
+
r_func_curr_dev = RBridge::create_function_call("dev.cur", {})
|
285
|
+
r_func_cairo_capture = RBridge::create_function_call("Cairo.capture",{"device" => r_func_curr_dev})
|
286
|
+
r_str_file_path = RBridge::create_strvec([temp_path])
|
287
|
+
if file_output_opt["type"] == "png"
|
288
|
+
r_func_write_png = RBridge::create_function_call("writePNG", {"image" => r_func_cairo_capture, "target" => r_str_file_path })
|
289
|
+
RBridge::exec_function_no_return( r_func_write_png )
|
290
|
+
elsif file_output_opt["type"] == "jpeg"
|
291
|
+
r_func_write_jpeg = RBridge::create_function_call("writeJPEG", {"image" => r_func_cairo_capture, "target" => r_str_file_path })
|
292
|
+
RBridge::exec_function_no_return( r_func_write_jpeg )
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
@new_device_info["dev_control"]["off"].call()
|
297
|
+
@new_device_info["dev_control"]["new"].call()
|
298
|
+
|
266
299
|
if(File.exist? temp_path)
|
267
300
|
output_mngr.add_new_message(:plot_file).set_content( temp_path )
|
268
301
|
end
|
data/lib/statsailr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsailr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshihiro Umehara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r_bridge
|