示例#1
0
文件: Validate.py 项目: momirza/pydsl
def validate(sgrammar:"SymbolGrammar", expression) -> "[AST]":
    """Returns a list of postTreeNodes"""
    resulttrees = sgrammar.get_trees(expression, True)
    treelist = []
    for tree in resulttrees:
        from pydsl.Grammar.Tree import parser_to_post_tree
        treelist.append(parser_to_post_tree(tree))
    return treelist
示例#2
0
文件: Symbol.py 项目: momirza/pydsl
 def get_groups(self, word, propertyname:str) -> list:
     """ Allow to ask for a grammar property of a valid sentence. Example: (English)ask for verb in a phrase: askProperty("verb","desk is clean") Maybe there is a method to pass it through __init__ (like _matchFun) """
     treelist = self.__parser.get_trees(word)
     for tree in treelist:
         from pydsl.Grammar.Tree import parser_to_post_tree
         posttree = parser_to_post_tree(tree)
         if propertyname in posttree:
             return posttree[propertyname] 
         else:
             return []