# class DBus::Type::Parser

# D-Bus type parser class¶ ↑

Helper class to parse a type signature in the protocol.

### Public Class Methods

new(signature) click to toggle source

Create a new parser for the given signature.

        # File lib/dbus/type.rb
    126 def initialize(signature)
    127   @signature = signature
    128   @idx = 0
    129 end

### Public Instance Methods

nextchar() click to toggle source

Returns the next character from the signature.

        # File lib/dbus/type.rb
    132 def nextchar
    133   c = @signature[@idx]
    134   @idx += 1
    135   c
    136 end

parse() click to toggle source

Parse the entire signature, return a `DBus::Type` object.

        # File lib/dbus/type.rb
    167 def parse
    168   @idx = 0
    169   ret = []
    170   while (c = nextchar)
    171     ret << parse_one(c)
    172   end
    173   ret
    174 end

parse_one(c) click to toggle source

Parse one character c of the signature.

        # File lib/dbus/type.rb
    139 def parse_one(c)
    140   res = nil
    141   case c
    142   when "a"
    143     res = Type.new(ARRAY)
    144     c = nextchar
    145     raise SignatureException, "Parse error in #{@signature}" if c.nil?
    146     child = parse_one(c)
    147     res << child
    148   when "("
    149     res = Type.new(STRUCT)
    150     while (c = nextchar) && c != ")"
    151       res << parse_one(c)
    152     end
    153     raise SignatureException, "Parse error in #{@signature}" if c.nil?
    154   when "{"
    155     res = Type.new(DICT_ENTRY)
    156     while (c = nextchar) && c != "}"
    157       res << parse_one(c)
    158     end
    159     raise SignatureException, "Parse error in #{@signature}" if c.nil?
    160   else
    161     res = Type.new(c)
    162   end
    163   res
    164 end