The regexp was too greedy and treated /* ... */ ... /* ... */ as
a single long comment. Luckily, others have already solved that
braintwister for us. This is the solution by Stephen Ostermiller.
---
src/compiler/scanner.re | 7 ++++++-
src/compiler/test/comment | 11 +++++++++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/src/compiler/scanner.re b/src/compiler/scanner.re
index 9056334..9db941d 100644
--- a/src/compiler/scanner.re
+++ b/src/compiler/scanner.re
@@ -61,6 +61,11 @@ static int nls(const unsigned char *s, const unsigned char
*end)
return n;
}
+/*
+ * Regular expression for C-style comments by Stephen Ostermiller, from
+ * http://ostermiller.org/findcomment.html
+ */
+
int scan(struct scanner *s)
{
std:
@@ -73,7 +78,7 @@ int scan(struct scanner *s)
goto std; }
"//"[^\n\x00]* { goto std; }
- "/*"("*"*[^/\x00]|[^*\x00])*"*"+"/"
+ "/*"([^*\x00]|("*"+([^*/\x00])))*"*"+"/"
{ s->lineno += nls(s->old_cursor,
s->cursor);
goto std; }
diff --git a/src/compiler/test/comment b/src/compiler/test/comment
index 3aeadc0..916ccb5 100755
--- a/src/compiler/test/comment
+++ b/src/compiler/test/comment
@@ -133,4 +133,15 @@ expect <<EOF
FPVM, line 1, near "*": parse error
EOF
+#------------------------------------------------------------------------------
+
+ptest "comment: multiple /*...*/ comments" <<EOF
+/* */ a /* */
+/***/ = /**/
+/**/ b /* */
+EOF
+expect <<EOF
+a = b
+EOF
+
###############################################################################
--
1.7.1
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode