Re: Feedback on Editor's Draft.

Howard Katz wrote:
> Bryan,
> 
> It probably doesn't help you much, but I had problems with qnames in antlr
> as well in early versions of my XQuery query engine. I too hoisted QNAME
> into the parser trying to solve lexer difficulties, but if I recall
> correctly, that then allowed users to enter spaces between the prefix,
> colon, and localPart! I eventually gave up (for other reasons as well) and
> eventually moved to javacc. I'm happier now (at least my analyst tells me I
> should be).
> 
> You got me curious and I went looking for antlr/QNAME productions. I've been
> away from antlr so long that the following xquery.g file from eXist just
> looks like gobbledeegook to me now. If it's useful, more power to you:
> 
> qName returns [String name]
> {
> 	name= null;
> 	String name2;
> }
> :
> 	( ncnameOrKeyword COLON ncnameOrKeyword )
> 	=> name=nc1:ncnameOrKeyword COLON name2=ncnameOrKeyword
> 	{
> 		name= name + ':' + name2;
> 		#qName.copyLexInfo(#nc1);
> 	}
> 	|
> 	name=ncnameOrKeyword
> 	;
> 
> Howard
> 

I used the same mechanism (ANTLR calls it syntactic predicates, I think)  did 
much the same with my N3 grammar for Jena (which is in ANTLR).  This is a 
genralisation of what lex-class and javacc tokenizers do.

THING
: (NSNAME COLON LNAME)=> NSNAME COLON LNAME { ... }
| (COLON LNAME)=> COLON LNAME { ... }
| (NSNAME COLON )=> NSNAME COLON { ... }
| (COLON)=> COLON
etc etc

See http://www.antlr.org/doc/lexer.html#dfacompare

	Andy

Received on Thursday, 17 March 2005 10:13:08 UTC