summaryrefslogtreecommitdiff
path: root/ipl/procs/stripcom.icn
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
committerIgor Pashev <pashev.igor@gmail.com>2013-01-27 23:51:56 +0000
commit6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1 (patch)
tree926065cf45450116098db664e3c61dced9e1f21a /ipl/procs/stripcom.icn
downloadicon-6ab0c0f5bf14ed9c15370407b9ee7e0b4b089ae1.tar.gz
Initial upstream version 9.4.3upstream/9.4.3
Diffstat (limited to 'ipl/procs/stripcom.icn')
-rw-r--r--ipl/procs/stripcom.icn71
1 files changed, 71 insertions, 0 deletions
diff --git a/ipl/procs/stripcom.icn b/ipl/procs/stripcom.icn
new file mode 100644
index 0000000..a9fa89f
--- /dev/null
+++ b/ipl/procs/stripcom.icn
@@ -0,0 +1,71 @@
+############################################################################
+#
+# File: stripcom.icn
+#
+# Subject: Procedures to strip comments from Icon line
+#
+# Author: Richard L. Goerwitz
+#
+# Date: March 3, 1996
+#
+############################################################################
+#
+# This file is in the public domain.
+#
+############################################################################
+#
+# Version: 1.5
+#
+############################################################################
+#
+# 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