diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-01-11 20:28:57 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2012-01-11 20:28:57 +0000 |
commit | 7b79ae514806848e5f1dacd62540406182f81aca (patch) | |
tree | 53b9d4db12657edb93ce3ce9e454c9c0706b85a6 /docutils/parsers/rst | |
parent | a90d43de9fb59d1329e0d66b790a5b2f7882a273 (diff) | |
download | docutils-7b79ae514806848e5f1dacd62540406182f81aca.tar.gz |
Report table parsing errors with correct line number.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7313 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/parsers/rst')
-rw-r--r-- | docutils/parsers/rst/states.py | 10 | ||||
-rw-r--r-- | docutils/parsers/rst/tableparser.py | 37 |
2 files changed, 31 insertions, 16 deletions
diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py index 4d822a3e1..f2955a32d 100644 --- a/docutils/parsers/rst/states.py +++ b/docutils/parsers/rst/states.py @@ -1627,9 +1627,9 @@ class Body(RSTState): + 1) table = self.build_table(tabledata, tableline) nodelist = [table] + messages - except tableparser.TableMarkupError, detail: - nodelist = self.malformed_table( - block, ' '.join(detail.args)) + messages + except tableparser.TableMarkupError, err: + nodelist = self.malformed_table(block, ' '.join(err.args), + offset=err.offset) + messages else: nodelist = messages return nodelist, blank_finish @@ -1715,7 +1715,7 @@ class Body(RSTState): block.pad_double_width(self.double_width_pad_char) return block, [], end == limit or not lines[end+1].strip() - def malformed_table(self, block, detail=''): + def malformed_table(self, block, detail='', offset=0): block.replace(self.double_width_pad_char, '') data = '\n'.join(block) message = 'Malformed table.' @@ -1723,7 +1723,7 @@ class Body(RSTState): if detail: message += '\n' + detail error = self.reporter.error(message, nodes.literal_block(data, data), - line=startline) + line=startline+offset) return [error] def build_table(self, tabledata, tableline, stub_columns=0): diff --git a/docutils/parsers/rst/tableparser.py b/docutils/parsers/rst/tableparser.py index a8c6be355..63a6caf92 100644 --- a/docutils/parsers/rst/tableparser.py +++ b/docutils/parsers/rst/tableparser.py @@ -26,7 +26,18 @@ from docutils import DataError from docutils.utils import strip_combining_chars -class TableMarkupError(DataError): pass +class TableMarkupError(DataError): + + """ + Raise if there is any problem with table markup. + + The keyword argument `offset` denotes the offset of the problem + from the table's start line. + """ + + def __init__(self, *args, **kwargs): + self.offset = kwargs.pop('offset', 0) + DataError.__init__(self, *args) class TableParser: @@ -64,16 +75,17 @@ class TableParser: if self.head_body_separator_pat.match(line): if self.head_body_sep: raise TableMarkupError( - 'Multiple head/body row separators in table (at line ' - 'offset %s and %s); only one allowed.' - % (self.head_body_sep, i)) + 'Multiple head/body row separators ' + '(table lines %s and %s); only one allowed.' + % (self.head_body_sep+1, i+1), offset=i) else: self.head_body_sep = i self.block[i] = line.replace('=', '-') if self.head_body_sep == 0 or self.head_body_sep == (len(self.block) - 1): raise TableMarkupError('The head/body row separator may not be ' - 'the first or last line of the table.') + 'the first or last line of the table.', + offset=i) class GridTableParser(TableParser): @@ -425,8 +437,9 @@ class SimpleTableParser(TableParser): cols.append((begin, end)) if self.columns: if cols[-1][1] != self.border_end: - raise TableMarkupError('Column span incomplete at line ' - 'offset %s.' % offset) + raise TableMarkupError('Column span incomplete in table ' + 'line %s.' % (offset+1), + offset=offset) # Allow for an unbounded rightmost column: cols[-1] = (cols[-1][0], self.columns[-1][1]) return cols @@ -442,8 +455,9 @@ class SimpleTableParser(TableParser): i += 1 morecols += 1 except (AssertionError, IndexError): - raise TableMarkupError('Column span alignment problem at ' - 'line offset %s.' % (offset + 1)) + raise TableMarkupError('Column span alignment problem ' + 'in table line %s.' % (offset+2), + offset=offset+1) cells.append([0, morecols, offset, []]) i += 1 return cells @@ -502,8 +516,9 @@ class SimpleTableParser(TableParser): if new_end > main_end: self.columns[-1] = (main_start, new_end) elif line[end:nextstart].strip(): - raise TableMarkupError('Text in column margin at line ' - 'offset %s.' % (first_line + offset)) + raise TableMarkupError('Text in column margin ' + 'in table line %s.' % (first_line+offset+1), + offset=first_line+offset) offset += 1 columns.pop() |