本文整理汇总了Python中stack.Stack.contains方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.contains方法的具体用法?Python Stack.contains怎么用?Python Stack.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IfdefOperation
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import contains [as 别名]
class IfdefOperation(Operation):
stack = None
def __init__(self):
self.stack = Stack()
pass
def apply(self, line, state):
result = OperationResult(line, False)
skip = False
if not self.stack.isEmpty():
#print(str(state.row) + " : " + str(self.stack.arr))
if self.stack.contains(False):
skip = True
dirsearch = regex['directive'].search(line)
if dirsearch:
directive = dirsearch.group(1)
identifier = dirsearch.group(2)
if directive == "#ifdef" or directive == "#ifndef" and not skip:
result.line = commentLine(result.line)
if identifier == "":
result.error = "Invalid " + directive
return result
if not identifier in state.macros:
self.stack.push(directive == "#ifndef")
result.line = handleCulledLine(result.line)
return result
self.stack.push(directive != "#ifndef")
elif directive == "#else":
result.line = commentLine(result.line)
if self.stack.isEmpty():
result.error = "Unexpected #else"
return result
if self.stack.top() == True:
self.stack.pop()
self.stack.push(False)
else:
self.stack.pop()
self.stack.push(True)
elif directive == "#endif":
result.line = commentLine(result.line)
if self.stack.isEmpty():
result.error = "Unexpected #endif"
return result
self.stack.pop()
if skip:
result.line = handleCulledLine(result.line)
return result