home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
STRIPCOM.ICN
< prev
next >
Wrap
Text File
|
1991-07-13
|
2KB
|
66 lines
############################################################################
#
# Name: stripcom.icn
#
# Title: Strip out comments from a line of Icon code
#
# Author: Richard L. Goerwitz
#
# Date: June 3, 1991
#
# Version: 1.4
#
############################################################################
#
# Strip commented-out portion of a line of Icon code. Fails on lines
# which, either stripped or otherwise, come out as an empty string.
#
############################################################################
#
# BUGS: Can't handle lines ending in an underscore as part of a
# broken string literal, since stripcom is not intended to be used
# on sequentially read files. It simply removes comments from indi-
# vidual lines.
#
############################################################################
# To preserve parallelism between file and procedure names.
procedure stripcom(s)
return strip_comments(s)
end
# The original name -
procedure strip_comments(s)
local i, j, c, c2, s2
s ? {
tab(many(' \t'))
pos(0) & fail
find("#") | (return trim(tab(0),' \t'))
match("#") & fail
(s2 <- tab(find("#"))) ? {
c2 := &null
while tab(upto('\\"\'')) do {
case c := move(1) of {
"\\" : {
if match("^")
then move(2)
else move(1)
}
default: {
if \c2
then (c == c2, c2 := &null)
else c2 := c
}
}
}
/c2
}
return "" ~== trim((\s2 | tab(0)) \ 1, ' \t')
}
end