Class: ProcBlock

Inherits:
Object
  • Object
show all
Extended by:
BlockSupport
Defined in:
lib/statsailr/block_builder/sts_block.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BlockSupport

type_adjust

Methods included from QuotedStringSupport

#escape_backslashes, #interpret_escape_sequences

Constructor Details

#initialize(command, opts, stmts) ⇒ ProcBlock

Returns a new instance of ProcBlock.



201
202
203
204
205
# File 'lib/statsailr/block_builder/sts_block.rb', line 201

def initialize( command, opts, stmts )
  @command = command
  @opts = opts
  @stmts = stmts
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



199
200
201
# File 'lib/statsailr/block_builder/sts_block.rb', line 199

def command
  @command
end

#optsObject (readonly)

Returns the value of attribute opts.



199
200
201
# File 'lib/statsailr/block_builder/sts_block.rb', line 199

def opts
  @opts
end

#stmtsObject (readonly)

Returns the value of attribute stmts.



199
200
201
# File 'lib/statsailr/block_builder/sts_block.rb', line 199

def stmts
  @stmts
end

Class Method Details

.new_from_gram_node(node) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/statsailr/block_builder/sts_block.rb', line 207

def self.new_from_gram_node( node )
  proc_command = type_adjust( node.e1.e1, :string )

  proc_opt_hash = {}
  proc_opts = node.e2
  if(! proc_opts.nil?)
    proc_opts.each(){|nd|
      proc_opt_key = nd.e1
      proc_opt_val = type_adjust( nd.e2.e1 , nd.e2.type )
      proc_opt_hash[proc_opt_key] = proc_opt_val
    }
  else
    proc_opt_hash = {}
  end

  proc_stmts = []

  proc_stmts_ori = node.e3
  proc_stmts_ori.each(){|proc_stmt_ori|
      proc_stmt_inst = ""
      proc_stmt_arg = []
      proc_stmt_opt_hash = {}

      proc_stmt_inst = type_adjust( proc_stmt_ori.e1.e1, :string) # String
      proc_stmt_arg_ori = proc_stmt_ori.e2
      if ! proc_stmt_arg_ori.nil? then
        idx = 0
        while idx < proc_stmt_arg_ori.size() do
          elem = proc_stmt_arg_ori[idx]
          next_elem = proc_stmt_arg_ori[idx + 1]
          next_next_elem = proc_stmt_arg_ori[idx + 2]
          if(elem.type == :sign && elem.e1 == "/" ) then
             if( ! next_elem.nil? && next_elem.type == :ident &&   # After /, optional arguments start
                 ! next_next_elem.nil? && next_next_elem.type == :sign && next_next_elem.e1 == "=") ||
                 next_elem.nil? then  # After /, there is nothing
               break
             end
          else
            x = type_adjust( elem.e1, elem.type, :retain_input_string )
            proc_stmt_arg << x
            idx = idx + 1
          end
        end
        idx = idx + 1
        if idx < proc_stmt_arg_ori.size()

          proc_stmt_opt_hash = STSBlockParseProcOpts.include(BlockSupport).new(proc_stmt_arg_ori, idx).parse()
        else
          proc_stmt_opt_hash = {}
        end
      else  # When no arguments (even )
        prc_stmt_arg = []
      end

      proc_stmts.push( [proc_stmt_inst, proc_stmt_arg, proc_stmt_opt_hash ] )
  }

  return ProcBlock.new( proc_command , proc_opt_hash, proc_stmts)
end