File: JavaFilter.py

package info (click to toggle)
synopsis 0.8.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,112 kB
  • ctags: 12,996
  • sloc: cpp: 34,254; ansic: 33,620; python: 10,975; sh: 7,261; xml: 6,369; makefile: 773; asm: 445
file content (45 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# Copyright (C) 2005 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

from Synopsis import AST
from Filter import Filter

import re

class JavaFilter(Filter):
    """A class that formats java /** style comments"""

    __re_java = r"/\*\*[ \t]*(?P<text>.*)(?P<lines>(\n[ \t]*\*.*)*?)(\n[ \t]*)?\*/"
    __re_line = r"\n[ \t]*\*[ \t]*(?P<text>.*)"

    def __init__(self):
        "Compiles the regular expressions"

        self.re_java = re.compile(JavaFilter.__re_java)
        self.re_line = re.compile(JavaFilter.__re_line)

    def filter_comment(self, comment):
      """Finds comments in the java format. The format is  /** ... */, and
      it has to cater for all four line forms: "/** ...", " * ...", " */" and
      the one-line "/** ... */".
      """

      text = comment.text()
      text_list = []
      mo = self.re_java.search(text)
      while mo:
         text_list.append(mo.group('text'))
         lines = mo.group('lines')
         if lines:
            mol = self.re_line.search(lines)
            while mol:
               text_list.append(mol.group('text'))
               mol = self.re_line.search(lines, mol.end())
         mo = self.re_java.search(text, mo.end())
      text = '\n'.join(text_list)
      comment.set_text(text)