help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CSV Parser - Empty values


From: John
Subject: Re: CSV Parser - Empty values
Date: Wed, 19 Feb 2003 13:05:37 -0500 (EST)

> one,two,,,three,four,"data,with comma"
>
> I wish to return an EMPTYDATA_TOK if an empty value is
> encountered (2 commas without any data in between)
>

The most elegant solution is for this scanner to return more than one
token (EMPTYDATA_TOK followed by DELIMETER_TOK).  This could easily be
done if flex had a token buffer. Then the rule's action would look
like this:

,,+    {  for(i=0; i < yyleng-1; i++){
             pushback(DELIMETER_TOK);
             pushback(EMPTYDATA_TOK);
                  }
                  pushback(DELIMETER_TOK);
                  RETURN;
           }

Where RETURN pops the token buffer and returns the token.  Subsequent
calls to yylex would pop the token buffer until it is empty.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]