#NEWLINE# def get_model_parser( top_rule , comments_model , **kwargs ) : #NEWLINE# #INDENT# '\n    Creates model parser for the given language.\n    ' #NEWLINE# class TextXModelParser ( Parser ) : #NEWLINE# #INDENT# '\n        Parser created from textual textX language description.\n        Semantic actions for this parser will construct object\n        graph representing model on the given language.\n        ' #NEWLINE# def __init__( self , * args , **kwargs ) : #NEWLINE# #INDENT# super ( TextXModelParser , self ) . __init__ ( * args , ** kwargs ) #NEWLINE# self . parser_model = Sequence ( nodes = [ top_rule , EOF ( ) ] , rule_name = 'ModelFile' , root = True ) #NEWLINE# self . comments_model = comments_model #NEWLINE# self . _inst_stack = [ ] #NEWLINE# self . _instances = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# def _parse( self ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return self . parser_model . parse ( self ) #NEWLINE# #UNINDENT# except NoMatch as e : #NEWLINE# #INDENT# ( line , col ) = e . parser . pos_to_linecol ( e . position ) #NEWLINE# raise TextXSyntaxError ( text ( e ) , line , col ) #NEWLINE# #UNINDENT# #UNINDENT# def get_model_from_file( self , file_name , encoding , debug ) : #NEWLINE# #INDENT# '\n            Creates model from the parse tree from the previous parse call.\n            If file_name is given file will be parsed before model\n            construction.\n            ' #NEWLINE# with codecs . open ( file_name , 'r' , encoding ) as f : #NEWLINE# #INDENT# model_str = f . read ( ) #NEWLINE# #UNINDENT# model = self . get_model_from_str ( model_str , file_name = file_name , debug = debug ) #NEWLINE# try : #NEWLINE# #INDENT# model . _filename = file_name #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return model #NEWLINE# #UNINDENT# def get_model_from_str( self , model_str , file_name = None , debug = None ) : #NEWLINE# #INDENT# '\n            Parses given string and creates model object graph.\n            ' #NEWLINE# old_debug_state = self . debug #NEWLINE# try : #NEWLINE# #INDENT# if ( debug is not None ) : #NEWLINE# #INDENT# self . debug = debug #NEWLINE# #UNINDENT# if self . debug : #NEWLINE# #INDENT# self . dprint ( '*** PARSING MODEL ***' ) #NEWLINE# #UNINDENT# self . parse ( model_str , file_name = file_name ) #NEWLINE# model = parse_tree_to_objgraph ( self , self . parse_tree [ 0 ] ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if ( debug is not None ) : #NEWLINE# #INDENT# self . debug = old_debug_state #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# model . _filename = None #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return model #NEWLINE# #UNINDENT# #UNINDENT# return TextXModelParser ( ** kwargs )