Пример #1
0
    def next_(self, recurse=False):
        if len(self.tokens) and not recurse:
            t = self.tokens.pop(0)
            if t[0] != VARIABLE:
                return (t[0], t[1], self.location_())
            return self.parse_variable(t[1])

        try:
            return Lexer.next_(self)
        except FeatureLibError as e:
            if u"Unexpected character" not in str(e):
                raise e

        location = self.location_()
        text = self.text_
        start = self.pos_
        cur_char = text[start]
        if cur_char == '$':
            self.pos_ += 1
            self.scan_over_(Lexer.CHAR_NAME_CONTINUATION_)
            varname = text[start + 1:self.pos_]
            if len(varname) < 1 or len(varname) > 63:
                raise FeatureLibError("Bad variable name length", location)
            return (VARIABLE, varname, location)
        else:
            raise FeatureLibError("Unexpected character: %r" % cur_char,
                                  location)
Пример #2
0
    def next_(self, recurse=False):
        while (not self.empty_):
            if self.tokens_ is not None:
                res = self.tokens_.pop(0)
                if not len(self.tokens_):
                    self.popstack()
                if res[0] != VARIABLE:
                    return (res[0], res[1], self.location_())
                return self.parse_variable(res[1])

            try:
                res = Lexer.next_(self)
            except IndexError as e:
                self.popstack()
                continue
            except StopIteration as e:
                self.popstack()
                continue
            except FeatureLibError as e:
                if u"Unexpected character" not in str(e):
                    raise e

                # only executes if exception occurred
                location = self.location_()
                text = self.text_
                start = self.pos_
                cur_char = text[start]
                if cur_char == '$':
                    self.pos_ += 1
                    self.scan_over_(Lexer.CHAR_NAME_CONTINUATION_)
                    varname = text[start+1:self.pos_]
                    if len(varname) < 1 or len(varname) > 63:
                        raise FeatureLibError("Bad variable name length", location)
                    res = (VARIABLE, varname, location)
                else:
                    raise FeatureLibError("Unexpected character: %r" % cur_char, location)
            return res
        raise StopIteration