Package PyFoam :: Package Basics :: Module PlyParser
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.PlyParser

 1  """Base class for all parser classes based on PLY 
 2   
 3  Most of this class was shamelessly stolen from the examples""" 
 4   
 5   
 6  import PyFoam.ThirdParty.ply.lex as lex 
 7  import PyFoam.ThirdParty.ply.yacc as yacc 
 8   
 9  import os 
10   
11 -class PlyParser(object):
12 """ 13 Base class for a lexer/parser that has the rules defined as methods 14 """ 15 tokens = () 16 precedence = () 17 18
19 - def __init__(self, **kw):
20 """Constructs the parser and the lexer""" 21 self.debug = kw.get('debug', 1) 22 self.names = { } 23 try: 24 modname = os.path.split(os.path.splitext(__file__)[0])[1] + "_" + self.__class__.__name__ 25 except: 26 modname = "parser"+"_"+self.__class__.__name__ 27 self.debugfile = modname + ".dbg" 28 self.tabmodule = modname + "_" + "parsetab" 29 #print self.debugfile, self.tabmodule 30 31 # Build the lexer and parser 32 lex.lex(module=self, debug=self.debug) 33 yacc.yacc(module=self, 34 debug=self.debug, 35 debugfile=self.debugfile, 36 tabmodule=self.tabmodule) 37 self.lex=lex 38 self.yacc=yacc
39
40 - def parse(self,content):
41 """Do the actual parsing 42 @param content: String that is to be parsed 43 @return: Result of the parsing""" 44 45 return yacc.parse(content)
46