Class: Puppet::Pops::Parser::PNParser

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/parser/pn_parser.rb

Constant Summary collapse

LIT_TRUE =
'true'.freeze
LIT_FALSE =
'false'.freeze
LIT_NIL =
'nil'.freeze
TOKEN_END =
0
TOKEN_BOOL =
1
TOKEN_NIL =
2
TOKEN_INT =
3
TOKEN_FLOAT =
4
TOKEN_IDENTIFIER =
5
TOKEN_WS =
0x20
TOKEN_STRING =
0x22
TOKEN_KEY =
0x3a
TOKEN_LP =
0x28
TOKEN_RP =
0x29
TOKEN_LB =
0x5b
TOKEN_RB =
0x5d
TOKEN_LC =
0x7b
TOKEN_RC =
0x7d
TYPE_END =
0
TYPE_WS =
1
TYPE_DELIM =
2
TYPE_KEY_START =
3
TYPE_STRING_START =
4
TYPE_IDENTIFIER =
5
TYPE_MINUS =
6
TYPE_DIGIT =
7
TYPE_ALPHA =
8

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePNParser

Returns a new instance of PNParser


35
36
37
# File 'lib/puppet/pops/parser/pn_parser.rb', line 35

def initialize
  @char_types = self.class.char_types
end

Class Method Details

.char_typesObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/puppet/pops/parser/pn_parser.rb', line 51

def self.char_types
  unless instance_variable_defined?(:@char_types)
    @char_types = Array.new(0x80, TYPE_IDENTIFIER)
    @char_types[0] = TYPE_END
    [0x09, 0x0d, 0x0a, 0x20].each { |n| @char_types[n] = TYPE_WS }
    [TOKEN_LP, TOKEN_RP, TOKEN_LB, TOKEN_RB, TOKEN_LC, TOKEN_RC].each { |n| @char_types[n] = TYPE_DELIM }
    @char_types[0x2d] = TYPE_MINUS
    (0x30..0x39).each { |n| @char_types[n] = TYPE_DIGIT }
    (0x41..0x5a).each { |n| @char_types[n] = TYPE_ALPHA }
    (0x61..0x7a).each { |n| @char_types[n] = TYPE_ALPHA }
    @char_types[TOKEN_KEY] = TYPE_KEY_START
    @char_types[TOKEN_STRING] = TYPE_STRING_START
    @char_types.freeze
  end
  @char_types
end

Instance Method Details

#parse(text, locator = nil, offset = nil) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/pops/parser/pn_parser.rb', line 39

def parse(text, locator = nil, offset = nil)
  @locator = locator
  @offset = offset
  @text = text
  @codepoints = text.codepoints.to_a.freeze
  @pos = 0
  @token = TOKEN_END
  @token_value = nil
  next_token
  parse_next
end