本文整理汇总了Python中grammar.Grammar.get_desc方法的典型用法代码示例。如果您正苦于以下问题:Python Grammar.get_desc方法的具体用法?Python Grammar.get_desc怎么用?Python Grammar.get_desc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grammar.Grammar
的用法示例。
在下文中一共展示了Grammar.get_desc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nonexistent_file
# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import get_desc [as 别名]
def test_nonexistent_file(self):
# Ensure no exceptions are thrown.
grammar = Grammar("nonexistent.json")
self.assertEqual(grammar.get_desc(), "")
示例2: test_grammar_load
# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import get_desc [as 别名]
def test_grammar_load(self):
grammar = Grammar("grammars/grammar1.json")
self.assertEqual(grammar.get_desc(), "{a^n # b^n | n > 0}")
示例3: len
# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import get_desc [as 别名]
examples:
./analyze.py grammars/grammar1.json "a#b"
./analyze.py grammars/grammar1.json ""
"""
import sys
from grammar import Grammar
from grammaranalyzer import GrammarAnalyzer
args = sys.argv
# Helpful usage hints.
if len(args) != 3:
print("usage:")
print("\t./analyze.py <path to grammar json> <input string>\n")
print("examples:")
print("\t./analyze.py grammars/grammar1.json \"a#b\"")
print("\t./analyze.py grammars/grammar1.json \"\"")
sys.exit()
path_to_grammar = args[1]
input_string = args[2]
grammar = Grammar(path_to_grammar)
grammar_analyzer = GrammarAnalyzer(grammar)
if grammar_analyzer.test_string(input_string):
print(grammar.get_desc() + ' CONTAINS "' + input_string + '"')
else:
print(grammar.get_desc() + ' DOES NOT CONTAIN "' + input_string + '"')