[antlr-interest] Possible to conditionally skip token in rule?

Mark Mandel mark.mandel at gmail.com
Wed Jun 20 19:08:27 PDT 2007


So I cleaned up the grammar a little:

cfml
	:
	tag?
	;

tag
	:
		startTag
	;

startTag
scope tagScope;
	:
	(
	sto=START_TAG_OPEN
	{
		{$tagScope::currentName = $sto.text.toLowerCase().substring(1); }
	}
	stc=START_TAG_CLOSE
	tc=tagContent
	)
	;

tagContent
	:
	cfml
		(
		{ $tagScope::currentName.equals(input.LT(1).getText().toLowerCase().substring(2))
}?=> (endTag)
		|
		)
	;

endTag
	:
	END_TAG_OPEN^ END_TAG_CLOSE
	;

Which solved my multiple rule path issues, but I am still getting a
NoViableAltException on the test case of <a><c></a>

I've attached the debug parse tree, and you can see that when it hits
the predicate in tagContent, it doesn't skip back up to look at the
endTag rule for the previous tag.

Looks like I'm going to have to build the tree by hand... not sure
what else to do.

Thanks for the help,

Mark

On 6/20/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On Jun 20, 2007, at 3:42 PM, Mark Mandel wrote:
>
> > Nice to have you on Australia time :D
> >
> > With trying to do it with a predicate ? rule, I keep hitting a
> > FailedPredicateException, as it looks at the </a>, and then goes
> > 'well.. I have nothing at my end rule to match as well.. so umn.. I'm
> > going to throw an error.
>
> Hmm...that should never fail, it should only direct the parse.
> >
> > I tried trying to match it to EOF, but that didn't manage to work -
> > something like:
> >
> > agContent
> >       :
> >       tag* (
> >               {
> > $tagScope::currentName.equals(input.LT(1).getText().toLowerCase
> > ().substring(2))
> > }?
> >               (
> >                       endTag
> >               )
> >               |
> >               EOF
> >               )
> >
> > But I get noViableToken errors with that...
>
> Hmm...well, ( endTag) can be just endTag, but that's not it.  Should
> be ( {...}? endTag | ).  Doesn't that work?
>
> Ter
>
>


-- 
E: mark.mandel at gmail.com
W: www.compoundtheory.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: parsetree.png
Type: image/png
Size: 8053 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070621/0f9586d9/attachment-0001.png 


More information about the antlr-interest mailing list