def compile_rules(environment):
 e = re.escape
 rules = [(len(environment.comment_start_string), 'comment', e(environment.comment_start_string)), (len(environment.block_start_string), 'block', e(environment.block_start_string)), (len(environment.variable_start_string), 'variable', e(environment.variable_start_string))]
 if (environment.line_statement_prefix is not None):
  rules.append((len(environment.line_statement_prefix), 'linestatement', ('^[ \\t\\v]*' + e(environment.line_statement_prefix))))
 if (environment.line_comment_prefix is not None):
  rules.append((len(environment.line_comment_prefix), 'linecomment', ('(?:^|(?<=\\S))[^\\S\\r\\n]*' + e(environment.line_comment_prefix))))
 return [x[1:] for x in sorted(rules, reverse=True)]

def compile_rules ( environment ) : e = re . escape rules = [ ( len ( environment . comment_start_string ) , 'comment' , e ( environment . comment_start_string ) ) , ( len ( environment . block_start_string ) , 'block' , e ( environment . block_start_string ) ) , ( len ( environment . variable_start_string ) , 'variable' , e ( environment . variable_start_string ) ) ] if ( environment . line_statement_prefix is not None ) : rules . append ( ( len ( environment . line_statement_prefix ) , 'linestatement' , ( '^[ \\t\\v]*' + e ( environment . line_statement_prefix ) ) ) ) if ( environment . line_comment_prefix is not None ) : rules . append ( ( len ( environment . line_comment_prefix ) , 'linecomment' , ( '(?:^|(?<=\\S))[^\\S\\r\\n]*' + e ( environment . line_comment_prefix ) ) ) ) return [ x [ 1 : ] for x in sorted ( rules , reverse = True ) ]
compiles all the rules from the environment into a list of rules .