'Parse a variable reference (like ``$foo`` or ``${foo}``)
starting at ``pos``. Possibly appends a Symbol object (or,
failing that, text) to the ``parts`` field and updates ``pos``.
The character at ``pos`` must, as a precondition, be ``$``.'

def parse_symbol(self):

    assert (self.pos < len(self.string))
    assert (self.string[self.pos] == SYMBOL_DELIM)
    if (self.pos == (len(self.string) - 1)):
        self.parts.append(SYMBOL_DELIM)
        self.pos += 1
        return
    next_char = self.string[(self.pos + 1)]
    start_pos = self.pos
    self.pos += 1
    if (next_char == GROUP_OPEN):
        self.pos += 1
        closer = self.string.find(GROUP_CLOSE, self.pos)
        if ((closer == (-1)) or (closer == self.pos)):
            self.parts.append(self.string[start_pos:self.pos])
        else:
            ident = self.string[self.pos:closer]
            self.pos = (closer + 1)
            self.parts.append(Symbol(ident, self.string[start_pos:self.pos]))
    else:
        ident = self._parse_ident()
        if ident:
            self.parts.append(Symbol(ident, self.string[start_pos:self.pos]))
        else:
            self.parts.append(SYMBOL_DELIM)
