Ejemplo n.º 1
0
    def interpret(self):
        '''interpret a line (first call Parser.getline())
        Returns 0 on success, 1 on error
        '''

        if not self.keyword:
            stderr('%s: no keyword set; invalid parser state' % self)
            self.errors += 1
            return 1

        if not self.ifdef_stack[0]:
            if not self.keyword in ('ifdef', 'ifndef', 'else', 'endif'):
                debug("%s: skipping %s" % (self, self.keyword))
                return 0

        # get the parser function
        try:
            func = getattr(self, 'parse_%s' % self.keyword)
        except AttributeError:
            stderr("%s: unknown keyword '%s'" % (self, self.keyword))
            self.errors += 1
            return 1

        try:
            func()
        except ParseError as parse_error:
            parse_error.perror()
            self.errors += 1
            return 1

        return 0
Ejemplo n.º 2
0
def read_input_file(filename):
    '''read a (included) input file
    Returns 0 on success, or error count on errors
    '''

    errors = 0

    parser = Parser()
    try:
        parser.open(filename)
    except IOError as err:
        stderr('failed to open %s: %s' % (filename, err.strerror))
        return 1

    while parser.getline():
        parser.insert_comment_line()
        parser.interpret()

    if len(parser.ifdef_stack) > 1:
        ParseError("%s: missing 'endif' statement" % parser).perror()
        errors += 1

    parser.close()
    errors = errors + parser.errors

    debug('errors == %d' % errors)
    return errors
Ejemplo n.º 3
0
    def perror(self):
        '''print error message'''

        stderr(self.msg)