本文整理匯總了Python中source.Source.error方法的典型用法代碼示例。如果您正苦於以下問題:Python Source.error方法的具體用法?Python Source.error怎麽用?Python Source.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類source.Source
的用法示例。
在下文中一共展示了Source.error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Scanner
# 需要導入模塊: from source import Source [as 別名]
# 或者: from source.Source import error [as 別名]
#.........這裏部分代碼省略.........
super(Scanner, self).__init__()
self.source = Source(program)
self.char = ''
self.atomPositionEnd = TextPos()
self.atomPositionStart = TextPos()
self.intConst = 0
self.strConst = ""
self.spell = ""
self.__nextChar()
def __nextChar(self):
self.char = self.source.nextChar()
def nextSymbol(self):
while True:
if self.char == -1:
return SymType.others
while str.isspace(self.char):
self.__nextChar()
if self.char == -1:
return SymType.others
if not str.isspace(self.char):
break
self.atomPositionStart = copy(self.source.textPos)
self.atomPositionEnd = self.source.textPos
if str.isalpha(self.char):
self.spell = ""
while True:
self.spell = self.spell + self.char
self.__nextChar()
if not str.isalnum(self.char):
break
if KT.get(self.spell, -1) != -1:
return KT[self.spell]
else :
return SymType.ident
elif str.isdigit(self.char) and self.char != '0':
num = 0
while True:
num = num*10 + int(self.char)
self.__nextChar()
if not str.isdigit(self.char):
break
self.intConst = num
return SymType.intconst
elif self.char == '0':
self.intConst = 0
self.__nextChar()
if not str.isdigit(self.char) :
return SymType.intconst
else:
return SymType.others
elif self.char == '"':
strConst = ""
while True:
self.__nextChar()
strConst = strConst + self.char
if not str.isalnum(self.char):
break
if self.char == '"':
self.__nextChar()
self.strConst = strConst[:-1]
return SymType.charconst
else:
self.scanError(1)
elif self.char == '<':
self.__nextChar()
if self.char == '=':
self.__nextChar()
return SymType.leop
else :
return SymType.ltop
elif self.char == '>':
self.__nextChar()
if self.char == '=':
self.__nextChar()
return SymType.geop
else :
return SymType.gtop
elif self.char == '(':
self.__nextChar()
return SymType.lparent
elif self.char == ')':
self.__nextChar()
return SymType.rparent
elif self.char == ',':
self.__nextChar()
return SymType.comma
elif self.char == '=':
self.__nextChar()
return SymType.becomes
else:
self.__nextChar()
return SymType.others
def scanError(self, ecode, mtxt="", atxt=""):
self.source.error(ecode, self.atomPositionStart, self.atomPositionEnd, mtxt, atxt)