Ejemplo n.º 1
0
    def parse(self, filename):
        # some counter
        self.d = {
                'line_count' : 0,
                'comments' : 0,
                'empty' : 0,
                'libido' : 0,
                }
        # reset
        self.line = []


        #open file in reading mode unicode
        f = open(filename, 'rU')
        # reading file (line by line)
        n = 0
        for line in f:
            n += 1
            self.d['line_count'] += 1
            m = REMatcher(line.rstrip('\n'))
            self.lines.append(line)

            if m.match(r'libido:'):
                self.d['libido'] += 1
            if m.match(r'^\s*#'):
                self.d['comments'] += 1
            elif m.match(r'^\s*$'):
                self.d['empty'] += 1

        f.close()

        return self.d
Ejemplo n.º 2
0
def test_REMatcher():
    l = 'some string'

    m = REMatcher(l)
    assert m.match(r'(some)')
    assert m.group(1) == 'some'

    assert m.all() == ('some',)
Ejemplo n.º 3
0
    def parse(self, filename):
        self.init_parser()

        #open file in reading mode unicode
        f = open(filename, 'rU')
        func_name = None
        for line in f:
            self.n += 1
            self.d['line_count'] += 1
            m = REMatcher(line.rstrip('\n'))
            # line are stored with their \n
            self.lines.append(line)

            # match a libido tag
            if m.match(r'libido:'):
                self.d['libido'] += 1
                self.libido_parser.analyze_line(self, m)

            if m.match(r'^\s*#'):
                self.d['comments'] += 1
            elif m.match(r'^\s*$'):
                self.d['empty'] += 1
            elif m.match(r'^(function)?\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\(\)'):
                self.d['function'] += 1
                func_name = m.group(2)
                self.chunks[func_name] = { 'start' : self.n }
            elif m.match(r'^\}') and func_name:
                self.chunks[func_name]['end'] = self.n
                func_name = None

        f.close()

        return self.d
Ejemplo n.º 4
0
    def parse(self, filename):
        #open file in reading mode unicode
        f = open(filename, 'rU')
        # some counter
        self.d = {
                'line_count' : 0,
                'libido' : 0,
                }

        # reading file (line by line)
        n = 0
        for line in f:
            n += 1
            self.d['line_count'] += 1
            m = REMatcher(line.rstrip('\n'))
            self.lines.append(line)

            if m.match(self.open_marker):
                self.d['libido'] += 1

                p = self.tokenize(m)

                if p:
                    if p.action == 'assign':
                        self.assign(p.var, p.args)
                    elif p.action == 'expand':
                        self.add_expansion(n, p.args)
                    elif p.action == 'depend':
                        # in specific parser? ex: bash
                        printerr('parse:%d:dependencies found %s ??' % (n, line.rstrip()))
                        pass
                else:
                    printerr('parsre error:%d:%s' % (n, line.rstrip()))

        f.close()
        return self.d