Example #1
0
def change_case(i):

    mode = i.pop()
    string = i.pop()

    if not mode:
        raise BibTeXError('empty mode string passed to change.case$')
    mode_letter = mode[0].lower()
    if not mode_letter in ('l', 'u', 't'):
        raise BibTeXError('incorrect change.case$ mode: %s' % mode)

    i.push(utils.change_case(string, mode_letter))
Example #2
0
    def pop(self):
        try:
            value = self.stack.pop()
        except IndexError:
            raise BibTeXError('pop from empty stack')
#        print 'pop <%s>' % value
        return value
Example #3
0
    def check_braces(self, s):
        """
        Raise an exception if the given string has unmatched braces.

        >>> w = Writer()
        >>> w.check_braces('Cat eats carrots.')
        >>> w.check_braces('Cat eats {carrots}.')
        >>> w.check_braces('Cat eats {carrots{}}.')
        >>> w.check_braces('')
        >>> w.check_braces('end}')
        >>> try:
        ...     w.check_braces('{')
        ... except BibTeXError, error:
        ...     print error
        String has unmatched braces: {
        >>> w.check_braces('{test}}')
        >>> try:
        ...     w.check_braces('{{test}')
        ... except BibTeXError, error:
        ...     print error
        String has unmatched braces: {{test}

        """

        tokens = list(scan_bibtex_string(s))
        if tokens:
            end_brace_level = tokens[-1][1]
            if end_brace_level != 0:
                raise BibTeXError('String has unmatched braces: %s' % s)
Example #4
0
def int_to_chr(i):
    n = i.pop()
    try:
        char = six.unichr(n)
    except ValueError:
        raise BibTeXError('%i passed to int.to.chr$', n)
    i.push(char)
Example #5
0
def chr_to_int(i):
    s = i.pop()
    try:
        value = ord(s)
    except TypeError:
        raise BibTeXError('%s passed to chr.to.int$', s)
    i.push(value)
Example #6
0
    def __init__(self, chars, level=0, max_level=100):
        if level > max_level:
            raise BibTeXError('too many nested braces')

        self.level = level
        self.is_closed = False
        self.contents = list(self.find_closing_brace(iter(chars)))
Example #7
0
 def execute(self, interpreter):
     try:
         var = interpreter.vars[self.value()]
     except KeyError:
         raise BibTeXError('can not push undefined variable %s' %
                           self.value())
     interpreter.push(var)
Example #8
0
 def add_variable(self, name, value):
     if name in self.vars:
         raise BibTeXError('variable "{0}" already declared as {1}'.format(name, type(value).__name__))
     self.vars[name] = value
Example #9
0
 def execute(self, interpreter):
     try:
         f = interpreter.vars[self.value()]
     except KeyError:
         raise BibTeXError('can not execute undefined function %s' % self)
     f.execute(interpreter)
Example #10
0
def print_warning(msg):
    report_error(BibTeXError(msg))