Class: Pinpoint::Format::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/pinpoint/format/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

Public: Initializes a Parser and converts the passed String into a TokenList that will be utilized when it is parsed.

Raises a ParseError if the Tokenizer cannot tokenize the String Returns a Parser



17
18
19
# File 'lib/pinpoint/format/parser.rb', line 17

def initialize(string)
  self.tokens = Pinpoint::Format::Tokenizer.new(string).to_token_list
end

Instance Method Details

#parseObject

Public: Provides a way to convert a TokenList into a tree repersenting groups, message names, and String literals.

If the TokenList is not valid, a form of ParseError is raised.

Example

Parser.new('(%s, )((%l, )(%p )%z)(, %c)').parse
# =>  [
#       [
#         :street,
#         ', ',
#       ],
#       [
#         [
#           :locality,
#           ', '
#         ],
#         [
#           :province,
#           ' '
#         ],
#         :postal_code
#       ],
#       [
#         ', ',
#         :country
#       ]
#     ]

Returns an Array containing the parse tree structure



54
55
56
# File 'lib/pinpoint/format/parser.rb', line 54

def parse
  process(tokens) if tokens.valid?
end