[stringtemplate-interest] Problem in StringTemplate V4

Terence Parr parrt at cs.usfca.edu
Thu Mar 4 14:43:34 PST 2010


Hi. interesting. dang windoze.  ok, so I want ST4 to always use / as the dir separator for consistency across platforms.  how do we fix?  Should I convert all \ to /?
Ter
On Mar 4, 2010, at 11:19 AM, Cliff Zhao wrote:

> I run into problem for StringTemplate V4. It failed in my Windows XP environment.
> 
> I did some debug, and found the problem is about forward slash (/) and back slash(\). 
> 
> The File(name).getParent() return OS-specific path. On Windows, it is "\". So, when I load a template in a group like group.getInstanceOf("admin/home"), it returns null.
> The code in STGroupDir.java:
> 
>     public CompiledST loadTemplateFile(String fileName) {
>         //System.out.println("load "+fileName+" from "+root);
>         String prefix = new File(fileName).getParent();
>         if ( !prefix.endsWith("/") ) prefix += "/";
>         try {
>             String templateName = Misc.getFileNameNoSuffix(fileName);
>             URL f = new URL(root+fileName);
>             ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
>             if ( ErrorManager.v3_mode) {
>                 String template = fs.toString(); // needs > ANTLR 3.2
>                 template = template.trim();
>                 String justName = new File(templateName).getName();
>                 defineTemplate(prefix,
>                                new CommonToken(GroupParser.ID,justName),
>                                null,
>                                template);
>             }
>             else {
>                 GroupLexer lexer = new GroupLexer(fs);
>                 fs.name = fileName;
>                 CommonTokenStream tokens = new CommonTokenStream(lexer);
>                 GroupParser parser = new GroupParser(tokens);
>                 parser.group = this;
> =A=====>                parser.templateDef(prefix);
>             }
> =B=====>            return templates.get(templateName);
>         }
> 
> After the A point, the templates variable contains one entry { "\admin/home", --parsed ST--}.
> At the B point, the templateName is "/admin/home". It is a mismatch!
> 
> Could you fix it?
> 
> Thank you very much.
> 
> Best Regards,
> Cliff Zhao
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list