读书人

StringTemplate学习札记(四) StringTe

发布时间: 2012-07-24 17:47:58 作者: rapoo

StringTemplate学习笔记(四) StringTemplateGroup文件

一,简介

????? StringTemplateGroup文件时在StringTemplate2.0之后被引入的。

????? 主要有以下特点:

可以把多个模板定义在一个模板组文件里提供了对模板参数的检测(所有属性都必须在模板属性列表中列出,否则会报错),使模板更加容易阅读

????test.stg

????????? child.stg

interface

????????? 与java的接口类似,文件后缀名为sti,并且文件名前缀必须和接口名一致

?????????

???????? 说明: “:”左边为key,右边为value,

???????????????????? 访问方式为访问map属性一致,例如<typeInitMap.int>返回"0",

???????????????????? 如果访问的key未定义,则返回default的值,如<typeInitMap.object>返回"null"

???????????????????? 如果想获取key值,只需使用default:key,此时<typeInitMap.object>返回"object"

???????????????????? 可见性:如果StringTemplate中有一属性名字也为typeInitMap,则typeInitMap在该StringTemplate种不可见

?????????

?五,StringTemplateGroup文件格式

????

??

?六,参考资料

?

http://www.antlr.org/wiki/display/ST/Group+Files

http://www.antlr.org/wiki/display/ST/Group+interfaces

读书人网 >开源软件

热点推荐