Example #1
0
 def __init__(self, filename):
     from utils import Scanner
     fn = Settings.locate_file(filename)
     if os.path.exists(fn):
         f = open(fn)
         string = f.read()
         string.replace('\t', ' ')
         file_without_comment = Scanner.remove_comments(string)
         scanner = Scanner.Scanner(file_without_comment)
         scanner.next()
         self.rules = []
         self.functions = []
         self.function_map = {}
         self.parse_rules(scanner)
         f.close()
     else:
         logger.error("Cannot locate template file %s", filename)
Example #2
0
def parse_output(input_string):
    '''Utility function used within this file's classes. 

    :param input_string: None
    :type input_string: str
    '''
    from utils import Scanner
    output_scanner = Scanner.Scanner(input_string)
    output_scanner.next()
    words = []
    prevWasVariable = False
    while output_scanner.cur[0] != tokenize.ENDMARKER:
        if output_scanner.cur[0] == tokenize.NAME or output_scanner.cur[
                1] in u'-_ éèêàîï':
            words.append(output_scanner.cur[1])
            output_scanner.next()
            prevWasVariable = False
        elif output_scanner.cur[1] == u'$':
            variable = u'$'
            output_scanner.next()
            variable += output_scanner.cur[1]
            words.append(variable)
            output_scanner.next()
            prevWasVariable = True
        elif output_scanner.cur[1] == u'%':
            function = u'%'
            output_scanner.next()
            while output_scanner.cur[1] != u')':
                function += output_scanner.cur[1]
                output_scanner.next()
            function += output_scanner.cur[1]
            words.append(function)
            output_scanner.next()
            prevWasVariable = True
        else:
            if prevWasVariable:
                words.append(output_scanner.cur[1])
                output_scanner.next()
            else:
                words[-1] += output_scanner.cur[1]
                output_scanner.next()
            prevWasVariable = False
    return words