[stringtemplate-interest] Problem in StringTemplate V4
Terence Parr
parrt at cs.usfca.edu
Tue Mar 23 14:35:29 PDT 2010
Hi. what about when you make a group dir at root C:\foo ? Doesn't that mess up when i load a template called T? I'd get a URL of C:\foo/T.stg here:
groupFileURL = new URL(root+parent+".stg");
Ter
On Mar 4, 2010, at 5:37 PM, Cliff Zhao wrote:
> I did a quick fix as below:
> 1. Add a method in the Misc class:
> public static String getParent(String name) {
> if (name==null) return null;
> int pos=name.lastIndexOf('/');
> if (pos<=0) return "/";
> return name.substring(0, pos+1);
> }
> 2. Replace "new File(something).getParent()" with "Misc.getParent(something)"
>
> It worked for me. I am not sure if it is a good fix, since I am not so deep in the StringTemplate code.
>
> Best Regards,
> Cliff Zhao
>
> On Thu, Mar 4, 2010 at 5:43 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> 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