parsing comments in scripts
Robert Brenstein
rjb at rz.uni-potsdam.de
Fri Dec 10 08:22:49 EST 2004
>#comment
>text --comment
>text "more text -- still more"
>text "more text" --comment
>text "more text" text "-- text"
>text "more text" text "still more" --comment
>(did I leave any out)
plenty :) although it may be that only MetaCard allows to use both
quoting modes.
from the above set
text "more text -- still more" --comment
same with hash
text #comment
text "more text # still more"
text "more text" #comment
text "more text" text "# text"
text "more text" text "still more" #comment
text "more text # still more" #comment
mixed instances
text "more text # still more" --comment
text "more text -- still more" #comment
I also use the following combinations to mark debugging code
text "text" -- #comment
text "text" #-- comment
You could also consider other combo cases
text "more text --- still more" #comment
text "more text -- still more -- still more" #comment
text "more text -- # -- still more" #comment
text "more text ### still more" #comment
In these cases it matters whether you first check for # or -- so you
should really check both cases and see which has has lower offset.
In general, I think you need to use the offset function for each line
and check for either -- or # and count whether there is an even
number of double-quotes before it (setting for example itemdelim to
quote and get the item count). If count is odd, you are within
literal and should continue. If count is even, then you hit a
beginning of comment. I think this approach will work with all cases.
Robert Brenstein
More information about the use-livecode
mailing list