Repository: neogeny/TatSu

Issue:
Error message doesn't contains line on witch error happens
```python
import tatsu

GRAMMAR_TEXT = """
start = ATTRIBUTE operator value ;

ATTRIBUTE = /[A-Za-z]+/;

operator = '='
         | '!='
         ;

value = NUMBER ;

NUMBER = /[0-9]+/ ;
"""


def parse(data):
    with open('gr.py', 'w') as fd:
        fd.write(tatsu.to_python_sourcecode(GRAMMAR_TEXT))
    grammar = tatsu.compile(GRAMMAR_TEXT)
    return grammar.parse(data)


for sample in ['foo = 1', 'foo']:
    print(sample)
    print(parse(sample))

```

```
python t.py
foo = 1
['foo', '=', '1']
foo
Traceback (most recent call last):
  File "t.py", line 27, in <module>
    print(parse(sample))
  File "t.py", line 22, in parse
    return grammar.parse(data)
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 946, in parse
    **kwargs
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 211, in parse
    raise self._furthest_exception
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 203, in parse
    result = rule()
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 694, in parse
    result = self._parse_rhs(ctx, self.exp)
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 701, in _parse_rhs
    result = ctx._call(ruleinfo)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 509, in _call
    result = self._recursive_call(ruleinfo)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 540, in _recursive_call
    result = self._invoke_rule(ruleinfo, key)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 573, in _invoke_rule
    ruleinfo.impl(self)
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 349, in parse
    ctx.last_node = [s.parse(ctx) for s in self.sequence]
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 349, in <listcomp>
    ctx.last_node = [s.parse(ctx) for s in self.sequence]
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 650, in parse
    return rule()
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 694, in parse
    result = self._parse_rhs(ctx, self.exp)
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 701, in _parse_rhs
    result = ctx._call(ruleinfo)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 509, in _call
    result = self._recursive_call(ruleinfo)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 540, in _recursive_call
    result = self._invoke_rule(ruleinfo, key)
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 573, in _invoke_rule
    ruleinfo.impl(self)
  File "/Users/wizard/Code/TatSu/tatsu/grammars.py", line 401, in parse
    ctx._error('no available options')
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 435, in _error
    raise self._make_exception(item, exclass=exclass)
tatsu.exceptions.FailedParse: (1:1) no available options :

^
operator
start
```

Expected something like
```
  File "/Users/wizard/Code/TatSu/tatsu/contexts.py", line 435, in _error
    raise self._make_exception(item, exclass=exclass)
tatsu.exceptions.FailedParse: (1:1) no available options :
foo
^
operator
start
```


Discussion:

Patch:
diff --git a/tatsu/buffering.py b/tatsu/buffering.py
index cba470c..4ab6cf7 100644
--- a/tatsu/buffering.py
+++ b/tatsu/buffering.py
@@ -340,9 +340,7 @@ class Buffer(object):
         if pos is None:
             pos = self._pos
 
-        if pos >= len(self._line_cache):
-            return LineInfo(self.filename, self.linecount, 0, self._len, self._len, '')
-
+        pos = min(pos, len(self._line_cache) - 2)
         start, line, length = self._line_cache[pos]
         end = start + length
         col = pos - start


Test patch:
diff --git a/test/buffering_test.py b/test/buffering_test.py
index e9d00d2..802ccf9 100644
--- a/test/buffering_test.py
+++ b/test/buffering_test.py
@@ -81,8 +81,8 @@ class BufferingTests(unittest.TestCase):
                 start = n + 1
         text_len = len(self.text)
         info = self.buf.line_info(1 + text_len)
-        self.assertEqual(info.line, 1 + len(self.text.splitlines()))
-        self.assertEqual(info.start, text_len)
+        self.assertEqual(info.line, len(self.text.splitlines()) - 1)
+        self.assertEqual(info.end, text_len)
 
     def test_linecount(self):
         b = Buffer('')