Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
how-to-realize-a-velocity-template-interpreters
Search
eward
December 28, 2012
Programming
0
150
how-to-realize-a-velocity-template-interpreters
how to realize a velocity template language interpreters, use Jison.
eward
December 28, 2012
Tweet
Share
Other Decks in Programming
See All in Programming
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
120
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
160
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
120
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
380
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
110
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
270
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
190
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
690
5つのアンチパターンから学ぶLT設計
narihara
1
110
NPOでのDevinの活用
codeforeveryone
0
260
Java on Azure で LangGraph!
kohei3110
0
170
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Scaling GitHub
holman
459
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
940
VelocityConf: Rendering Performance Case Studies
addyosmani
330
24k
The Pragmatic Product Professional
lauravandoore
35
6.7k
For a Future-Friendly Web
brad_frost
179
9.8k
Automating Front-end Workflow
addyosmani
1370
200k
Visualization
eitanlees
146
16k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
YesSQL, Process and Tooling at Scale
rocio
173
14k
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⽇日星期五