[antlr-interest] Re: Why No Error?
genericised
trigonometric at softhome.net
Thu Aug 15 08:40:06 PDT 2002
well the lexer is defined like this now:
class CSVLexer extends Lexer;
options { charVocabulary='\3'..'\377'; }
RECORD : '"'! (~(','|'\r'|'\n'))+ ;
COMMA : ',' ;
NEWLINE : ('\r''\n')=> '\r''\n' //DOS
| '\r' //MAC
| '\n' //UNIX
{ newline(); }
;
WS : (' '|'\t') { $setType(Token.SKIP); } ;
So data is expected to be like:
"a, "b, "blah
"hei, "fhei, "fhih,
so
a, b, c
a, , ,
would produce an error because it is
not the correct format anyway, if converted
to the correct format:
"a, "b, "c
"a, ", ",
this would also create an error because a
record must contain at least one character
"a, "b, "c
"a, " , " ,
would produce no error. Note that this is
behaving exactly as it should.
Davy Cricket
--- In antlr-interest at y..., Bogdan Mitu <bogdan_mt at y...> wrote:
> > ...
> > is there anything actually WRONG with me using:
> >
> > class CSVParser extends Parser;
> > file : (line)+ ;
> > line : (record)+ (NEWLINE|EOF);
> > record : (r:RECORD) (COMMA)? ;
> >
> > I would have thought that if EOF is actually matched
> > then this is a perfectly viable way of matching the
> > whole file. In fact, IF the EOF IS matched then I see
> > no reason NOT to use this way.
>
> Should parse OK correct input. But I'm afraid it will also parse
incorrect
> input without producing any error.
>
> For instance, try an input like:
>
> a, b, c
> a, , ,
>
> which I think it's incorrect. I didn't test, but I expect that the
parser
> will stop after the first line, without any warning or error.
>
> Let me know how it works.
>
> Cheers,
> Bogdan
>
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
> >
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> HotJobs - Search Thousands of New Jobs
> http://www.hotjobs.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list