I have a parser for syntax that uses python to test each command github.
It works very well for what i need, but it is not capable of running python code 'begin program. ;print...' because the parser isn't set up to handle the lack of command terminator or the importance of spaces. The code below is an excerpt of working code found https://github.com/chetstar/Python-SPSS/blob/master/SyntaxErrorTest.py Jon reccomended: """use readlines and for each command just submit the lines that define the command but collect the lines in one of these special blocks until you find the block end and Submit as a batch. """ #Files=['k:\meinzer/Production\dashboarddatasets/clinfo.sps','k:\meinzer/Production\dashboarddatasets/clinfo.sps'] def main(Files): """The parser and processor for Syntax Error Reporting """ try: for FilePath in Files: Start = datetime.now().replace( microsecond=0) DBname, init_Syntax = init_Vars(FilePath) cmds = init_cmds(init_Syntax) try: # cmd, cmd2, cmd3=run_cmds(cmds) cmd2='' cmd3='' for cmd in cmds: cmd=cmd.replace('\r\n','\n ') cmd=cmd.replace('\t',' ') print cmd spss.Submit(cmd) cmd3=cmd2 cmd2=cmd def init_cmds(init_Syntax): """initalize the syntax by removing BOMUTF8, seperating on os.linesep """ with open(init_Syntax,'rb') as f: BOM_UTF8 = "\xef\xbb\xbf" code = f.read().lstrip(BOM_UTF8) cmds = re.split("(?<=\\.)%s[\t]*" % os.linesep, code, flags=re.M) cmds = [cmd.lstrip() for cmd in cmds if not cmd.startswith("*")] return cmds |
Administrator
|
I'm sure there is a question in here somewhere. Please clarify.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
How do I get my code to parse python script that is embedded in spss syntax?
|
Free forum by Nabble | Edit this page |