[antlr-interest] Mismatched input, expecting set null error

Nathan Eloe powerofazure at gmail.com
Wed Jun 9 13:21:01 PDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all,
I have a question about the "Mismatched input 'foo' expecting set null" error.

Here are the relevant parts of the grammar I am working on:

for_expr:	for_t space name (wspace in_t space word)? semiel do_t wspace list semiel done_t -> ^(for_t name (word)? list);
space	:	BLANK;
wspace	:	BLANK | EOL;
name	:	FILEPATH;
semiel	:	BLANK? (';' | EOL) BLANK?;

for_t	:	'for';
in_t	:	'in';
do_t	:	'do';
done_t	:	'done';
word	:	command_sub;

BLANK	:	(' '|'\t')+;
EOL	:	('\r'?'\n') ;

fragment
FILENAME:	'"'(ALPHANUM|'.'|'-'|'_')(ALPHANUM|'.'|' '|'-'|'_')*'"'
	|	(ALPHANUM|'.'|'-'|'_')(ALPHANUM|'.'|'-'|'_')*;
FILEPATH:	'/'?FILENAME('/'FILENAME)*;

I'm testing my grammar with gunit, and I'm using the following input:

"for asdf; do
time cat; done" -> (for asdf (cat time))

This succeeds and does not fail the unit test.  However, if I give it the input

"for asdf; do
time cat
done" -> (for asdf (cat time))

I get the error:

test1 (for_expr, line4) - 
expected: (for asdf (cat time))
actual: line 3:0 mismatched input 'done' expecting set null

The debugger in ANTLRworks allows this input (I copied and pasted from the gunit file to the debugger input window) and shows the correct abstract syntax tree.  Everything  I've been able to find on the list so far has boiled down to white space which I've checked repeatedly.  What I cannot figure out is why changing the one character makes a difference.

Is there something obvious that I am doing wrong?  I'm still fairly new to ANTLR, and this is a very ambitious project, so any help would be greatly appreciated.

Thanks,
Nathan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)

iEYEARECAAYFAkwP97EACgkQFpoRlVgtqKavdgCfWgzlGBMHz0rguJLd4PRt9vyH
r5UAn3RC8oSjERRkO0kwhK6hkCowFrUW
=bLYD
-----END PGP SIGNATURE-----


More information about the antlr-interest mailing list