File: Qtdoc.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 (56 lines) | stat: -rw-r--r-- 2,009 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
46
47
48
49
50
51
52
53
54
55
56
#
# Copyright (C) 2000 Stephen Davies
# Copyright (C) 2000 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

from Javadoc import Javadoc

class Qtdoc(Javadoc):
   """A formatter that uses Qt-style doc tags."""

   _re_see = '@see (([A-Za-z+]+)/)?(([A-Za-z_]+\.?)+)'
   _re_tags = r'((?P<text>.*?)\n)?[ \t]*(?P<tags>\\[a-zA-Z]+[ \t]+.*)'
   _re_seealso = '[ \t]*(,|and|,[ \t]*and)[ \t]*'

   def __init__(self):
      Javadoc.__init__(self)
      self.re_seealso = re.compile(self._re_seealso)

   def parse_text(self, str, decl):

      if str is None: return str
      #str, see = self.extract(self.re_see_line, str)
      see_tags, param_tags, return_tag = [], [], None
      joiner = lambda x,y: len(y) and y[0]=='\\' and x+[y] or x[:-1]+[x[-1]+y]
      str, tags = self.parse_tags(str, joiner)
      # Parse each of the tags
      for line in tags:
         tag, rest = string.split(line,' ',1)
         if tag == '\\sa':
            see_tags.extend(map(lambda x: [x,''], self.re_seealso.split(rest)))
         elif tag == '\\param':
            param_tags.append(string.split(rest,' ',1))
         elif tag == '\\return':
            return_tag = rest
         else:
            # Warning: unknown tag
            pass
      return "%s%s%s%s"%(self.parse_see(str, decl),
                         self.format_params(param_tags),
                         self.format_return(return_tag),
                         self.format_see(see_tags, decl))

   def format_see(self, see_tags, decl):
      """Formats a list of (ref,description) tags"""

      if not len(see_tags): return ''
      seestr = div('tag-see-header', "See Also:")
      seelist = []
      for see in see_tags:
         ref,desc = see[0], len(see)>1 and see[1] or ''
         tag = self.re_seealso.match(ref) and ' %s '%ref or self.find_link(ref, decl)
         seelist.append(span('tag-see', tag+desc))
      return seestr + string.join(seelist,'')