>From d089856a5b473fd3806ec226f707bb1985bb22aa Mon Sep 17 00:00:00 2001
From: Jochen Keil <jochen.keil@emlix.com>
Date: Fri, 29 Jan 2010 13:46:53 +0100
Subject: [PATCH 5/9] consume whole content of a proc declaration
 replace it with {}
 this is done by counting '{' and '}'. we start with an open bracket and
 increase the counter for every subsequent open bracket whereas for every
 close bracket we'll decrease the count by one.
 when the counter is one again we have reached the closing bracket of the
 proc and we can start from initial again.
 this ensures that anything inside of a proc won't confuse the rest of
 the lexer.

---
 tcl-dox.l |   36 ++++++++++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/tcl-dox.l b/tcl-dox.l
index ee254a0..21afca5 100644
--- a/tcl-dox.l
+++ b/tcl-dox.l
@@ -28,6 +28,11 @@ int g_firstArg;
 int g_oarg;
 
 /**
+ * count brackets inside of proc statements so the function body can be
+ * ignored and won't confuse the lexer with keywords */
+int g_bcount = 1;
+
+/**
  * Keeps track of the current class name.  This is needed for correct
  * output of constructors and destructors using C++ syntax.
  */
@@ -57,7 +62,7 @@ void handleArgumentComma();
 
 %option nounput 
 
-%x CBLOCK CLASS PROC PROC_OPEN PROC_ARGS OPTIONAL_ARG 
+%x CBLOCK CLASS PROC PROC_OPEN PROC_ARGS PROC_EAT OPTIONAL_ARG
 %x VAR CLASS_INH INH NAMESPACE UNSUPPORTED_CMD PACKAGE EXEC
 
 ID    [[:alpha:]_]+[[:alnum:]_]*
@@ -290,8 +295,8 @@ WS    [ \t]
 
 <PROC_ARGS>{
    \} {
-      fprintf(yyout, "%s", ")");
-      BEGIN(INITIAL);
+      fprintf(yyout, "%s\n%s", ")", "{");
+      BEGIN(PROC_EAT);
    }
 
    {ID} {
@@ -307,7 +312,30 @@ WS    [ \t]
    }
 }
 
-
+<PROC_EAT>{
+	.*\n {
+		do
+		{
+			switch (*yytext)
+			{
+				case '{':
+					g_bcount++;
+					break;
+				case '}':
+					g_bcount--;
+					break;
+			}
+			/*fprintf(stderr, "%s\t%i\n", yytext, * g_bcount);*/
+		} while (*(yytext++));
+
+		if (g_bcount == 1) {
+			fprintf(yyout, "%s\n", "}");
+			BEGIN(INITIAL);
+		} else {
+			BEGIN(PROC_EAT);
+		}
+	}
+}
 
 <CLASS>{
    {ID} {
-- 
1.6.6.1

