def _inner(file_name, input_str, position): context, line, column = _full_context(input_str, position) return (_a('Error') + ' {}at position ' + _a('{},{} ') + _('=>') + ' "{}". ' + _('Expected: ') + '{}').format( 'in file "{}" '.format(file_name) if file_name else "", line, column, context, _(' or ').join([s.name for s in symbols]))
def __str__(self): line, column = self.line, self.column if line is not None: return _a('{}{}:{}:"{}" => '.format( "{}:".format(self.file_name) if self.file_name else "", line, column, position_context(self.input_str, self.start_position))) elif self.file_name: return _a('{} => '.format(self.file_name)) else: return "<Unknown location>"
def position_context(input_str, position): """ Returns position context string. """ start = max(position - 10, 0) c = str(input_str[start:position]) + _a(" **> ") \ + str(input_str[position:position+10]) return replace_newlines(c)
def position_context(context): """ Returns position context string. """ start = max(context.position - 10, 0) c = text(context.input_str[start:context.position]) + _a(" **> ") \ + text(context.input_str[context.position:context.position+10]) return replace_newlines(c)
def position_context(input_str, position): """ Returns position context string. """ start = max(position - 10, 0) c = text(input_str[start:position]) + _a("*") \ + text(input_str[position:position+10]) c = c.replace("\n", "\\n") return c
def __str__(self): if self.context is None: line, column = None, None else: line, column = self.line, self.column context = self.context if line is not None: return ('{}{}:{}:"{}"'.format( "{}:".format(self.file_name) if self.file_name else "", line, column, position_context(context.input_str, context.start_position))) elif self.file_name: return _a(self.file_name) else: return "<Unknown location>"