fix: enable to access interval as a list

This commit is contained in:
Vladi Lyga 2016-11-30 17:16:35 +02:00
parent f50fb7df15
commit 8b60373c43
2 changed files with 10 additions and 4 deletions

View File

@ -40,7 +40,6 @@
# {@link CommonTokenStream}.</p>
from io import StringIO
from antlr4.IntervalSet import Interval
from antlr4.Token import Token
from antlr4.error.Errors import IllegalStateException
@ -306,11 +305,11 @@ class BufferedTokenStream(TokenStream):
self.lazyInit()
self.fill()
if interval is None:
interval = Interval(0, len(self.tokens)-1)
start = interval.start
interval = (0, len(self.tokens)-1)
start = interval[0]
if isinstance(start, Token):
start = start.tokenIndex
stop = interval.stop
stop = interval[1]
if isinstance(stop, Token):
stop = stop.tokenIndex
if start is None or stop is None or start<0 or stop<0:

View File

@ -18,6 +18,13 @@ class Interval(object):
def __iter__(self):
return iter(self.range)
def __getitem__(self, idx):
if idx == 0:
return self.start
elif idx == 1:
return self.stop
raise IndexError('Interval index out or range [{}]'.format(idx))
class IntervalSet(object):
def __init__(self):