Class DBus::Type::Parser
In: lib/dbus/type.rb
Parent: Object

D-Bus type parser class

Helper class to parse a type signature in the protocol.

Methods

new   nextchar   parse   parse_one  

Public Class methods

Create a new parser for the given signature.

[Source]

# File lib/dbus/type.rb, line 158
    def initialize(signature)
      @signature = signature
      @idx = 0
    end

Public Instance methods

Returns the next character from the signature.

[Source]

# File lib/dbus/type.rb, line 164
    def nextchar
      c = @signature[@idx]
      @idx += 1
      c
    end

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

[Source]

# File lib/dbus/type.rb, line 197
    def parse
      @idx = 0
      ret = Array.new
      while (c = nextchar)
        ret << parse_one(c)
      end
      ret
    end

Parse one character c of the signature.

[Source]

# File lib/dbus/type.rb, line 171
    def parse_one(c)
      res = nil
      case c
      when ?a
        res = Type.new(ARRAY)
        child = parse_one(nextchar)
        res << child
      when ?(
        res = Type.new(STRUCT)
        while (c = nextchar) != nil and c != ?)
          res << parse_one(c)
        end
        raise SignatureException, "Parse error in #{@signature}" if c == nil
      when ?{
        res = Type.new(DICT_ENTRY)
        while (c = nextchar) != nil and c != ?}
          res << parse_one(c)
        end
        raise SignatureException, "Parse error in #{@signature}" if c == nil
      else
        res = Type.new(c)
      end
      res
    end

[Validate]