예제 #1
0
파일: syntax.py 프로젝트: ktonon/GameSoup
 def parse(cls, w):
     """
     This is the usual way to instantiate an interface expression
     from a string.
     
     The most basic interface expression is the empty expression,
     to which all other expressions are super. It is represented
     as an empty union set using square brackets.
     
         >>> Expr.parse('[]')
         []
     
     Parsing an empty string will just return the integer 0
     instead of an expression object.
     
         >>> nothing = Expr.parse('')
         >>> nothing
         0
         >>> nothing.__class__.__name__
         'int'
     """
     if isinstance(w, Expr): return w
     if re.match(r'^\s*(?:0)?\s*$', w): return 0
     expr = cls.get(w)
     if expr is None:
         tree = Rule.expr(w)
         expr = cls.from_tree(tree)
         cls.set(w, expr)
     return expr
예제 #2
0
파일: grammar.py 프로젝트: ktonon/GameSoup
def render(w, g):
    '''
    Render expression w to graph g.
    '''
    try:
        tree = Rule.expr(w)
    except Exception, e:
        g.add_node('invalid', label='%s' % e)
        return