[docs]classMatlabParser(LanguageParser):""" Represents a grammar for the MATLAB language. """def__init__(self,remove_line_continuations:bool=False,**kwargs):""" Initializes a new instance of the MatlabGrammar class. Args: remove_line_continuations (bool, optional): Whether to remove line continuations. Defaults to False. """self._rlc=remove_line_continuationstmLanguageFile=(Path(__file__).parents[3]/"syntaxes"/"matlab"/"Matlab.tmbundle"/"Syntaxes"/"MATLAB.tmLanguage")tmLanguageYAML=Path(__file__).parent/"grammar.yaml"iftmLanguageFile.exists():withopen(tmLanguageFile,"rb")astmFile:grammar=plistlib.load(tmFile,fmt=plistlib.FMT_XML)withopen(tmLanguageYAML,"w")asymlFile:ymlFile.write(yaml.dump(grammar,indent=2))else:withopen(tmLanguageYAML)asymlFile:try:grammar=yaml.load(ymlFile.read(),Loader=yaml.CLoader)exceptImportError:grammar=yaml.load(ymlFile.read(),Loader=yaml.Loader)super().__init__(grammar,**kwargs)
[docs]defpre_process(self,input:str)->str:""" Pre-processes the input text. """ifself._rlc:input=self._remove_line_continuations(input)returninput
def_remove_line_continuations(self,input:str)->str:""" Removes line continuations from the input text. """if"..."notininput:returninputoutput=""forsplitininput.split("..."):matching=re.search(r"\n[\t\f\v ]*",split)ifmatching:output+=split[matching.span()[1]:]else:output+=splitreturnoutput