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

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,  1, 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)
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,
  NOT_EQUAL.symbol =>  NOT_EQUAL,
  MATCH.symbol     =>  MATCH,
}.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



36
37
38
# File 'lib/puppetdb_query/parser.rb', line 36

def position
  @position
end

#symbolsObject (readonly)

array of symbols



35
36
37
# File 'lib/puppetdb_query/parser.rb', line 35

def symbols
  @symbols
end

Class Method Details

.parse(puppetdb_query) ⇒ Object



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

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



39
40
41
42
43
44
45
# File 'lib/puppetdb_query/parser.rb', line 39

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