[antlr-interest] how to check if a optional token exists or not ??

Austin Hastings Austin_Hastings at Yahoo.com
Fri Nov 16 00:44:16 PST 2007


In java, ANTLR creates a named variable for each label you use. Check 
for meta == null, without using a '$' sign.

if (meta != null)

=Austin

OJAY78 at gmx.de wrote:
> Hi,
>
> I stuck on a small Problem. I have this rule with an optional token meta. In the Java Code I want to check if this token is null or not so that I can call a other method. But this check of the meta token will result in a nullpointer exception. Does anyone know how I can solve this? How can I check the meta token?
>
> Thanks
>
> valueType returns[StringObject value]
> 	:'value' ',' rv=function_parameter (',' meta=valueMetaType)?
> 	{
> 	
> 	String valName = $rv.value;
> 	FormValue fv = formInstance.getFormValue( valName 
> 		
> 		if( fv == null ) {
> 			log.debug("VALUE TYPE: Feld ist leer");
> 			$value = new StringObject("",null,null);
> 		}
> 		else {
> 			if ($meta.text == null){
> 			$value = new StringObject(fv.getFieldValue().toString(),fv,valName);
> 			}
> 			else{
> 			 $value=FELHelper.getFormValueMeta(fv,$meta.text);
> 			}
> 		}
>
> 	}
> 	;
>   



More information about the antlr-interest mailing list