[antlr-interest] Re : gunit tree testsuite can't find the group template file

Stanislas Rusinsky rusinskystanislas at yahoo.fr
Sun Jul 6 05:35:02 PDT 2008


Hi Leon,

thank you for your answer (and your work with gUnit), I have found a temporary workaround to be able to load the group and test the tree grammar for the moment.

The code loading the template group file is directly inserted in the tree grammar instead of inside the external class containing the main() method.

Looks like this:
@header {
    package com.foo.bar;
    import java.io.*;
    import org.antlr.stringtemplate.StringTemplateGroup;
}
...
myStartRuleInMyTreeGrammar
@init    {
    try {
        FileReader groupFileR = new FileReader("treeKoRuGenClasses.stg"); 
        StringTemplateGroup templates = new StringTemplateGroup(groupFileR); 
        groupFileR.close();
        this.setTemplateLib(templates);
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

Stanislas Herman.


----- Message d'origine ----
De : Leon Su <leon.antlr at mac.com>
À : Stanislas Rusinsky <rusinskystanislas at yahoo.fr>
Cc : antlr-interest <antlr-interest at antlr.org>
Envoyé le : Samedi, 5 Juillet 2008, 20h23mn 54s
Objet : Re: [antlr-interest] gunit tree testsuite can't find the group template file

Hi Stanislas,

gUnit currently can only test on plain parser/tree grammar, and  
doesn't support loading group file(*.stg) or setting customized tree  
adaptor yet.
The functionality such as walker.etTemplateLib() and  
parser.setTreeAdaptor() will be added into the next release. Sorry  
for the inconvenience.

Leon

On Jul 5, 2008, at 9:09 AM, Stanislas Rusinsky wrote:

> Hello all,
>
> (I almost wrote "hello ANTLeRs"... happily babelfish saved me from  
> my french ignorance of english subtleties)
>
>
> The problem: I have a text grammar and a tree grammar.
>
> The tree grammar has its group template file loaded with these  
> commands:
>         FileReader groupFileR = new FileReader 
> ("treeKoRuGenClasses.stg");
>         StringTemplateGroup templates = new StringTemplateGroup 
> (groupFileR);
>         groupFileR.close();
>         walker.setTemplateLib(templates); // where to find templates
>
> Running the tree parser works like a charm with this code.
>
> The gunit testsuite works fine with the text grammar, but the tree  
> grammar gunit testsuite complains it can't "find template  
> entity_modifiers.st; group hierarchy is  
> [treeKoRuGenClassesTemplates]".
> The path includes the directory containing the template group file.
>
> I have tried renaming my .stg file to  
> treeKoRuGenClassesTemplates.stg as suggested by the trace, changing  
> also the first line to "group treeKoRuGenClassesTemplates;" but  
> nothing helped, I still get the stacktrace (see below).
>
> It seems the java class generated from the tree sets a default  
> empty template group ( protected StringTemplateGroup templateLib =  
> new StringTemplateGroup("treeKoRuGenClassesTemplates",  
> AngleBracketTemplateLexer.class); ). Should I use a streamreader in  
> my treeKoRuGenClasses.g to read the stg group file and set it with  
> some sort of "this.setTemplateLib(myTemplateGroupFileStream)" ?
>
> Anyone could give me some advice, hint, or broaden my vision on  
> this subject?
>
> Thanks in advance,
>
> Stanislas Herman Rusinsky.
>
> test-tree:
>      [java] java.lang.reflect.InvocationTargetException
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0 
> (Native Method)
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:39)
>      [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:25)
>      [java]     at java.lang.reflect.Method.invoke(Method.java:585)
>      [java]     at org.antlr.gunit.gUnitExecuter.runTreeParser 
> (gUnitExecuter.java:392)
>      [java]     at org.antlr.gunit.gUnitExecuter.runCorrectParser 
> (gUnitExecuter.java:133)
>      [java]     at org.antlr.gunit.gUnitExecuter.executeTests 
> (gUnitExecuter.java:149)
>      [java]     at org.antlr.gunit.gUnitExecuter.execTest 
> (gUnitExecuter.java:92)
>      [java]     at org.antlr.gunit.Interp.main(Interp.java:62)
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0 
> (Native Method)
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:39)
>      [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:25)
>      [java]     at java.lang.reflect.Method.invoke(Method.java:585)
>      [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run 
> (ExecuteJava.java:217)
>      [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute 
> (ExecuteJava.java:152)
>      [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java: 
> 747)
>      [java]     at org.apache.tools.ant.taskdefs.Java.executeJava 
> (Java.java:201)
>      [java]     at org.apache.tools.ant.taskdefs.Java.execute 
> (Java.java:104)
>      [java]     at org.apache.tools.ant.UnknownElement.execute 
> (UnknownElement.java:288)
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0 
> (Native Method)
>      [java]     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:39)
>      [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:25)
>      [java]     at java.lang.reflect.Method.invoke(Method.java:585)
>      [java]     at  
> org.apache.tools.ant.dispatch.DispatchUtils.execute 
> (DispatchUtils.java:105)
>      [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
>      [java]     at org.apache.tools.ant.Target.execute(Target.java: 
> 357)
>      [java]     at org.apache.tools.ant.Target.performTasks 
> (Target.java:385)
>      [java]     at org.apache.tools.ant.Project.executeSortedTargets 
> (Project.java:1329)
>      [java]     at org.apache.tools.ant.Project.executeTarget 
> (Project.java:1298)
>      [java]     at  
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets 
> (DefaultExecutor.java:41)
>      [java]     at org.apache.tools.ant.Project.executeTargets 
> (Project.java:1181)
>      [java]     at org.apache.tools.ant.Main.runBuild(Main.java:698)
>      [java]     at org.apache.tools.ant.Main.startAnt(Main.java:199)
>      [java]     at org.apache.tools.ant.launch.Launcher.run 
> (Launcher.java:257)
>      [java]     at org.apache.tools.ant.launch.Launcher.main 
> (Launcher.java:104)
>      [java] Caused by: java.lang.IllegalArgumentException: Can't  
> find template entity_modifiers.st; group hierarchy is  
> [treeKoRuGenClassesTemplates]
>      [java]     at  
> org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate 
> (StringTemplateGroup.java:507)
>      [java]     at  
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf 
> (StringTemplateGroup.java:392)
>      [java]     at  
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf 
> (StringTemplateGroup.java:404)
>      [java]     at  
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf 
> (StringTemplateGroup.java:412)
>      [java]     at  
> com.mindspark.koru.treeKoRuGenClasses.entity_modifiers(Unknown Source)
>      [java]     at com.mindspark.koru.treeKoRuGenClasses.entity 
> (Unknown Source)
>      [java]     at com.mindspark.koru.treeKoRuGenClasses.koru 
> (Unknown Source)
>      [java]     ... 35 more
>      [java] org.apache.tools.ant.ExitException: Permission  
> (java.lang.RuntimePermission exitVM) was not granted.
>      [java]     at org.apache.tools.ant.types.Permissions 
> $MySM.checkExit(Permissions.java:174)
>      [java]     at java.lang.Runtime.exit(Runtime.java:88)
>      [java]     at java.lang.System.exit(System.java:869)
>      [java]     at org.antlr.gunit.gUnitExecuter.runTreeParser 
> (gUnitExecuter.java:460)
>      [java]     at org.antlr.gunit.gUnitExecuter.runCorrectParser 
> (gUnitExecuter.java:133)
>      [java]     at org.antlr.gunit.gUnitExecuter.executeTests 
> (gUnitExecuter.java:149)
>      [java]     at org.antlr.gunit.gUnitExecuter.execTest 
> (gUnitExecuter.java:92)
>      [java]     at org.antlr.gunit.Interp.main(Interp.java:62)
>
>
>        
> ______________________________________________________________________ 
> _______
> Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http:// 
> mail.yahoo.fr
>
>
>
>        
> ______________________________________________________________________ 
> _______
> Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http:// 
> mail.yahoo.fr



      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr


More information about the antlr-interest mailing list