[antlr-interest] Parsing line by line and multiline comments

forumer at smartmobili.com forumer at smartmobili.com
Thu Apr 12 05:48:16 PDT 2012


I also tried to define a ANYCHAR rule like this :

ANYCHAR
     :   .
     ;

and in the mTokens() lexer methods I tried to eat the token when I am 
inside a block comment :


public override void mTokens()
{
	...

         // 9 corresponds to END_BLOCK_COMMENT (*/)
         if (InBlockComment && alt34 != 9)
         {
             mANYCHAR(); if (state.failed) return;
         }
         ...
}

but I get an exception inside WS rule :

if ((input.LA(1)>='\t' && input.LA(1)<='\n')||(input.LA(1)>='\f' && 
input.LA(1)<='\r')||input.LA(1)==' ')
			{
				input.Consume();
			state.failed=false;
			}
			else
			{
				if (state.backtracking>0) {state.failed=true; return;}
				MismatchedSetException mse = new 
MismatchedSetException(null,input);
				DebugRecognitionException(mse);
				Recover(mse);
				throw mse;
			}


So I suppose this is not so easy to hack the lexer.
What is the right approach for this problem ?


More information about the antlr-interest mailing list