Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
how-to-realize-a-velocity-template-interpreters
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
eward
December 28, 2012
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
how-to-realize-a-velocity-template-interpreters
how to realize a velocity template language interpreters, use Jison.
eward
December 28, 2012
Other Decks in Programming
See All in Programming
Domain-Driven Transformation
hschwentner
2
2.3k
SREの越境 / SRE Collaboration
y0hgi
2
310
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
270
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
最近”作らせてる” ローカルAIアプリの話
akit37
0
470
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
450
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Believing is Seeing
oripsolob
1
240
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Typedesign – Prime Four
hannesfritz
42
3.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Prompt Engineering for Job Search
mfonobong
0
520
Raft: Consensus for Rubyists
vanstee
142
7.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
What's in a price? How to price your products and services
michaelherold
247
13k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
640
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Transcript
Velocity.js 如何实现⼀一个编译器 1 12年12月28⽇日星期五
来源:Plum • demo服务器和静态⽂文 件服务器 • less statics proxy php tms
• velocity 2 12年12月28⽇日星期五
要有⼀一个velocity解释器 3 12年12月28⽇日星期五
解决⽅方案1 $ java -jar velcoity.jar foo.vm foo.json 4 12年12月28⽇日星期五
5 12年12月28⽇日星期五
⽅方案2 6 12年12月28⽇日星期五
⽅方案2 6 12年12月28⽇日星期五
⽅方案2 • jsVelocity 6 12年12月28⽇日星期五
⽅方案2 • jsVelocity • EJS 6 12年12月28⽇日星期五
⽅方案2 • jsVelocity • EJS • handlerbars 6 12年12月28⽇日星期五
⽅方案2 • jsVelocity • EJS • handlerbars • doT.js 6
12年12月28⽇日星期五
⽅方案2 • jsVelocity • EJS • handlerbars • doT.js •
Juice 6 12年12月28⽇日星期五
⽅方案2 • jsVelocity • EJS • handlerbars • doT.js •
Juice • Logic-less templates 6 12年12月28⽇日星期五
jsVelocity • 第⼀一步:识别变量 7 12年12月28⽇日星期五
可以处理的情况 8 12年12月28⽇日星期五
实际情况是 9 12年12月28⽇日星期五
上⾯面只是简单模式 10 12年12月28⽇日星期五
复杂的情况 • 变量是由三种基本模式 组合⽽而来,正则⽆无法匹 配 11 12年12月28⽇日星期五
复杂的情况 • 变量是由三种基本模式 组合⽽而来,正则⽆无法匹 配 11 12年12月28⽇日星期五
复杂的情况 • 变量是由三种基本模式 组合⽽而来,正则⽆无法匹 配 11 12年12月28⽇日星期五
复杂的情况 • 变量是由三种基本模式 组合⽽而来,正则⽆无法匹 配 11 12年12月28⽇日星期五
复杂的情况 • 变量是由三种基本模式 组合⽽而来,正则⽆无法匹 配 11 12年12月28⽇日星期五
⽤用ruby和python语法写js 共同之处在于,如何解析复杂规则 http://coffeescript.org/ 12 12年12月28⽇日星期五
在解释什么是jison之前,总节 一下本次分享的第一个重要的 话题。前面讲了很多,其实是 如何实现一个编译器这个问题 最关键的步骤,后面是具体怎 么做,前面的步骤是,找到解 决问题的方法,我觉得,前者 更加重要。 13 12年12月28⽇日星期五
在解释什么是jison之前,总节 一下本次分享的第一个重要的 话题。前面讲了很多,其实是 如何实现一个编译器这个问题 最关键的步骤,后面是具体怎 么做,前面的步骤是,找到解 决问题的方法,我觉得,前者 更加重要。 13 12年12月28⽇日星期五
What can Jison do? 14 12年12月28⽇日星期五
vexflow 15 12年12月28⽇日星期五
handlebarsjs 16 12年12月28⽇日星期五
zaach/reflect.js 17 12年12月28⽇日星期五
Jison是⼀一种通⽤用技术 • css render https://speakerdeck.com/ dmosher/so-you-want-to-be-a-front-end- engineer 18 12年12月28⽇日星期五
Tom and Jerry 19 12年12月28⽇日星期五
Tom 和 Jerry为什么会 发⽣生故事? 20 12年12月28⽇日星期五
猫吃⽼老⿏鼠 21 12年12月28⽇日星期五
⽣生物链规则 22 12年12月28⽇日星期五
⽣生物链规则 • 为什么是猫吃⽼老⿏鼠,⽽而 不是Tom eat Jerry? 22 12年12月28⽇日星期五
⽣生物链规则 • 为什么是猫吃⽼老⿏鼠,⽽而 不是Tom eat Jerry? • 编译器实现的是⼀一套语 法规则的解析 22
12年12月28⽇日星期五
⽣生物链规则 • 为什么是猫吃⽼老⿏鼠,⽽而 不是Tom eat Jerry? • 编译器实现的是⼀一套语 法规则的解析 •
语法规则和⾷食物链规则 类似 22 12年12月28⽇日星期五
⽣生物链规则 • 为什么是猫吃⽼老⿏鼠,⽽而 不是Tom eat Jerry? • 编译器实现的是⼀一套语 法规则的解析 •
语法规则和⾷食物链规则 类似 • 分为Grammer和Lex 22 12年12月28⽇日星期五
语法规则 • reference = $ + id + attributes •
attributes = attribute | attributes + attribute • attribute = method | index | property • method = id + ( + param + ) • index = [ + reference + ] • property = dot + id 23 12年12月28⽇日星期五
递归 • 递归定义 • 问题不断拆分成⼩小问题 • ⽆无法匹配⼀一个vm语法 的复杂规则,但是可以 匹配规则的元素 24
12年12月28⽇日星期五
25 12年12月28⽇日星期五
语法分析过程 http://zaach.github.com/jison/demos/calc/ 26 12年12月28⽇日星期五
语法分析过程 http://zaach.github.com/jison/demos/calc/ 26 12年12月28⽇日星期五
$hello.foo[0] { "type": "references", "id": "hello", "leader": "$", "path": [
{ "type": "property", "id": "foo" }, { "type": "index", "id": { "type": "integer", "value": "0" } } ] } 27 12年12月28⽇日星期五
#if($foo > 10) { "type": "if", "condition": { "type": "math",
"operator": ">", "expression": [ { "type": "references", "id": "foo", "leader": "$" }, { "type": "integer", "value": "10" } ] } } 28 12年12月28⽇日星期五
#foreach($bar in [-2..4]) { "type": "foreach", "to": "bar", "from": {
"type": "array", "isRange": true, "value": [-2, "4"] } } 29 12年12月28⽇日星期五
第⼆二步,解释 30 12年12月28⽇日星期五
• http://git.shepherdwind.com/velocity.js/ runner/tests.html?grep=expression • https://github.com/shepherdwind/velocity.js/ blob/master/src/compile/expression.js#L11 • https://github.com/shepherdwind/velocity.js/ blob/master/src/parse/velocity.yy#L190 expression
31 12年12月28⽇日星期五
Block语法 32 12年12月28⽇日星期五
解决问题(解释器) 理论(编译原理) 问题(vm规则) + 问题解决⼀一般思路 实现编译器之前,需要知道编译原理 33 12年12月28⽇日星期五
3.学习需要的技术 4.解决问题 5.总结 2.寻找相似问题解决⽅方案 1.关注问题 6.编译原理 实际问题解决过程 34 12年12月28⽇日星期五
3.学习需要的技术 4.解决问题 5.总结 2.寻找相似问题解决⽅方案 1.关注问题 6.编译原理 实际问题解决过程 34 12年12月28⽇日星期五
灵感来源:顿悟 35 12年12月28⽇日星期五
Thanks 36 12年12月28⽇日星期五