Class: PuppetDBQuery::Parser

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/puppetdb_query/parser.rb

Overview

parse a puppetdb query string into #PuppetDBQuery::Term s rubocop:disable Metrics/ClassLength

Constant Summary collapse

AND =

these are the operators we understand rubocop:disable Style/ExtraSpacing

Operator.new(:_and,       true,  100, 2)
OR =
Operator.new(:_or,        true,   90, 2)
NOT =
Operator.new(:_not,       false, 150, 1, 1)
EQUAL =
Operator.new(:_equal,     true,  200, 2, 2)
NOT_EQUAL =
Operator.new(:_not_equal, true,  200, 2, 2)
MATCH =
Operator.new(:_match,     true,  200, 2, 2)
IN =
Operator.new(:_in,        true,  200, 2, 2)
OPERATORS =

map certain symbols (we get them from a tokenizer) to our operators

{
  AND.symbol       =>  AND,
  OR.symbol        =>  OR,
  NOT.symbol       =>  NOT,
  EQUAL.symbol     =>  EQUAL,
  :_is             =>  EQUAL,
  NOT_EQUAL.symbol =>  NOT_EQUAL,
  MATCH.symbol     =>  MATCH,
  IN.symbol        =>  IN,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger, #logger=

Instance Attribute Details

#positionObject (readonly)

current parsing position in array of symbols



40
41
42
# File 'lib/puppetdb_query/parser.rb', line 40

def position
  @position
end

#symbolsObject (readonly)

array of symbols



39
40
41
# File 'lib/puppetdb_query/parser.rb', line 39

def symbols
  @symbols
end

Class Method Details

.parse(puppetdb_query) ⇒ Object



12
13
14
# File 'lib/puppetdb_query/parser.rb', line 12

def self.parse(puppetdb_query)
  Parser.new.parse(puppetdb_query)
end

Instance Method Details

#parse(query) ⇒ Object

parse query and get resulting array of PuppetDBQuery::Term s



43
44
45
46
47
48
49
# File 'lib/puppetdb_query/parser.rb', line 43

def parse(query)
  @symbols = Tokenizer.symbols(query)
  @position = 0
  r = []
  r << read_maximal_term(0) until empty?
  r
end