statsailr 0.7.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f27292effff5ace93fcbae7cecd0a62615450ff496ba1c2bdc03b3824894a56
4
- data.tar.gz: 7a13e3905398a04bde7f3dd0719576bcfc92a6b95b62e2a34071eca9db0086c0
3
+ metadata.gz: 8701d54a846ae0d81c7f91080586c7dd81b05c081743ba84606c46ecc53f25a8
4
+ data.tar.gz: 7f2636ea0b00008f160e303b389d977b94e7698a1eb800603850cff38901b14e
5
5
  SHA512:
6
- metadata.gz: 356f45dd828c22c84071879e6d0a9a16ec215adf5f3894d37b6a292a6189dde7e211a12aea4697e5695a21cc8d6848c57ae5156d263b035c5b2eed667abb7300
7
- data.tar.gz: 1f94bb8192f0af9d20ee9a79600a8db9278d17c4a323da274e8aad6e6ad3318368d070422fd30c631da75ac845773810708999d92a066ebcff0e2dce9bb8be59
6
+ metadata.gz: 4007addec1d2a15f05c62bef40850a31648b4e2099ac7cf79890f0cb480854561990b478420bf3ab750089c88b1013b7fe4261c15738cb608b893257c2ef5134
7
+ data.tar.gz: e38f0f64d035ab90bfdd8c052f63c1b4f0cd605cac841ddaefa18de6af127658f2c6453b4fbd74b7dfcf31e29920ba26c9b6db8b8211ee452ad983dce8c0ae3e
data/README.md CHANGED
@@ -254,7 +254,7 @@ END
254
254
  + How main argument part is parsed varies on each instruction. This is defined in main_arg_and_how_to_treat variable in setting.
255
255
  + opt_args
256
256
  + Optional arguments. Values specified in opt_args are also passed to R function's argument.
257
- + opt_args part consists of (a) key-value(s) or key(s).
257
+ + opt_args part consists of (a) key-value(s).
258
258
  + Internally, this argument parsing is conducted by methods in STSBlockParseProcOpts.
259
259
 
260
260
 
@@ -1,8 +1,82 @@
1
1
  require "r_bridge"
2
2
  require_relative "./sts_block_parse_proc_opts.rb"
3
3
 
