Class: Safrano::Filter::ArgTree

Inherits:
Tree show all
Defined in:
lib/odata/filter/base.rb,
lib/odata/filter/tree.rb,
lib/odata/filter/sequel.rb

Overview

Arguments or lists

Instance Attribute Summary collapse

Attributes inherited from Tree

#parent

Attributes inherited from RootTree

#children, #state

Attributes inherited from Node

#value

Instance Method Summary collapse

Methods inherited from RootTree

#apply_to_dataset, #attach, #check_types, #detach, #first_child_value, #sequel_expr

Methods inherited from Node

#success

Constructor Details

#initialize(val) ⇒ ArgTree

Returns a new instance of ArgTree.



294
295
296
297
298
# File 'lib/odata/filter/tree.rb', line 294

def initialize(val)
  @type = :expression
  @state = :open
  super
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



292
293
294
# File 'lib/odata/filter/tree.rb', line 292

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



351
352
353
# File 'lib/odata/filter/tree.rb', line 351

def ==(other)
  super(other) && @type == other.type && @state == other.state
end

#accept?(tok, typ) ⇒ Boolean

nil is considered as accepted, otherwise non-nil=the error

Returns:

  • (Boolean)


313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/odata/filter/tree.rb', line 313

def accept?(tok, typ)
  case typ
  when :Delimiter
    if @value == '(' && tok == ')' && @state != :closed
      if (@parent.class == IdentityFuncTree) ||
         @parent.arity_full?(@children.size)

        nil
      else
        Parser::ErrorInvalidArity.new(tok, typ, self)
      end
    else
      if @value == '(' && tok == '(' && @state == :open
        nil
      else
        Parser::ErrorUnmatchedClose.new(tok, typ, self)
      end
    end
  when :Separator
    if @value == '(' && tok == ',' && @state == :val
      nil
    elsif @state == :sep
      Parser::ErrorInvalidToken.new(tok, typ, self)
    end
  when :Literal, :NullLiteral, :Qualit, :QString, :FuncTree, :FPNumber, :DecimalLit,
       :DateTimeLit, :DateTimeOffsetLit, :GuidLit
    if (@state == :open) || (@state == :sep)
      Parser::ErrorInvalidArity.new(tok, typ, self) if @parent.arity_full?(@children.size)
    else
      Parser::ErrorInvalidToken.new(tok, typ, self)
    end
  when :BinopBool, :BinopArithm
    nil
  else
    Parser::ErrorInvalidToken.new(tok, typ, self)
  end
end

#update_state(_tok, typ) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/odata/filter/tree.rb', line 300

def update_state(_tok, typ)
  case typ
  when :Delimiter
    @state = :closed
  when :Separator
    @state =  :sep
  when :Literal, :NullLiteral, :Qualit, :QString, :FuncTree, :FPNumber, :DecimalLit,
       :DateTimeLit, :DateTimeOffsetLit, :GuidLit
    @state =  :val
  end
end