本文整理汇总了Python中lexer.Lexer.nextToken方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.nextToken方法的具体用法?Python Lexer.nextToken怎么用?Python Lexer.nextToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.nextToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StateLinker
# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import nextToken [as 别名]
class StateLinker(Visitor):
def __init__(self):
self.visiting_statechart = None
self.visiting_node = None
self.lexer = Lexer()
def visit_ClassDiagram(self, class_diagram):
for c in class_diagram.classes :
c.accept(self)
def visit_Class(self, c):
if c.statechart:
c.statechart.accept(self)
def visit_StateChart(self, statechart):
self.visiting_statechart = statechart
for node in statechart.basics + statechart.composites:
node.accept(self)
def visit_StateChartNode(self, node):
self.visiting_node = node
node.enter_action.accept(self)
node.exit_action.accept(self)
for transition in node.transitions :
transition.accept(self)
def visit_StateChartTransition(self, transition):
try :
transition.target.accept(self)
except StateReferenceException as exception :
raise StateReferenceException("Transition from <" + self.visiting_node.full_name + "> has invalid target. " + exception.message)
try :
transition.action.accept(self)
except StateReferenceException as exception :
raise StateReferenceException("Transition from <" + self.visiting_node.full_name + "> has invalid action. " + exception.message)
try :
if transition.guard :
transition.guard.accept(self)
except StateReferenceException as exception :
raise StateReferenceException("Transition from <" + self.visiting_node.full_name + "> has invalid guard. " + exception.message)
def visit_StateReference(self, state_reference):
state_reference.target_nodes = []
current_node = None #Will be used to find the target state(s)
split_stack = [] #used for branching
self.lexer.input(state_reference.path_string)
for token in self.lexer.tokens() :
if current_node == None : #current_node is not set yet or has been reset, the CHILD token can now have a special meaning
if token.type == TokenType.SLASH :
#Root detected
current_node = self.visiting_statechart.root
#Token consumed so continue
continue
else :
current_node = self.visiting_node
if token.type == TokenType.DOT :
#Advance to next token
token = self.lexer.nextToken()
if token is None or token.type == TokenType.SLASH :
#CURRENT operator "." detected
continue
elif token.type == TokenType.DOT :
#Advance to next token
token = self.lexer.nextToken()
if token is None or token.type == TokenType.SLASH :
#PARENT operator ".." detected
current_node = current_node.parent
if current_node is None :
raise StateReferenceException("Illegal use of PARENT \"..\" operator at position " + str(token.pos) + " in state reference. Root of statechart reached.")
else :
raise StateReferenceException("Illegal use of PARENT \"..\" operator at position " + str(token.pos) + " in state reference.")
else :
raise StateReferenceException("Illegal use of CURRENT \".\" operator at position " + str(token.pos) + " in state reference.")
elif token.type == TokenType.SLASH :
continue
elif token.type == TokenType.WORD :
#try to advance to next child state
cname = token.val
found = False
for child in current_node.children :
if child.name == cname :
found = True
current_node = child
break
if not found :
raise StateReferenceException("Refering to non exiting node at posisition " + str(token.pos) + " in state reference.")
elif token.type == TokenType.LBRACKET :
split_stack.append(current_node)
elif token.type == TokenType.RBRACKET :
if len(split_stack) > 0 :
#.........这里部分代码省略.........