Directly support C style comments in tblgen, but allow them to actually nest
authorChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 19:39:36 +0000 (19:39 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 19:39:36 +0000 (19:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7429 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/FileLexer.l
utils/TableGen/FileLexer.l

index c7e4346c0feeed8da9a8665536476b681b572f80..7289ca0bbba1bafa42e8fa84787f7a8179fb775a 100644 (file)
@@ -16,6 +16,7 @@
 %option noreject
 %option noyymore
 
+%x comment
 
 %{
 #include "Record.h"
@@ -29,6 +30,8 @@ static int ParseInt(const char *Str) {
   return strtol(Str, 0, 0); 
 }
 
+static int CommentDepth = 0;
+
 %}
 
 Comment     \/\/.*
@@ -63,4 +66,14 @@ in             { return IN; }
 
 [ \t\n]+       { /* Ignore whitespace */ }
 .              { return Filetext[0]; }
+
+
+"/*"                    { BEGIN(comment); CommentDepth++; }
+<comment>[^*/]*         /* eat anything that's not a '*' or '/' */
+<comment>"*"+[^*/]*     /* eat up '*'s not followed by '/'s */
+<comment>"/*"           { ++CommentDepth; }
+<comment>"/"+[^*]*      /* eat up /'s not followed by *'s */
+<comment>"*"+"/"        { if (!--CommentDepth) { BEGIN(INITIAL); } }
+<comment><<EOF>>        { fprintf(stderr, "Unterminated comment!\n"); abort(); }
+
 %%
index c7e4346c0feeed8da9a8665536476b681b572f80..7289ca0bbba1bafa42e8fa84787f7a8179fb775a 100644 (file)
@@ -16,6 +16,7 @@
 %option noreject
 %option noyymore
 
+%x comment
 
 %{
 #include "Record.h"
@@ -29,6 +30,8 @@ static int ParseInt(const char *Str) {
   return strtol(Str, 0, 0); 
 }
 
+static int CommentDepth = 0;
+
 %}
 
 Comment     \/\/.*
@@ -63,4 +66,14 @@ in             { return IN; }
 
 [ \t\n]+       { /* Ignore whitespace */ }
 .              { return Filetext[0]; }
+
+
+"/*"                    { BEGIN(comment); CommentDepth++; }
+<comment>[^*/]*         /* eat anything that's not a '*' or '/' */
+<comment>"*"+[^*/]*     /* eat up '*'s not followed by '/'s */
+<comment>"/*"           { ++CommentDepth; }
+<comment>"/"+[^*]*      /* eat up /'s not followed by *'s */
+<comment>"*"+"/"        { if (!--CommentDepth) { BEGIN(INITIAL); } }
+<comment><<EOF>>        { fprintf(stderr, "Unterminated comment!\n"); abort(); }
+
 %%