Package jazzparser :: Package parsers :: Module loader
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.parsers.loader

 1  """Utility to load dynamically a named parser module. 
 2   
 3  Tools for loading a parser module by name. The main tool, get_parser,  
 4  returns the actual Parser subclass that implements this parsing  
 5  algorithm, which implements the standard interface defined by Parser. 
 6   
 7  """ 
 8  """ 
 9  ============================== License ======================================== 
10   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
11    
12   This file is part of The Jazz Parser. 
13    
14   The Jazz Parser is free software: you can redistribute it and/or modify 
15   it under the terms of the GNU General Public License as published by 
16   the Free Software Foundation, either version 3 of the License, or 
17   (at your option) any later version. 
18    
19   The Jazz Parser is distributed in the hope that it will be useful, 
20   but WITHOUT ANY WARRANTY; without even the implied warranty of 
21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
22   GNU General Public License for more details. 
23    
24   You should have received a copy of the GNU General Public License 
25   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
26   
27  ============================ End license ====================================== 
28   
29  """ 
30  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
31   
32  from jazzparser.utils.base import load_class 
33  from jazzparser.settings import DEFAULT_PARSER 
34   
35 -def get_parser(name):
36 from . import PARSERS 37 if name not in PARSERS: 38 raise ParserLoadError, "The parser '%s' does not exist." % name 39 path = 'jazzparser.parsers.%s.Parser' % name 40 return load_class(path)
41
42 -def get_default_parser():
43 return get_parser(DEFAULT_PARSER)
44
45 -class ParserLoadError(Exception):
46 pass
47