[stringtemplate-interest] [ST4] Specify the encoding in the template group file

Terence Parr parrt at cs.usfca.edu
Fri Jan 28 13:20:55 PST 2011


Hi. don't we need to know that the encoding is before we can load the file?
Ter
On Jan 27, 2011, at 8:24 AM, Udo Borkowski wrote:

> Hi,
> 
> I suggest to specify the encoding/charset of a file in the file itself. This follows the same arguments as for the delimiter:
> 
>> why are we doing
>> 
>> STGroup g = new STGroupFile("t.stg", "ISO-8859-1", '$', '$');
>> 
>> when the file itself and not the code should determine what the encoding is. the code should not care. If we change the encoding in the file, the code no longer works. (Ter, bold stuff by Udo)
> 
> I suggest to add a new (optional) group statement the group file must start with (if defined). If it is missing the (platform specific) default encoding is used.
> 
> Possible syntax
> 
> 	'encoding' STRING
> 
> For the GroupDir case the "group.config" file could be used again. However we may consider if the individual template files may specify individual charsets, too. (Note: this is different from the "delimiter" case where all template files share the same delimiters)
> 
> BUT: as I am writing this I noticed that this is very much like the stuff in the XML preamble:
> 
>> <?xml encoding='ISO-8859-1'?>
> 
> Maybe we should do something similar. What about making the group file (optionally) start with something like this:
> 
> 	<st(version="4.0", encoding="ISO-8859-1")>
> 
> Looks familiar?!
> 
> This "template call" style also gives us the option to add more information later.
> 
> 
> Udo
> 
> P.S.: Using such a well defined file content prefix "<st(" will probably also allows us to support "encoding autodetection" (http://www.w3.org/TR/REC-xml/#sec-guessing) in the future.
> 
> _______________________________________________
> 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