示例#1
0
 def _warn_conflict(self, nonterminal, terminal, area):
     "Emits a warning for a conflictive state."
     msg = ''
     msg += i18n.i18n('Conflictive rule for: ("%s", "%s")\n') % (
                 nonterminal, terminal)
     msg += i18n.i18n('Will choose first production:\n')
     msg += utils.indent(bnf_rule_to_str(
                     self._parse_table[(nonterminal, terminal)]))
     self.warn(ParserException(msg, area))
示例#2
0
 def backtrace(self, msg):
     def describe(ar, indent_):
         loc = ar.routine.nearby_elems.get(ar.ip, self.program.tree).pos_begin.file_row()
         return '%s%s %s %s' % ('    ' * indent_, ar.routine.prfn, ar.routine.name, loc)
     cs = self.callstack + [self.ar]
     res = ''
     res += msg + '\n\n'
     res += i18n.i18n('At:') + '\n'
     res += indent('\n'.join([
                          describe(x, y)
                          for x, y in zip(cs, range(0, len(cs)))
                        ])) + '\n'
     bindings = [(k, v) for k, v in seq_sorted(self.ar.bindings.items())
                        if k[0] != '_']
     if len(bindings) > 0:
         res += i18n.i18n('Locals:') + '\n'
         res += indent('\n'.join(['%s: %s' % (k, v) for k, v in bindings]))
     return res
示例#3
0
 def reraise(self, new_class, old_exception, new_msg, new_area):
     if self._source_filename == self._toplevel_filename:
         raise new_class(
             new_msg + '\n' + utils.indent(
                 '%s\n%s' % (old_exception.area, old_exception.msg)
             ),
             new_area
         )
     else:
         raise old_exception
示例#4
0
 def parse_error(self, top, _previous_token, token):
     "Raises a ParserException describing a parse error."
     if is_nonterminal(top):
         follow = self._followups(top)
     else:
         follow = [Token.type_description(top)]
     if len(follow) == 1:
         msg = i18n.i18n('Found: %s\nExpected: %s') % (token, follow[0])
     else:
         msg = ''
         msg += i18n.i18n('\n'.join([
                             'Found: %s',
                             'Expected one of the following tokens:'])) % (
                  token,)
         msg += '\n' + utils.indent('\n'.join(follow))
     raise ParserException(msg, position.ProgramAreaNear(token))
示例#5
0
def report_error(errtype, msg):
    LOGGER.error('%s:\n' % (errtype,))
    LOGGER.error('%s\n' % (utils.indent(msg),))