statsailr 0.7.2 → 0.7.6

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.
@@ -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 << [:STRING, matched[Range.new(1, -2)] ]
113
+ tokens << [:SQ_STRING, matched[Range.new(1, -2)] ]
155
114
  when scan(DQ_STR_PATTERN)
156
- tokens << [:STRING, interpret_escape_sequences(matched[Range.new(1, -2)]) ]
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 :P_HAT
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(/\%in\%/)
237
- return :P_PERC
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 :P_TILDA
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 << [:STRING, matched[Range.new(1, -2)] ]
247
+ tokens << [:SQ_STRING, matched[Range.new(1, -2)] ]
269
248
  when scan(DQ_STR_PATTERN)
270
- tokens << [:STRING, interpret_escape_sequences(matched[Range.new(1, -2)]) ]
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 << [:SEP_SLASH, matched]
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, "dev.copy_opt" => {"dir_path"=> dir_to_save , "prefix"=> "plot", "type" => "png"} }]
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
- if ! ["png", "jpeg"].include? cairo_info["dev.copy_opt"]["type"]
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 cairo_info["dev.copy_opt"]["type"]
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
- new_cairo_device_func = RBridge.create_function_call("Cairo", { "width" => RBridge.create_intvec([ cairo_info["width"] ]),
50
- "height" => RBridge.create_intvec([ cairo_info["height"] ]),
51
- "type" => RBridge.create_strvec([ "raster" ]) })
52
- RBridge.exec_function_no_return(new_cairo_device_func)
53
- @new_device_info = { "file_output" => true, "dev_off_required" => true ,
54
- "opt" => cairo_info["dev.copy_opt"].merge( {
55
- "device_func" => RBridge::SymbolR.new( cairo_info["dev.copy_opt"]["type"] ).to_r_symbol,
56
- "default_width" => cairo_info["width"], "default_height" => cairo_info["height"]})}
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
- dev_info_opt = @new_device_info["opt"]
276
+ file_output_opt = @new_device_info["file_output_opt"]
256
277
  temp_path = ""
257
- temp_file = Tempfile.new( [dev_info_opt["prefix"] , "." + dev_info_opt["type"] ] , dev_info_opt["dir_path"] )
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
- dev_copy_func = RBridge::create_function_call("dev.copy", { "device" => dev_info_opt["device_func"], "file" => RBridge::create_strvec([temp_path]),
261
- "width" => RBridge::create_intvec( [dev_info_opt["default_width"]] ),
262
- "height" => RBridge::create_intvec( [dev_info_opt["default_height"]] ) })
263
- RBridge::exec_function_no_return(dev_copy_func)
264
- dev_off_func = RBridge::create_function_call("dev.off", {})
265
- RBridge::exec_function_no_return(dev_off_func)
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
@@ -1,3 +1,3 @@
1
1
  module StatSailr
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.6"
3
3
  end
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.2
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshihiro Umehara
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r_bridge
@@ -84,6 +84,7 @@ files:
84
84
  - lib/statsailr.rb
85
85
  - lib/statsailr/block_builder/sts_block.rb
86
86
  - lib/statsailr/block_builder/sts_block_parse_proc_opts.rb
87
+ - lib/statsailr/block_to_r/proc_setting_support/proc_block_finalizer.rb
87
88
  - lib/statsailr/block_to_r/proc_setting_support/proc_opt_validator.rb
88
89
  - lib/statsailr/block_to_r/proc_setting_support/proc_setting_manager.rb
89
90
  - lib/statsailr/block_to_r/proc_setting_support/proc_setting_module.rb
@@ -111,7 +112,7 @@ metadata:
111
112
  homepage_uri: https://github.com/niceume/statsailr
112
113
  source_code_uri: https://github.com/niceume/statsailr
113
114
  changelog_uri: https://github.com/niceume/statsailr
114
- post_install_message:
115
+ post_install_message:
115
116
  rdoc_options: []
116
117
  require_paths:
117
118
  - lib
@@ -126,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
128
129
  requirements: []
129
- rubygems_version: 3.1.4
130
- signing_key:
130
+ rubygems_version: 3.2.31
131
+ signing_key:
131
132
  specification_version: 4
132
133
  summary: Provides a platform to focus on statistics
133
134
  test_files: []