Esempio n. 1
0
 def create_root_symbols(self):
     """Insert magical symbols above the root of the grammar in
     order to match the beginning and end of the sample."""
     RootSymbol = Symbol(Token(None,None,'R00t.Symbol'))
     RootSymbol.GlobalSymbolDict=self.GlobalSymbolDict
     StartDocSymbol = Symbol(Token(None,None,'%^'))
     StartDocSymbol.regex = Set('%^')
     StartDocSymbol.is_lit = True
     StartDocSymbol.GlobalSymbolDict=self.GlobalSymbolDict
     EndDocSymbol = Symbol(Token(None,None,'%$'))
     EndDocSymbol.regex = Set('%$')
     EndDocSymbol.is_lit = True
     EndDocSymbol.GlobalSymbolDict=self.GlobalSymbolDict
     RootSymbol.productions = [Production(RootSymbol,[StartDocSymbol]+self.get_roots()+[EndDocSymbol])]
     self.GlobalSymbolDict['R00t.Symbol'] = RootSymbol #XXX this is a nasty hack
     self.GlobalSymbolDict['%^']=StartDocSymbol
     self.GlobalSymbolDict['%$']=EndDocSymbol