[stringtemplate-interest] [ST4] Specifying delimiter in group files
Udo Borkowski
ub at abego-software.de
Thu Jan 27 07:25:53 PST 2011
I suggest we defined one set of delimiter as the default (I guess the current favorite is '<','>').
When a group file uses different delimiter than the default it must explicitly specify them (e.g. by using a new "delimiter" statement, as suggested in the original post).
For the GroupDir case I suggest to have an extra (optional) file in the directory (e.g. "group.config") that may hold the "delimiter" statement for the whole group. I.e. if the "group.config" file exists and defines the delimiter they are use for all template files in the directory. In a "template file" there must not be any "delimiter" statement.
One will no longer specify delimiter in the source code for STGroupFile and STGroupDir. However I would keep the STGroup(char delimiterStartChar, char delimiterStopChar) constructor, just in case one wants to create a group "on the fly", e.g. when writing inline test cases.
Udo
On 27.01.2011, at 02:04, Terence Parr wrote:
> Actually, this brings up an excellent point. why are we doing
>
> STGroup g = new STGroupFile("t.stg", '$', '$');
>
> when the file itself and not the code should determine what the delimiters are. the code should not care. If we change the delimiter in the file, the code no longer works.
>
> Even if we're doing STGroupDir("/tmp/templates") I don't think we should specify the delimiters. It might be the case that the templates use different delimiters. Hmm... groups currently only understand one set of delimiters so maybe this is okay for dirs.
>
> I'd like to be consistent though. with the directory version, we wouldn't know with the delimiter was until we read in one of the templates. not sure I like that.
>
> suggestions anyone?
>
> Ter
>
> On Jan 26, 2011, at 2:19 AM, Udo Borkowski wrote:
>
>> Hi,
>>
>> I am currently using different sets of delimiter in different group files (e.g. '$','$' vs. '<','>'). Depending on this I need to make sure the STGroup is create with the proper delimiter.
>>
>> What do you think of making it more explicit in the group file, what delimiter it uses?
>>
>> This may be achieved with a new (optional) syntax element in the group grammar, defining the delimiter for this file. It may look like:
>>
>> delimiter
>> : 'delimiter' s=STRING e=STRING {
>> //TODO: check if s and e have length 1, or better: use CHAR token
>> group.delimiterStartChar=$s.charAt(0);
>> group.delimiterEndChar=$e.charAt(0);
>> }
>>
>> (Code not tested)
>>
>> This statement would overwrite the previous delimiter setting in the group.
>>
>> The delimiter statement need to be speficied before the first def element.
>>
>>
>>
>> Udo
>>
>>
>> _______________________________________________
>> 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