From d33b8db415f2f6a8aa0a830a3f5186c1826d66cc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 30 Jul 2003 19:39:36 +0000 Subject: Directly support C style comments in tblgen, but allow them to actually nest git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7429 91177308-0d34-0410-b5e6-96231b3b80d8 --- support/tools/TableGen/FileLexer.l | 13 +++++++++++++ utils/TableGen/FileLexer.l | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/support/tools/TableGen/FileLexer.l b/support/tools/TableGen/FileLexer.l index c7e4346..7289ca0 100644 --- a/support/tools/TableGen/FileLexer.l +++ b/support/tools/TableGen/FileLexer.l @@ -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++; } +[^*/]* /* eat anything that's not a '*' or '/' */ +"*"+[^*/]* /* eat up '*'s not followed by '/'s */ +"/*" { ++CommentDepth; } +"/"+[^*]* /* eat up /'s not followed by *'s */ +"*"+"/" { if (!--CommentDepth) { BEGIN(INITIAL); } } +<> { fprintf(stderr, "Unterminated comment!\n"); abort(); } + %% diff --git a/utils/TableGen/FileLexer.l b/utils/TableGen/FileLexer.l index c7e4346..7289ca0 100644 --- a/utils/TableGen/FileLexer.l +++ b/utils/TableGen/FileLexer.l @@ -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++; } +[^*/]* /* eat anything that's not a '*' or '/' */ +"*"+[^*/]* /* eat up '*'s not followed by '/'s */ +"/*" { ++CommentDepth; } +"/"+[^*]* /* eat up /'s not followed by *'s */ +"*"+"/" { if (!--CommentDepth) { BEGIN(INITIAL); } } +<> { fprintf(stderr, "Unterminated comment!\n"); abort(); } + %% -- cgit v1.1