Class: ClickHouse::Ast::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/click_house/ast/parser.rb

Constant Summary collapse

OPEN =
'('
CLOSED =
')'
COMMA =
','
SPACE =
' '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • input (String)


16
17
18
# File 'lib/click_house/ast/parser.rb', line 16

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



13
14
15
# File 'lib/click_house/ast/parser.rb', line 13

def input
  @input
end

Instance Method Details

#parseObject

Map(String, Decimal(10, 5)) Array(Array(Array(Array(Nullable(Int, String)))))



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/click_house/ast/parser.rb', line 23

def parse
  ticker = Ticker.new
  control = false

  input.each_char do |char|
    # cases like (1,<space after comma> 3)
    next if control && char == SPACE

    case char
    when OPEN
      control = true
      ticker.open
    when CLOSED
      control = true
      ticker.close
    when COMMA
      control = true
      ticker.comma
    else
      control = false
      ticker.char(char)
    end
  end

  # if a single type like "Int"
  ticker.current.name! unless control
  ticker.current
end