本文整理汇总了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)