Class: DBus::Type::Parser
- Inherits:
-
Object
- Object
- DBus::Type::Parser
- Defined in:
- lib/dbus/type.rb
Overview
D-Bus type parser class
Helper class to parse a type signature in the protocol.
Instance Method Summary collapse
-
#initialize(signature) ⇒ Parser
constructor
Create a new parser for the given signature.
-
#nextchar ⇒ Object
Returns the next character from the signature.
-
#parse ⇒ Object
Parse the entire signature, return a DBus::Type object.
-
#parse_one(c) ⇒ Object
Parse one character c of the signature.
Constructor Details
#initialize(signature) ⇒ Parser
Create a new parser for the given signature.
126 127 128 129 |
# File 'lib/dbus/type.rb', line 126 def initialize(signature) @signature = signature @idx = 0 end |
Instance Method Details
#nextchar ⇒ Object
Returns the next character from the signature.
132 133 134 135 136 |
# File 'lib/dbus/type.rb', line 132 def nextchar c = @signature[@idx] @idx += 1 c end |
#parse ⇒ Object
Parse the entire signature, return a DBus::Type object.
167 168 169 170 171 172 173 174 |
# File 'lib/dbus/type.rb', line 167 def parse @idx = 0 ret = [] while (c = nextchar) ret << parse_one(c) end ret end |
#parse_one(c) ⇒ Object
Parse one character c of the signature.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dbus/type.rb', line 139 def parse_one(c) res = nil case c when "a" res = Type.new(ARRAY) c = nextchar raise SignatureException, "Parse error in #{@signature}" if c.nil? child = parse_one(c) res << child when "(" res = Type.new(STRUCT) while (c = nextchar) && c != ")" res << parse_one(c) end raise SignatureException, "Parse error in #{@signature}" if c.nil? when "{" res = Type.new(DICT_ENTRY) while (c = nextchar) && c != "}" res << parse_one(c) end raise SignatureException, "Parse error in #{@signature}" if c.nil? else res = Type.new(c) end res end |