CComment

Bernhard Fischer <[email protected]>
Newsgroups gmane.comp.documentation.synopsis
Message-ID <[email protected]>
On Sun, Feb 20, 2005 at 01:56:05PM +0100, Bernhard Fischer wrote:
>On Sat, Feb 19, 2005 at 08:05:59PM -0500, Stefan Seefeld wrote:
>>Bernhard Fischer wrote:
>>>Hi Stefan,
>>>
[snip]
>>to check in a new python frontend that calls the Cxx parser in C mode
>>and as soon as that is confirmed to work retire the ctool backend.
>>Let me know if you are interested in testing it, or want to help in
>>other ways.
>
>Yes, i'm interrested in testing it.
>Currently i am perusing linux/drivers/infiniband/ulp/sdp as my primary
>testcase (available in recent kernels).
>Another testcase is here: http://members.aon.at/berny_f/synopsis/
>>
>>>Attached is a quick C style comment parser. Before applying it, one
>>>should make the intermittent asterisk optional, though.....
>>
>>That looks good !
>>You are right about the asterisk. In fact, I would add the restriction
>>that the asterisks have to be aligned, i.e.
>>
>>/*
>> * ...
>> */
>>
>>would count, but
>>
>>/* comment showing that
>>   *foobar is the dereferenced foobar.
>>*/
>>
>>would not. The asterisk being optional should be expressed using
>
>Indeed.

Attached is a revised patch to add CComment which handles the tiny
testcase (http://members.aon.at/berny_f/synopsis/) proper for me.
>
>>the usual 'Parameter' idiom used everywhere else in the synopsis
>>frontend.
>
>Ok, i'll try to use that.

>From a short glance, i don't quite see how i'd do that. Could you
elaborate or point me to an example, please?

>
>>Would you mind adjusting your patch ?

I've got a question regarding the implementation of CPrevious.
Previous is recognized by means of the '<' character at pos 0 in the
comment text. CPrevious OTOH does not have the '<' character but rather
is a comment which is positioned after some code (See struct bar in
foo.h contained in the tiny testcase referenced above).

Would i implement CPrevious via
o putting a '<' into the comment when CComment finds code before the
  comment? This may be considered a rough hack but may allow me to
  simply reuse Previous instead of introducing a new CPrevious..
o matching only ^/[\*]+... as CComment and introducing a CPrevious which
  associates ^(^/[\*]+)... to the respective code.

_______________________________________________
Synopsis-devel mailing list
[email protected]
http://lists.fresco.org/cgi-bin/listinfo/synopsis-devel
add-CComment.sre-02.diff (text/plain, 2 KB)
diff -X /usr/src/cvs/excl -rdup Synopsis.oorig/Synopsis/Processors/Comments/Comments.py Synopsis/Synopsis/Processors/Comments/Comments.py
--- Synopsis.oorig/Synopsis/Processors/Comments/Comments.py	2004-11-18 16:34:16.000000000 +0100
+++ Synopsis/Synopsis/Processors/Comments/Comments.py	2005-03-01 14:34:15.000000000 +0100
@@ -84,6 +84,49 @@ class SSDComments(CommentProcessor):
 
       return string.join(self.re_ssd.findall(str),'\n')
 
+class CComments (CommentProcessor):
+   """A class that formats C /* */ style comments"""
+
+   __re_c = r"/[\*]+[ \t]*(?P<text>.*)(?P<lines>(\n[ \t]*.*)*?)(\n[ \t]*)?[\*]+/"
+   # match lines with and without asterisk.
+   # preserve space after asterisk so empty lines are formatted correctly.
+   __re_line = r"\n[ \t]*([ \t]*[\*]+(?=[ \t\n]))*(?P<text>.*)"
+
+   def __init__(self):
+      "Compiles the regular expressions"
+
+      if self.debug:
+          print 'CComment Processor requested.\n'
+      self.re_c = re.compile(CComments.__re_c)
+      self.re_line = re.compile(CComments.__re_line)
+
+   def visit_comments(self, decl):
+      "Calls process_comment on all comments"
+
+      map(self.process_comment, decl.comments())
+
+   def process_comment(self, comment):
+      """Finds comments in the C format. The format is  /* ... */.
+      It has to cater for all five line forms: "/* ...", " * ...", " ...",
+      " */" and the one-line "/* ... */".
+      """
+
+      text = comment.text()
+      text_list = []
+      mo = self.re_c.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_c.search(text, mo.end())
+      text = string.join(text_list,'\n')
+      comment.set_text(text)
+
+
 class JavaComments (CommentProcessor):
    """A class that formats java /** style comments"""
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.