本文整理汇总了Python中Lexer.Lexer.expect_keywords方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.expect_keywords方法的具体用法?Python Lexer.expect_keywords怎么用?Python Lexer.expect_keywords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer.Lexer
的用法示例。
在下文中一共展示了Lexer.expect_keywords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from Lexer import Lexer [as 别名]
# 或者: from Lexer.Lexer import expect_keywords [as 别名]
#.........这里部分代码省略.........
self.lexer.expect('comma')
self.lexer.skip('whitespace')
commands.append(self.lexer.expect('identifier'))
self.lexer.skip('whitespace')
if len(commands) > 0:
commands.insert(0, id)
id = None
if id is None:
id = self.lexer.expect('identifier')
elif self.lexer.token == 'identifier':
commands.append(id)
id = self.lexer.expect('identifier')
if len(commands) == 0 and id.lower() == 'skip':
# Special case: command "skip" can be used without identifier
return None, [id]
else:
return id, commands
def parse_rule(self, name, actions):
"""
Parse an expression and add the rule to the current section
@return: None
"""
self.lexer.skip('whitespace', 'comment')
if self.lexer.token in ['newline', 'endofstream'] or self.lexer.is_keyword('enter', 'exit', 'switch'):
expression = None
else:
expression = self.parse_expression()
self.lexer.skip('whitespace')
rule = self.Rule(name, expression, actions)
self.rules_file[-1].add('rule', rule)
if self.lexer.token == 'identifier':
keyword = self.lexer.expect_keywords('enter', 'exit', 'switch').lower()
self.lexer.skip('whitespace')
if keyword == 'enter' or keyword == 'switch':
self.lexer.skip('whitespace')
text = self.lexer.expect('identifier')
if text.lower() == 'section':
section = self.Section(name, self.rules_file[-1])
self.lexer.skip('whitespace')
attributes = self.parse_section_attributes()
section.inherits = 'inherits' in attributes
section.exits = 'exits' in attributes
rule.section_action = (keyword, section)
self.rules_file[-1].add_scope('section', section)
self.rules_file.append(section)
else:
rule.section_action = (keyword, self.SectionReference(text))
elif keyword == 'exit':
rule.section_action = ('exit', None)
self.lexer.expect_keywords('section')
def parse_definition(self, name):
"""
Parse an expression and add the define to the current section
@param name: the ID of the definition being parsed
@return: None
"""
self.lexer.skip('whitespace')
expression = self.parse_expression()
define = self.Define(name, expression)
self.rules_file[-1].add('define', define)
def parse_expression(self):
"""