コード例 #1
0
ファイル: __init__.py プロジェクト: imvial/Vitamin
 def parse(self, tokens):        
     
     #вспомогательные конструкции первого уровня
     obr = skip(ntype("{"))
     cbr = skip(ntype("}"))
     osbr = skip(ntype("["))
     csbr = skip(ntype("]"))
     check = skip(ntype("?"))
     ref = skip(ntype(">>"))
     alt = skip(ntype("|"))
     uns = skip(ntype("#"))
     star = skip(ntype("@"))        
     twospot = skip(ntype(":"))
     #текст
     text = ntype("text") >> self.create_str
     value = (obr + text + cbr) >> self.create_var
     reference = (ref + text) >> self.create_ref      
     cycle = (uns + reference + star + text + uns) >> self.create_cycle
     flag = (obr + text + twospot + (oneplus(text) >> zip) + cbr) >> self.create_flag    
     alternative = future()
     tryme = future()
     ctr_ = oneplus(text | value | reference | alternative | flag | cycle | tryme) >> zip
     ctr = ctr_ + finish()
     alternative.define((osbr + ctr_.join(alt) + csbr) >> self.create_alter)
     tryme.define((check + osbr + ctr_.join(alt) + csbr) >> self.create_tryme)
     return ctr.parse(tokens)[0]
コード例 #2
0
ファイル: vitaparse.py プロジェクト: dmifurman/Vitamin
 def parse(tokens):
     integer = ntype("int") >> (lambda t: int(t.value))
     comma = skip(ntype(","))
     obr = skip(ntype("{"))
     cbr = skip(ntype("}"))
     br = skip(ntype("'"))
     orbr = skip(ntype("("))
     crbr = skip(ntype(")"))
     two = skip(ntype(":"))
     word = ntype("text") >> (lambda t: t.value)
     string = br + word + br
     dictionary = future()
     tuple = future()
     elem = integer | string | tuple | dictionary
     tuple.define(orbr + elem.join(comma) + crbr)
     dictionary.define((obr + (elem + two + elem).join(comma) + cbr >> dict))
     parser = dictionary | tuple
     return parser.parse(tokens)[0]