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

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

Overview

API:

  • public

Constant Summary collapse

LIT_TRUE =

API:

  • public

'true'
LIT_FALSE =

API:

  • public

'false'
LIT_NIL =

API:

  • public

'nil'
TOKEN_END =

API:

  • public

0
TOKEN_BOOL =

API:

  • public

1
TOKEN_NIL =

API:

  • public

2
TOKEN_INT =

API:

  • public

3
TOKEN_FLOAT =

API:

  • public

4
TOKEN_IDENTIFIER =

API:

  • public

5
TOKEN_WS =

API:

  • public

0x20
TOKEN_STRING =

API:

  • public

0x22
TOKEN_KEY =

API:

  • public

0x3a
TOKEN_LP =

API:

  • public

0x28
TOKEN_RP =

API:

  • public

0x29
TOKEN_LB =

API:

  • public

0x5b
TOKEN_RB =

API:

  • public

0x5d
TOKEN_LC =

API:

  • public

0x7b
TOKEN_RC =

API:

  • public

0x7d
TYPE_END =

API:

  • public

0
TYPE_WS =

API:

  • public

1
TYPE_DELIM =

API:

  • public

2
TYPE_KEY_START =

API:

  • public

3
TYPE_STRING_START =

API:

  • public

4
TYPE_IDENTIFIER =

API:

  • public

5
TYPE_MINUS =

API:

  • public

6
TYPE_DIGIT =

API:

  • public

7
TYPE_ALPHA =

API:

  • public

8

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePNParser

Returns a new instance of PNParser.

API:

  • public



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

def initialize
  @char_types = self.class.char_types
end

Class Method Details

.char_typesObject

API:

  • public



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

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

API:

  • public



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

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