Filename in ErrorMessage after precompiling
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tob_Lin
Posted On:   Tuesday, December 4, 2001 12:35 PM

First, I wont generate cpp code with antlr. After I send the inputfile to precompiler like cpp i get a document with lines like this: #line 1 "includeTest2.txt" now I wont parse this document and save the information for a better errormassage with the lexer rule like this: PREPROZLINE : "#line " i:NUMBER ' ' s:STRING_LITERAL (" "|' '|' ') { setFilename(s->getText()); setLine(i->getText()); _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; } ; first question: is Inputstate place to store the filename or is t   More>>

First, I wont generate cpp code with antlr.


After I send the inputfile to precompiler like cpp i get a document with lines like this:


#line 1 "includeTest2.txt"



now I wont parse this document and save the information for a better errormassage with the lexer rule like this:


			
PREPROZLINE
: "#line " i:NUMBER ' ' s:STRING_LITERAL ("
"|'
'|'
')
{
setFilename(s->getText());
setLine(i->getText());
_ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP;
}
;


first question:

is Inputstate place to store the filename or is this used by antlr for other things.

second question:

how can I get the filename in the errormassage, like:



			Error: filename(includeTest2.txt), line(5), expecting ID, found ';'
			
   <<Less

Re: Filename in ErrorMessage after precompiling

Posted By:   Terence_Parr  
Posted On:   Thursday, December 20, 2001 11:37 AM

there should be a set filename method somewhere if I remember properly. I wouldn't rely on InputState remaining the same in future versions.

Re: Filename in ErrorMessage after precompiling

Posted By:   Tob_Lin  
Posted On:   Wednesday, December 5, 2001 06:49 AM

I'm again. I saw in source code of RecognitionException, that the default errormassage (toString()) was build with a filename, if there one. but this filename is not pass by the Lexer to the Parser and the Parser can only have one filename per Lexer, isn't it? The problem seams to be, that the Lexer save only the linenummber in a Token, but not the filename.

Is there a way, to tell ANTLR to store the filename also in Tokens and use this in the Exceptions or have I to write my own LexerClass, own TokenClass and my own ParserClasses?
About | Sitemap | Contact