4
+ module QuotedStringSupport
5
+ def interpret_escape_sequences(str)
6
+ # This deals with escape sequences in double quoted string literals
7
+ # The behavior should be same as libsailr (or datasailr)
8
+ new_str = ""
9
+ str_array = str.split(//)
10
+ idx = 0
11
+ while( idx < str_array.size) do
12
+ c = str_array[idx]
13
+ if(c == "\\")
14
+ idx = idx + 1
15
+ c = str_array[idx]
16
+ raise "Tokenizer error: double quoted string literal should never end with \\" if idx >= str_array.size
17
+ case c
18
+ when 't'
19
+ new_str << "\t"
20
+ when 'n'
21
+ new_str << "\n"
22
+ when 'r'
23
+ new_str << "\r"
24
+ when "\\"
25
+ new_str << "\\"
26
+ when "\'"
27
+ new_str << "\'"
28
+ when "\""
29
+ new_str << "\""
30
+ when '?'
31
+ new_str << '?'
32
+ else
33
+ new_str << c
34
+ end
35
+ else
36
+ new_str << c
37
+ end
38
+ idx = idx + 1
39
+ end
40
+ return new_str
41
+ end
42
+
43
+ def escape_backslashes(str)
44
+ str.gsub("\\", "\\\\")
45
+ end
46
+ end
47
+
4
48
  module BlockSupport
5
- def type_adjust(obj , type)
49
+ include QuotedStringSupport
50
+ class QuotedStringR
51
+ include QuotedStringSupport
52
+ def initialize(str, quote_type)
53
+ raise ":dq or :sq should be specified for quote_type" unless [:dq, :sq].include? quote_type
54
+ @ori_str = str
55
+ @quote_type = quote_type
56
+ end
57
+
58
+ def to_s
59
+ to_s_for_r_bridge
60
+ end
61
+
62
+ def to_s_for_r_bridge
63
+ if @quote_type == :dq
64
+ interpret_escape_sequences( @ori_str )
65
+ elsif
66
+ @ori_str
67
+ end
68
+ end
69
+
70
+ def to_s_for_r_parsing
71
+ if @quote_type == :dq
72
+ %q{"} + @ori_str + %q{"}
73
+ elsif @quote_type == :sq
74
+ %q{'} + escape_backslashes( @ori_str ) + %q{'}
75
+ end
76
+ end
77
+ end
78
+
79
+ def type_adjust(obj , type , *opts)
6
80
  case type
7
81
  when :ident
8
82
  if obj.is_a?(String)
@@ -22,6 +96,28 @@ module BlockSupport
22
96
  else
23
97
  raise "GramNode with inconsistent type(#{type.to_s}) and object(#{obj.class})"
24
98
  end
99
+ when :sq_string
100
+ if obj.is_a?(String)
101
+ unless opts.include?( :retain_input_string )
102
+ # default behavior
103
+ result = obj
104
+ else
105
+ result = QuotedStringR.new( obj, :sq )
106
+ end
107
+ else
108
+ raise "GramNode with inconsistent type(#{type.to_s}) and object(#{obj.class})"
109
+ end
110
+ when :dq_string
111
+ if obj.is_a?(String)
112
+ unless opts.include?( :retain_input_string )
113
+ # default behavior
114
+ result = interpret_escape_sequences( obj )
115
+ else
116
+ result = QuotedStringR.new( obj, :dq )
117
+ end
118
+ else
119
+ raise "GramNode with inconsistent type(#{type.to_s}) and object(#{obj.class})"
120
+ end
25
121
  when :sign
26
122
  if obj.is_a?(String)
27
123
  result = RBridge::SignR.new(obj)
@@ -137,10 +233,16 @@ class ProcBlock
137
233
  idx = 0
138
234
  while idx < proc_stmt_arg_ori.size() do
139
235
  elem = proc_stmt_arg_ori[idx]
140
- if( elem.type == :sign && elem.e1 == "/" )
141
- break
236
+ next_elem = proc_stmt_arg_ori[idx + 1]
237
+ next_next_elem = proc_stmt_arg_ori[idx + 2]
238
+ if(elem.type == :sign && elem.e1 == "/" ) then
239
+ if( ! next_elem.nil? && next_elem.type == :ident && # After /, optional arguments start
240
+ ! next_next_elem.nil? && next_next_elem.type == :sign && next_next_elem.e1 == "=") ||
241
+ next_elem.nil? then # After /, there is nothing
242
+ break
243
+ end
142
244
  else
143
- x = type_adjust( elem.e1, elem.type )
245
+ x = type_adjust( elem.e1, elem.type, :retain_input_string )
144
246
  proc_stmt_arg << x
145
247
  idx = idx + 1
146
248
  end
@@ -50,7 +50,6 @@ class STSBlockParseProcOpts
50
50
  # arg_opt : IDENT = primary
51
51
  # | IDENT = array
52
52
  # | IDENT = func
53
- # | IDENT
54
53
  #
55
54
  # parimary : STRING
56
55
  # | NUM
@@ -87,15 +86,15 @@ class STSBlockParseProcOpts
87
86
  else
88
87
  opt_value = ident() # According to BNF, this should be parimary(). However, ident() is more direct and makes sense here.
89
88
  end
90
- elsif [:string, :num].include? peek.type
89
+ elsif [:dq_string, :sq_string, :num].include? peek.type
91
90
  next_token()
92
91
  opt_value = primary()
93
92
  else
94
93
  p current_token()
95
- raise "the token should be :ident or primaries such as :ident, :num and :string after = . Current token: " + current_token().type.to_s
94
+ raise "the token should be :ident or primaries such as :ident, :num and :string after = . Next token: " + peek.type.to_s
96
95
  end
97
96
  else
98
- opt_value = true
97
+ raise "proc instruction optional argumeents should be in the form of a sequence of 'key = value'"
99
98
  end
100
99
  @result_hash[opt_key.to_s] = opt_value
101
100
  end
@@ -127,12 +126,14 @@ class STSBlockParseProcOpts
127
126
  case current_token.type
128
127
  when :ident
129
128
  return ident()
130
- when :string
129
+ when :dq_string
130
+ return string()
131
+ when :sq_string
131
132
  return string()
132
133
  when :num
133
134
  return num()
134
135
  else
135
- raise "the current token should be :ident, :string or :num."
136
+ raise "the current token should be :ident, :dq_string, :sq_string or :num."
136
137
  end
137
138
  end
138
139
 
@@ -155,8 +156,13 @@ class STSBlockParseProcOpts
155
156
  end
156
157
 
157
158
  def string()
158
- raise "the current token should be string" if current_token.type != :string
159
- return type_adjust( current_token.e1, :string)
159
+ if (current_token.type != :dq_string)
160
+ return type_adjust( current_token.e1, :dq_string)
161
+ elsif (current_token.type != :sq_string)
162
+ return type_adjust( current_token.e1, :sq_string)
163
+ else
164
+ raise "the current token should be string (:dq_string or :sq_string)"
165
+ end
160
166
  end
161
167
 
162
168
  def num()
@@ -40,6 +40,50 @@ module LazyFuncGeneratorSettingUtility
40
40
  return RBridge.create_strvec( ary.map(){|elem| elem.to_s } )
41
41
  end
42
42
 
43
+ def read_symbols_or_functions_as_strvec(ary)
44
+ deapth_ary = Array.new( ary.size )
45
+ idx = 0
46
+ last_idx = ary.size - 1
47
+ deapth = 0
48
+ while( idx <= last_idx )
49
+ if( ary[idx].is_a?(RBridge::SymbolR) && (ary[idx + 1].is_a?(RBridge::SignR) && ary[idx + 1].to_s == "("))
50
+ # function starts
51
+ deapth_ary[idx] = deapth
52
+ deapth = deapth + 1
53
+ idx = idx + 1
54
+ deapth_ary[idx] = deapth
55
+ elsif( ary[idx].is_a?(RBridge::SignR) && ary[idx].to_s == "(")
56
+ # parenthesis starts
57
+ deapth = deapth + 1
58
+ deapth_ary[idx] = deapth
59
+ elsif( ary[idx].is_a?(RBridge::SignR) && ary[idx].to_s == ")")
60
+ # parenthesis ends or function ends
61
+ deapth_ary[idx] = deapth
62
+ deapth = deapth - 1
63
+ else
64
+ deapth_ary[idx] = deapth
65
+ end
66
+ idx = idx + 1
67
+ end
68
+
69
+ result_ary = []
70
+ ary.zip( deapth_ary).each(){|elem, deapth|
71
+ if elem.respond_to? :to_s_for_r_parsing
72
+ elem_str = elem.to_s_for_r_parsing
73
+ else
74
+ elem_str = elem.to_s
75
+ end
76
+
77
+ if( deapth == 0)
78
+ result_ary.push( elem_str )
79
+ else
80
+ result_ary.last << " " << elem_str
81
+ end
82
+ }
83
+
84
+ return RBridge.create_strvec( result_ary )
85
+ end
86
+
43
87
  def result( name , *addl )
44
88
  if addl.empty?
45
89
  return RBridge::RResultName.new(name)