<s> """<STR_LIT>""" <EOL> import re <EOL> from pyparsing import CaselessKeyword <EOL> from pyparsing import CharsNotIn <EOL> from pyparsing import Literal <EOL> from pyparsing import OneOrMore <EOL> from pyparsing import WordStart <EOL> from pyparsing import ZeroOrMore <EOL> from pyparsing import nestedExpr <EOL> from pyparsing import replaceWith <EOL> def remove_empty_statements ( string , seperator = '<STR_LIT:;>' ) : <EOL> """<STR_LIT>""" <EOL> if string == '<STR_LIT>' : <EOL> return string <EOL> empty_statement = seperator + OneOrMore ( seperator ) <EOL> empty_statement . setParseAction ( replaceWith ( seperator ) ) <EOL> string = empty_statement . transformString ( string ) <EOL> return string . lstrip ( seperator ) <EOL> def remove_comments ( string ) : <EOL> """<STR_LIT>""" <EOL> if string == '<STR_LIT>' : <EOL> return string <EOL> multiline_comment = nestedExpr ( '<STR_LIT>' , '<STR_LIT>' ) . suppress ( ) <EOL> string = multiline_comment . transformString ( string ) <EOL> singleline_comment = Literal ( '<STR_LIT>' ) + ZeroOrMore ( CharsNotIn ( '<STR_LIT:\n>' ) ) <EOL> string = singleline_comment . suppress ( ) . transformString ( string ) <EOL> return string <EOL> def remove_transactional ( string ) : <EOL> """<STR_LIT>""" <EOL> transaction = WordStart ( ) + ( <EOL> CaselessKeyword ( '<STR_LIT>' ) | CaselessKeyword ( '<STR_LIT>' ) ) <EOL> return transaction . suppress ( ) . transformString ( string ) <EOL> def split_statements ( string , seperator = '<STR_LIT:;>' , quote_char = "<STR_LIT:'>" ) : <EOL> """<STR_LIT>""" <EOL> if string == '<STR_LIT>' : <EOL> return [ ] <EOL> stack = <NUM_LIT:0> <EOL> result = [ ] <EOL> statement = '<STR_LIT>' <EOL> for char in string : <EOL> if char == seperator and not stack % <NUM_LIT:2> : <EOL> result . append ( statement . strip ( ) ) <EOL> statement = '<STR_LIT>' <EOL> else : <EOL> statement += char <EOL> if char == quote_char : <EOL> stack += <NUM_LIT:1> <EOL> if statement . strip ( ) : <EOL> result . append ( statement . strip ( ) ) <EOL> return result <EOL> def remove_newlines ( string ) : <EOL> """<STR_LIT>""" <EOL> regex = r"<STR_LIT>" <EOL> return '<STR_LIT:U+0020>' . join ( re . findall ( regex , string ) ) </s>
