[GRASS-dev] DBMI parse error question

Markus Neteler neteler at itc.it
Wed Feb 28 02:32:23 EST 2007


On Wed, Feb 28, 2007 at 07:15:47AM +0000, Glynn Clements wrote:
> Markus Neteler wrote:
...
> > Any ideas?
> 
> As Hamish points out, it's "ora time" ("time" isn't a valid type for the
> DBF driver).

I have added support for "time" now.
 
> > Of course it would be fancy to have a more reasonable
> > error message. This error uses to pop up if preserved words are used
> > as column names, but I don't see any (even, it should tell me in an
> > ideal world).
> 
> Try defining YYERROR_VERBOSE in yac.y, i.e.:
> 
> --- lib/db/sqlp/yac.y	5 Feb 2007 10:45:38 -0000	1.25
> +++ lib/db/sqlp/yac.y	28 Feb 2007 06:46:04 -0000
> @@ -25,6 +25,7 @@
>  #include <grass/sqlp.h>
>  
>  #define YYDEBUG 1
> +#define YYERROR_VERBOSE 1
>  
>  %}
> 
> This should give error messages of the form "unexpected X, expecting Y",
> where X and Y are the terminal (token) names used in the grammar.
> 
> [Except that db.execute completely ignores the error message returned by
> the parser in sqlpStmt->errmsg. Actually, AFAICT, it's the DBF driver
> which completely ignores the error message ("grep errmsg *" in
> db/drivers/dbf comes up blank).]

I see - but I have no clue how to implement that.

> That's still not ideal, as the error messages won't identify the
> specific value; e.g. for the above case, you just get "unexpected NAME".
> 
> If you want more detailed error messages, you have to add explicit rules
> which match each erroneous case and use YYERROR to flag an error, e.g.:
> 
> y_columndef:
> 		NAME VARCHAR '(' INTNUM ')'	{ sqpColumnDef( $1, SQLP_VARCHAR, $4, 0 ); }
> 	|	NAME INT 			{ sqpColumnDef( $1, SQLP_INTEGER,  0, 0 ); }
> 	|	NAME INTEGER 			{ sqpColumnDef( $1, SQLP_INTEGER,  0, 0 ); }
> 	|	NAME DOUBLE			{ sqpColumnDef( $1, SQLP_DOUBLE,   0, 0 ); }
> 	|	NAME DOUBLE PRECISION		{ sqpColumnDef( $1, SQLP_DOUBLE,   0, 0 ); }
> 	|	NAME DATE			{ sqpColumnDef( $1, SQLP_DATE,     0, 0 ); }
> +	|	NAME NAME	{
> +					char buff[1000];
> +					sprintf(buf, "%s: invalid type: %s", $1, $2);
> +					yyerror(buf);
> +					YYERROR;
> +				}
> 	;

> Adding the above to yac.y (and hacking yyerror() to actually print the
> error rather than just return it so that the driver can ignore it)
> results in "ora: invalid type: time".

This would be perfect. I implemented locally you suggestion but the DBF
driver remains silent 8due to above indicated problem which I don't know
how to solve).

> The problem here is that you essentially need to enumerate all of the
> different syntax errors which you want to catch. You also need to ensure
> that you don't make a rule too broad and end up treating valid
> statements as syntax errors.

This is not fully clear to me.

I better to try to add better error testing to not break
it completely.

Markus




More information about the grass-dev mailing list