TheEvolutionoftheStringTemplateEngine

上传人:lx****y 文档编号:243022673 上传时间:2024-09-14 格式:PPT 页数:17 大小:104KB
返回 下载 相关 举报
TheEvolutionoftheStringTemplateEngine_第1页
第1页 / 共17页
TheEvolutionoftheStringTemplateEngine_第2页
第2页 / 共17页
TheEvolutionoftheStringTemplateEngine_第3页
第3页 / 共17页
点击查看更多>>
资源描述
Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,The Evolution of the,StringTemplate,Engine,P,resented to the UC Berkeley,Harmonia,group15 December 2004,Terence Parr,University of San Francisco,parrt,cs.,usfca,.edu,Overview,Introduction,what is,StringTemplate,?,why did I build it?,the nature of text generation,Design goals,The evolution; 4 phases,Experience,Lessons,What is,StringTemplate,Template engine designed with Tom Burns (CEO,jGuru,.com) while building commercial sites over many years,in response to JSP,small: 170k uncompressed binary (w/o test rig),Evolved from simple “document with holes” into a functional language capable of generating large class of languages,Well suited to generative programming as well as dynamic page generation; being used in new ANTLR parser generator for code generation,Distinguishing characteristic: strictly enforces separation of model and view,Canonical Operations,Attribute reference:,Template references (possibly recursive):,Apply template to multi-valued attribute:,or,Conditional include:,extends Name: Guest,Example*,Translated “,Program Manipulation via Interactive Transformations,” example to actual,StringTemplate,template definition:,Integration with existing code clean, easy,generateMemSize,(node) := ,return result;,*shameless,StringTemplate,plug,Semantics,Side-effect free expressions,No “state”,No defined order of execution,Lazy evaluation,Template inheritance group to subgroup,Dynamically scoped; values inherited,Recursive template instantiation,Design Goals,Optimized for enforcement of separation not for Turing completeness nor,expressive,“one-liners”,Conceptual integrity,single-minded fanaticism against entanglement,stick to a few concepts: attributes and templates,consistency; no special,cases; driven by design not implementation details,proper language formalisms, semantics, sane syntax,Simple as possible,useful to nonprogrammers,makes it fast, easy to build/maintain,Powerful as possible,Phase I, 1999-2001,“Document with holes”; only,tag,refs,Could nest templates by setting a tag value to template; dynamic scoping (“value inheritance”),Not intended for full page generation,File of template definitions loaded into hash table; code manually created template instances,INSERT INTO Topics VALUES (,);,Phase II, 2001-2003,Rewrite of,jGuru,.com; learned entanglement allowed by JSP is horrible!,Decided to enhance,StringTemplate, letting needs dictate feature set; would not be Turing-complete!,Moved to single template per file format with $ indicating,attribute,ref,Needed “include”,added template reference rather than #include, macro,subconciously,supported recursion,Phase II, 2001-2003 (Contd),Needed to walk multi-valued attributes; added “apply” syntax:,$names:bold(item=names)$,$names:bold(item=names, separator=“, “)$,Allowed anonymous templates,$names:”$names$”$,Iterated value naming convention evolved,$names:bold(item=namesi)$,Needed multiple array walk for relational DB,$a,b:,foo,(x=ai, y=bi)$,Finally, needed conditionalinclusion,$if(userName)$,Name: $userName$,$,endif,(userName)$,Phase III, 2003-Summer 2004,Wanted to say,$names:bold()$,w/o,arg,defined default attribute,attr,Cleaned up IF:,$if(,foo,)$,endif,$,Nested anonymous blocks:,$names:$,Round-robin template application,$users:,rowOdd,(),rowEven,()$,Properties:,$user.name$,calls,user.,getName,(),Indirect template ref:,$(,tname,)()$,; added in context of “immediate evaluation”,Template inheritance via,StringTemplateGroup,Phase IV, 2004,Added group file format: mutually-referential templates with formal arguments,method(type,name,args,body),:= ,public ( ) ,assign(lhs,expr,),:= “ = ;”,Future,Named,args,for anonymous blocks ala Smalltalk,$list:x | $x$,.,mem,_size();,iterator,could also choose single argument from named templates,Add parallel array walking back in,Syntax for super group?,group sub : super;,Lots of little clean up; e.g.,whitespace, ,Experience (ANTLR v3.0),Tree walker (controller) collects data from AST (model), pushes data into templates (view),Decouples order of computation from order of output (this is huge),Enforced separation guarantees easy retargeting, no code duplication, ,no code in template,no output strings in code generator,Previous code generator hopelessly entangled,Group file format (output grammar) is great! “Executable documentation”,Practical Lessons,Separate pattern matching from templates!,dont make templates also analyze model,lazy evaluation essential; decouple order of computation from order of output; build in any order,Isolates templates (“user code”) from model changes, which will surely evolve,Templates may be reusable w/o embedded logic,Recursion required for nested structures,Attributes,dynamic scoping really handy,push dont pull attributes; attributes are inert,Simple language is fast, easy to learn, easy to use, promotes,retargetability,Philosophical Lessons,Say what you mean! e.g., no FOR-loops,Focus on principles, conceptual integrity,focus on what not how,other tools either doc with holes or Turing complete,Difficult to stick to your principles and still create usable tool; grey areas appear,Language design is hard;implementation is relatively easy,Selection pressure results in,StringTemplate,output conforms to a language, hence, a grammar,strict enforcement of separation leads to grammar,Demo,Generating Java / XML with same model,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!