View
@@ -11,9 +11,9 @@
import re
from asdl import const
from core import util
from core.id_kind import Id
from osh import ast_ as ast
@@ -43,7 +43,7 @@ def __init__(self, match_func, line, arena=None):
self.arena = arena
self.arena_skip = False # For MaybeUnreadOne
self.last_span_id = 0 # For MaybeUnreadOne
self.last_span_id = const.NO_INTEGER # For MaybeUnreadOne
self.Reset(line, -1) # Invalid arena index to start
@@ -88,7 +88,7 @@ def LookAhead(self, lex_mode):
# would involve interacting with the line reader, and we never need
# it. In the OUTER mode, there is an explicit newline token, but
# ARITH doesn't have it.
t = ast.token(Id.Unknown_Tok, '', 0) # no span ID
t = ast.token(Id.Unknown_Tok, '', const.NO_INTEGER)
return t
tok_type, end_pos = self.match_func(lex_mode, self.line, pos)
@@ -99,7 +99,7 @@ def LookAhead(self, lex_mode):
break
pos = end_pos
return ast.token(tok_type, tok_val, 0) # no span ID
return ast.token(tok_type, tok_val, const.NO_INTEGER)
def AtEnd(self):
return self.line_pos == len(self.line)
@@ -125,7 +125,7 @@ def Read(self, lex_mode):
if self.arena is not None:
if self.arena_skip:
assert self.last_span_id != 0
assert self.last_span_id != const.NO_INTEGER
span_id = self.last_span_id
self.arena_skip = False
else:
@@ -134,7 +134,7 @@ def Read(self, lex_mode):
else:
# Completion parser might not have arena?
# We should probably get rid of this.
span_id = 0
span_id = const.NO_INTEGER
t = ast.token(tok_type, tok_val, span_id)
View
@@ -12,6 +12,7 @@
import sys
from asdl import const
from core import word
@@ -91,19 +92,18 @@ def MakeStatusLines():
def PrettyPrintError(parse_error, arena, f):
#print(parse_error)
if parse_error.span_id is not None:
if parse_error.span_id != const.NO_INTEGER:
span_id = parse_error.span_id
elif parse_error.token:
span_id = parse_error.token.span_id
elif parse_error.part:
span_id = word.LeftMostSpanForPart(parse_error.part)
elif parse_error.word:
# Can be -1
span_id = word.LeftMostSpanForWord(parse_error.word)
else:
span_id = -1
span_id = const.NO_INTEGER # invalid
if span_id == -1:
if span_id == const.NO_INTEGER:
line = '<no position info for token>'
path = '<unknown>'
line_num = -1
View
@@ -23,8 +23,9 @@
import inspect
import types
from asdl import const
Buffer = io.BytesIO
Buffer = io.BytesIO # used by asdl/format.py
class _ErrorWithLocation(Exception):
@@ -37,7 +38,7 @@ def __init__(self, msg, *args, **kwargs):
self.args = args
# NOTE: We use a kwargs dict because Python 2 doesn't have keyword-only
# args.
self.span_id = kwargs.pop('span_id', None)
self.span_id = kwargs.pop('span_id', const.NO_INTEGER)
self.token = kwargs.pop('token', None)
self.part = kwargs.pop('part', None)
self.word = kwargs.pop('word', None)
View
@@ -6,6 +6,7 @@
from osh import ast_ as ast
from core.id_kind import Id, Kind, LookupKind
from core import util
from asdl import const
p_die = util.p_die
@@ -108,7 +109,7 @@ def LeftMostSpanForPart(part):
if part.tag == word_part_e.ArrayLiteralPart:
if not part.words:
return -1
return const.NO_INTEGER
else:
return LeftMostSpanForWord(part.words[0]) # Hm this is a=(1 2 3)
@@ -123,14 +124,14 @@ def LeftMostSpanForPart(part):
if part.tokens:
return part.tokens[0].span_id
else:
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.DoubleQuotedPart:
if part.parts:
return LeftMostSpanForPart(part.parts[0])
else:
# We need the double quote location
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.SimpleVarSub:
return part.token.span_id
@@ -142,7 +143,7 @@ def LeftMostSpanForPart(part):
return part.spids[0]
elif part.tag == word_part_e.TildeSubPart:
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.ArithSubPart:
# begin, end
@@ -176,31 +177,31 @@ def _RightMostSpanForPart(part):
if part.tokens:
return part.tokens[-1].span_id
else:
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.DoubleQuotedPart:
if part.parts:
return LeftMostSpanForPart(part.parts[-1])
else:
# We need the double quote location
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.SimpleVarSub:
return part.token.span_id
elif part.tag == word_part_e.BracedVarSub:
spid = part.spids[0]
assert spid != -1
assert spid != const.NO_INTEGER
return spid
elif part.tag == word_part_e.CommandSubPart:
return part.spids[1]
elif part.tag == word_part_e.TildeSubPart:
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.ArithSubPart:
return -1
return const.NO_INTEGER
elif part.tag == word_part_e.ExtGlobPart:
return part.spids[1]
@@ -227,7 +228,7 @@ def LeftMostSpanForWord(w):
# TODO: Really we should use par
if w.tag == word_e.CompoundWord:
if len(w.parts) == 0:
return -1
return const.NO_INTEGER
elif len(w.parts) == 1:
return LeftMostSpanForPart(w.parts[0])
else:
@@ -245,7 +246,7 @@ def UNUSED_RightMostSpanForWord(w):
# TODO: Really we should use par
if w.tag == word_e.CompoundWord:
if len(w.parts) == 0:
return -1
return const.NO_INTEGER
elif len(w.parts) == 1:
return _RightMostSpanForPart(w.parts[0])
else:
View
@@ -12,6 +12,8 @@
import sys
from asdl import const
from core import braces
from core import word
from core.id_kind import Id, Kind
@@ -216,7 +218,7 @@ def ParseRedirect(self):
if first_char.isdigit():
fd = int(first_char)
else:
fd = -1
fd = const.NO_INTEGER
if self.c_id in (Id.Redir_DLess, Id.Redir_DLessDash): # here doc
node = ast.HereDoc()
View
@@ -11,6 +11,8 @@
import unittest
from asdl import const
from core import alloc
from core.id_kind import Id
from core import word
@@ -70,7 +72,7 @@ def _assertSpanForWord(test, code_str):
print(code_str)
print(span_id)
if span_id != -1:
if span_id != const.NO_INTEGER:
span = arena.GetLineSpan(span_id)
print(span)