Class: STSBlockParseProcOpts
- Inherits:
-
Object
- Object
- STSBlockParseProcOpts
- Defined in:
- lib/statsailr/block_builder/sts_block_parse_proc_opts.rb
Instance Method Summary collapse
- #arg_opt ⇒ Object
-
#arg_opts ⇒ Object
arg_opts : arg_opt | arg_opts arg_opt.
- #array ⇒ Object
- #current_token ⇒ Object
- #elems(ary) ⇒ Object
- #func ⇒ Object
- #has_next? ⇒ Boolean
- #ident ⇒ Object
-
#initialize(elems, idx) ⇒ STSBlockParseProcOpts
constructor
A new instance of STSBlockParseProcOpts.
- #next_token ⇒ Object
- #num ⇒ Object
-
#parse ⇒ Object
Entry point.
- #peek ⇒ Object
- #primary ⇒ Object
- #string ⇒ Object
Constructor Details
#initialize(elems, idx) ⇒ STSBlockParseProcOpts
Returns a new instance of STSBlockParseProcOpts.
3 4 5 6 7 8 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 3 def initialize(elems, idx) @size = elems.size @elems = elems @idx = idx @result_hash = Hash.new() end |
Instance Method Details
#arg_opt ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 75 def arg_opt() opt_key = ident() if (!peek.nil?) && peek.type == :sign && peek.e1 == "=" next_token() # At = if peek.type == :sign && peek.e1 == "[" # RHS of = is array next_token() # Now at [ opt_value = array() elsif peek.type == :ident # RHS of = is ident, meaning just ident or function next_token() if (! peek.nil?) && peek.type == :sign && peek.e1 == "(" opt_value = func() else opt_value = ident() # According to BNF, this should be parimary(). However, ident() is more direct and makes sense here. end elsif [:dq_string, :sq_string, :num].include? peek.type next_token() opt_value = primary() else p current_token() raise "the token should be :ident or primaries such as :ident, :num and :string after = . Next token: " + peek.type.to_s end else raise "proc instruction optional argumeents should be in the form of a sequence of 'key = value'" end @result_hash[opt_key.to_s] = opt_value end |
#arg_opts ⇒ Object
arg_opts : arg_opt
| arg_opts arg_opt
arg_opt : IDENT = primary
| IDENT = array
| IDENT = func
parimary : STRING
| NUM
| IDENT
array : [ elems ]
func : IDENT ( elems )
elems : primary
| elems , primary
67 68 69 70 71 72 73 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 67 def arg_opts() arg_opt() if has_next? next_token() arg_opts() end end |
#array ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 102 def array() raise "array should start with [ " if ! (current_token.type == :sign && current_token.e1 == "[") next_token() ary = Array.new() elems( ary ) raise "array should end with ] " if ! (current_token.type == :sign && current_token.e1 == "]") return ary end |
#current_token ⇒ Object
35 36 37 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 35 def current_token() @elems[@idx] end |
#elems(ary) ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 114 def elems( ary ) ary.push primary() next_token if current_token.type == :sign && current_token.e1 == "," next_token elems( ary ) else return ary end end |
#func ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 140 def func() func_name = ident() parenthesis = next_token() raise "func arg should start with ( " if ! (parenthesis.type == :sign && parenthesis.e1 == "(") next_token() func_args = elems( Array.new() ) raise "func should end with ) " if ! (current_token.type == :sign && current_token.e1 == ")") func_hash = {"type" => :func , "fname" => func_name.to_s , "fargs" => func_args} return func_hash end |
#has_next? ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 10 def has_next?() if @idx + 1 < @size return true else return false end end |
#ident ⇒ Object
153 154 155 156 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 153 def ident() raise "the current token should be ident" if current_token.type != :ident return type_adjust( current_token.e1, :ident) end |
#next_token ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 18 def next_token() if has_next? @idx = @idx + 1 @elems[@idx] else nil end end |
#num ⇒ Object
168 169 170 171 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 168 def num() raise "the current token should be num" if current_token.type != :num return type_adjust( current_token.e1, :num) end |
#parse ⇒ Object
Entry point
40 41 42 43 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 40 def parse() arg_opts() return @result_hash end |
#peek ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 27 def peek() if has_next? @elems[@idx + 1] else nil end end |
#primary ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 125 def primary() case current_token.type when :ident return ident() when :dq_string return string() when :sq_string return string() when :num return num() else raise "the current token should be :ident, :dq_string, :sq_string or :num." end end |
#string ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/statsailr/block_builder/sts_block_parse_proc_opts.rb', line 158 def string() if (current_token.type != :dq_string) return type_adjust( current_token.e1, :dq_string) elsif (current_token.type != :sq_string) return type_adjust( current_token.e1, :sq_string) else raise "the current token should be string (:dq_string or :sq_string)" end end |