Class: DDQL::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/ddql/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, location: nil, type:) ⇒ Token

Returns a new instance of Token.



10
11
12
13
14
# File 'lib/ddql/token.rb', line 10

def initialize(data:, location: nil, type:)
  @data     = data
  @location = location
  @type     = type
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/ddql/token.rb', line 5

def data
  @data
end

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/ddql/token.rb', line 6

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/ddql/token.rb', line 5

def type
  @type
end

Instance Method Details

#and?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ddql/token.rb', line 16

def and?
  data == 'AND'
end

#as_hashObject



20
21
22
# File 'lib/ddql/token.rb', line 20

def as_hash
  type.as_hash(data)
end

#comparison?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ddql/token.rb', line 24

def comparison?
  type.comparison?(data)
end

#complex_comparison?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ddql/token.rb', line 28

def complex_comparison?
  type.complex_comparison?(data)
end

#infix?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ddql/token.rb', line 32

def infix?
  type.infix?
end

#math?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ddql/token.rb', line 36

def math?
  type.math?(data)
end

#op_dataObject



40
41
42
# File 'lib/ddql/token.rb', line 40

def op_data
  data.squish
end

#or?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ddql/token.rb', line 44

def or?
  data == 'OR'
end

#parse(parser, expression: nil) ⇒ Object



48
49
50
# File 'lib/ddql/token.rb', line 48

def parse(parser, expression: nil)
  type.parse(parser, self, expression: expression)
end

#post_process(parser:, expression:) ⇒ Object



52
53
54
55
# File 'lib/ddql/token.rb', line 52

def post_process(parser:, expression:)
  raise "#{type} doesn't support post-processing" unless supports_post_processing?
  type.post_process(parser: parser, expression: expression)
end

#postfix?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ddql/token.rb', line 57

def postfix?
  type.postfix?
end

#prefix?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ddql/token.rb', line 61

def prefix?
  type.prefix?
end

#simple_comparison?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ddql/token.rb', line 65

def simple_comparison?
  type.simple_comparison?(data)
end

#supports_post_processing?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/ddql/token.rb', line 69

def supports_post_processing?
  type.supports_post_processing?
end

#to_hObject



73
74
75
# File 'lib/ddql/token.rb', line 73

def to_h
  type.as_hash(data)
end

#to_sObject



77
78
79
# File 'lib/ddql/token.rb', line 77

def to_s
  "#{type.name} : #{data}"
end

#type?(token_type) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/ddql/token.rb', line 81

def type?(token_type)
  token_type == type
end