本文整理汇总了Python中arpeggio.ParserPython.root_rule_name方法的典型用法代码示例。如果您正苦于以下问题:Python ParserPython.root_rule_name方法的具体用法?Python ParserPython.root_rule_name怎么用?Python ParserPython.root_rule_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arpeggio.ParserPython
的用法示例。
在下文中一共展示了ParserPython.root_rule_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _from_peg
# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import root_rule_name [as 别名]
def _from_peg(self, language_def):
parser = ParserPython(peggrammar, comment, reduce_tree=False,
debug=self.debug)
parser.root_rule_name = self.root_rule_name
parse_tree = parser.parse(language_def)
return visit_parse_tree(parse_tree, PEGVisitor(self.root_rule_name,
self.comment_rule_name,
self.ignore_case,
debug=self.debug))
示例2: language_from_str
# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import root_rule_name [as 别名]
def language_from_str(language_def, metamodel):
"""
Constructs parser and initializes metamodel from language description
given in textX language.
Args:
language_def (str): A language description in textX.
metamodel (TextXMetaModel): A metamodel to initialize.
Returns:
Parser for the new language.
"""
if metamodel.debug:
metamodel.dprint("*** PARSING LANGUAGE DEFINITION ***")
# Check the cache for already conctructed textX parser
if metamodel.debug in textX_parsers:
parser = textX_parsers[metamodel.debug]
else:
# Create parser for TextX descriptions from
# the textX grammar specified in this module
parser = ParserPython(textx_model, comment_def=comment,
ignore_case=False,
reduce_tree=False, debug=metamodel.debug)
# Prepare regex used in keyword-like strmatch detection.
# See str_match_SA
flags = 0
if metamodel.ignore_case:
flags = re.IGNORECASE
parser.keyword_regex = re.compile(r'[^\d\W]\w*', flags)
# Cache it for subsequent calls
textX_parsers[metamodel.debug] = parser
# This is used during parser construction phase.
# Metamodel is filled in. Classes are created based on grammar rules.
parser.metamodel = metamodel
# Builtin rules representing primitive types
parser.root_rule_name = None
# Parse language description with textX parser
try:
parser.parse(language_def)
except NoMatch as e:
line, col = parser.pos_to_linecol(e.position)
raise TextXSyntaxError(text(e), line, col)
# Construct new parser based on the given language description.
lang_parser = parser.getASG()
# Meta-model is constructed. Validate semantics of metamodel.
parser.metamodel.validate()
# Meta-model is constructed. Here we connect meta-model and language
# parser for convenience.
lang_parser.metamodel = parser.metamodel
metamodel.parser = lang_parser
if metamodel.debug:
# Create dot file for debuging purposes
PMDOTExporter().exportFile(
lang_parser.parser_model,
"{}_parser_model.dot".format(metamodel.rootcls.__name__))
return lang_parser