octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Block comments


From: John W. Eaton
Subject: Block comments
Date: Thu, 1 Jun 2006 09:30:37 -0400

On  1-Jun-2006, William Poetra Yoga Hadisoeseno wrote:

| Hi, I've (somewhat) implemented block comments (%{ and %}), but it's
| still very crude at the moment (look at the diff, it still has
| debugging features like printf and warning everywhere :p). The current
| problems are:
| 
| 1. the block comment start and ends are not stripped. So for example
| if I have a file a.m:
| 
| [...]
| 
| 2. The code looks ugly (lots of duplication of code)
| 
| 3. I don't know whether some block comments would be missed, or
| non-block comments would be identified as such, for example:

I think this discussion belongs on the maintainers list.  Please post
any replies there.

The page

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/edit_d14.html

says that block comments should nest.

I think completely separate code should be used for in-line and block
comments.  With flex, it might be easiest to handle block comments with
an exclusive start state.  To use this method, you'll probably need to
have patterns something like this:

  "%{"  -- begin BLOCK_COMMENT state, set block_comment nesting level
           to 1, save current start state (saved_start_state = YY_START).

  <BLOCK_COMMENT>"%{"  -- increment block_comment nesting level.

  <BLOCK_COMMENT>"%}"  -- decrement block_comment nesting level.  If
                          nesting level is 0, restore previous start
                          state (BEGIN (saved_start_state)).

  <BLOCK_COMMENT>\n    -- increment line counter

  <BLOCK_COMMENT>.     -- all other text in the comment (you might
                          also be able to match more than one
                          character at a time with regular expressions
                          if you are careful -- see the flex manual
                          for an example of handline C-style comments,
                          but note that C-style comments don't have to
                          nest).

In each of these, you'll need to save the comment in the comment
buffer and keep track of the column counter.

The only catch here is that there are a few places where comments are
already matched with regular expressions like "%.*\n", so those would
have to be modified as well.

Now that I see it is possible to save and restore start states by
using YY_START, perhaps the current comment-handling code could also
be simplified by using an exclusive start state.  So instead of trying
to handle comments directly in the <MATRIX> start state, we could
handle comments separately, but be sure to restore the previous start
state when the end of a comment is reached.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]