[stringtemplate-interest] [ST4 Beta-4] Cannot intercept error messages from imported groups

Udo Borkowski ub at abego-software.de
Fri Feb 11 03:38:35 PST 2011


> Hi Udo, can we add an ErrorManager arg to the STGroup* ctors?

Adding an ErrorManager arg to the STGroup* ctors will only work if the error manager of the "importing" group is passed in when an imported group is created (e.g. in "importTemplates"). 

This way the imported group "inherits" the ErrorManager of the importing group. Sounds good to me.

…

In an afterthought: I think, I'd rather add an "STGroup importer" arg to the STGroup* ctors.

In the above approach imported groups will use the ErrorManager of their importer as defined when they are constructed. I.e. changing the ErrorManager in the importer will not affect the imported groups.

By using the "importer" link to the importer we can make sure an STGroup will always use the "ErrorManager" of the importing group if it defines no "own" ErrorManager. 

E.g. extend STGroup :

	private STGroup importer; 
	
	public ErrorManager getErrMgr() {
		return 
			errMgr != null ?  errMgr :
			importer != null ? importer.getErrMgr() 
			: DEFAULT_ERR_MGR;
	}

	public void setErrMgr(ErrorManager errMgr) {
		this.errMgr = errMgr;
	}	

Having this link back to the "importer" STGroup may also come handy in other cases.

(Of cause we can no longer directly access the errMgr field but use the accessor when using this approach)

How does this sound?

Udo


On 11.02.2011, at 01:28, Terence Parr wrote:

> Hi Udo, can we add an ErrorManager arg to the STGroup* ctors?
> Ter
> On Feb 7, 2011, at 3:12 AM, Udo Borkowski wrote:
> 
>> Hi,
>> 
>> I am using my own ErrorListener and set it when a new group is created. 
>> 
>> With Beta-4 it is now possible to notice when an imported group file does not exist.
>> 
>> However I do not notice when the imported group is buggy. The error message is still written to the standard error listener.
>> 
>> This is because the error listeners of the imported groups haven't been updated to my error listener. I tried to do so at the same time when setting the listener for the parent group. However I noticed the "imports" are not yet defined after creating the parent group but when the first instance of the parent group is created. 
>> 
>> Any idea how I can set the error listeners for the imported groups to my error listener?
>> 
>> 
>> One idea: as I am using ONE error listener for ALL groups it would be fine for me just to replace the "standard error listener" globally. E.g.
>> 
>>> What about making the constant STGroup.DEFAULT_ERR_MGR a static variable/property? This way a different DefaultErrorManager could be defined. The default would be the current "new ErrorManager()". 
>> 
>> I already suggested this in an earlier post to work around the "missing imported group" issue. But this also seems to be an easy solution for the "cannot intercept error messages from imported groups" issue. I already tried it out and it works fine.
>> 
>> 
>> Udo
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110211/9ab305be/attachment-0001.html 


More information about the stringtemplate-interest mailing list