parsing comments in scripts

Ben Rubinstein benr_mc at cogapp.com
Wed Dec 15 05:11:19 EST 2004


Alex Tweedly wrote:
> If you want the editor to have an "uncomment the entire handler" command,
> then it's going to need to look into comments, to see whether or not
> removing the leading comment indicator would leave a line which could then
> be a start / finish of a handler. Doesn't seem too bad to me - but I know
> there were concerns about the interpreter (now the editor) looking at
> comments and guessing about their meaning.

Two possible solutions here (I didn't say either were pretty):

* 'Comment Handler' finds the start and end of the handler that the
insertion point lies in; and extends this range of lines to incorporate any
contiguous comment lines.  It then adds "-- " to the start of every line in
this range.  Hence:

    -- a comment about foo
    --
    on foo x
       -- put x into it
       get x
    end foo

becomes

    -- -- a comment about this
    -- --
    -- on foo x
    --    -- put x into it
    --    get x
    -- end foo

'Uncomment Handler' then takes the contiguous range of commented lines round
the insertion point, and removes the initial "-- " from each one - thus
restoring previous comments as they were.


* we've got range comments now, /* */.  So 'Comment Handler' could work like
this:

    -- a comment about foo
    --
    /* on foo x
       -- put x into it
       get x
    end foo */

Then 'Uncomment Handler' searches up and down from the insertion point for
some pretty easily recognised patterns: "/* on <label>" or "/* function
<label>" up, and "end <label> */" down.  If these don't match, or it finds
strange variants out of order, then it does the best it can or gives up and
leaves the user to figure it out.  (I don't know whether /* */ comments
nest; if not then Comment Handler should disable internal occurences, eg
changing to "/--*" and "*--/", and Uncomment Handler reverse this.)

Whatever, I do think the concept that 'junk' should be acceptable outside a
handler is a dangerous hangover, and should be abandoned.  I used to take
advantage of this in HyperCard too (I stored data in scripts, since they
were effectively the only properties available for all objects) but switched
with relief to using custom properties in MC/Rev.  Since there's now a real
issue (the fact that some statements from inside a 'commented' handler can
take effect outside the handler) and we have range comments anyway, the
worst that we're asking people to do, even if no additional conveniences are
provided in the script editor, is find the bottom of their handler to add
the close comment there.

How about we just request a simpler Script Editor enhancement - jump to end
of current handler?
 
  Ben Rubinstein               |  Email: benr_mc at cogapp.com
  Cognitive Applications Ltd   |  Phone: +44 (0)1273-821600
  http://www.cogapp.com        |  Fax  : +44 (0)1273-728866



More information about the use-livecode mailing list