Suche senden
Hochladen
How To Create Custom DSLs By PHP
•
1 gefällt mir
•
1,201 views
Atsuhiro Kubo
Folgen
Technologie
Melden
Teilen
Melden
Teilen
1 von 29
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
PHP超入門@LL温泉
PHP超入門@LL温泉
Sotaro Karasawa
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説
mochiko AsTech
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Yusuke Kawasaki
Windows PowerShell V2 の新機能
Windows PowerShell V2 の新機能
shigeya
PHP Conference 09 Japan Microsoft
PHP Conference 09 Japan Microsoft
hirookun
Modern XAML Development - Matt Lacey
Modern XAML Development - Matt Lacey
Matt Lacey
Oracle Unconference 松下 4/22
Oracle Unconference 松下 4/22
matsushita
Ubuntu Firefox オススメ・アドオン
Ubuntu Firefox オススメ・アドオン
ubon
Empfohlen
PHP超入門@LL温泉
PHP超入門@LL温泉
Sotaro Karasawa
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説
mochiko AsTech
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Yusuke Kawasaki
Windows PowerShell V2 の新機能
Windows PowerShell V2 の新機能
shigeya
PHP Conference 09 Japan Microsoft
PHP Conference 09 Japan Microsoft
hirookun
Modern XAML Development - Matt Lacey
Modern XAML Development - Matt Lacey
Matt Lacey
Oracle Unconference 松下 4/22
Oracle Unconference 松下 4/22
matsushita
Ubuntu Firefox オススメ・アドオン
Ubuntu Firefox オススメ・アドオン
ubon
SEASR and UIMA
SEASR and UIMA
Loretta Auvil
基于WordNet的英语词语相似度计算
基于WordNet的英语词语相似度计算
qiyadeng
090608-TogoWS REST
090608-TogoWS REST
ocha_kaneko
Open Source Type Pad Mobile
Open Source Type Pad Mobile
Hiroshi Sakai
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Yusuke Kawasaki
Windows 7兼容性系列课程(1):Windows 7兼容性概述
Windows 7兼容性系列课程(1):Windows 7兼容性概述
Chui-Wen Chiu
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
mochiko AsTech
オブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Ruby
Kitajiro Kitayama
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
mochiko AsTech
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
devsumi2009
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
terada
XS Japan 2008 Xen Mgmt Japanese
XS Japan 2008 Xen Mgmt Japanese
The Linux Foundation
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
Yusuke Wada
P2P Bug Tracking with SD
P2P Bug Tracking with SD
Jesse Vincent
What Can Compilers Do for Us?
What Can Compilers Do for Us?
National Cheng Kung University
Apache Tapestry
Apache Tapestry
Akio Katayama
Five Minutes Introduction For Rails
Five Minutes Introduction For Rails
Koichi ITO
Revisited
Revisited
Shunsaku Kudo
テンプレート管理ツール r3
テンプレート管理ツール r3
Ippei Ogiwara
20090313 Cakephpstudy
20090313 Cakephpstudy
Yusuke Ando
090309seminar talk about Cloud Computing
090309seminar talk about Cloud Computing
Kohei Nishikawa
Dynamic Language による Silverlight2 アプリケーション開発
Dynamic Language による Silverlight2 アプリケーション開発
terurou
Weitere ähnliche Inhalte
Was ist angesagt?
SEASR and UIMA
SEASR and UIMA
Loretta Auvil
基于WordNet的英语词语相似度计算
基于WordNet的英语词语相似度计算
qiyadeng
090608-TogoWS REST
090608-TogoWS REST
ocha_kaneko
Open Source Type Pad Mobile
Open Source Type Pad Mobile
Hiroshi Sakai
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Yusuke Kawasaki
Windows 7兼容性系列课程(1):Windows 7兼容性概述
Windows 7兼容性系列课程(1):Windows 7兼容性概述
Chui-Wen Chiu
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
mochiko AsTech
オブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Ruby
Kitajiro Kitayama
Was ist angesagt?
(8)
SEASR and UIMA
SEASR and UIMA
基于WordNet的英语词语相似度计算
基于WordNet的英语词语相似度计算
090608-TogoWS REST
090608-TogoWS REST
Open Source Type Pad Mobile
Open Source Type Pad Mobile
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Cloud Computing - クラウドコンピューティング(会津産学懇話会)
Windows 7兼容性系列课程(1):Windows 7兼容性概述
Windows 7兼容性系列课程(1):Windows 7兼容性概述
20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
オブジェクト指向スクリプト言語 Ruby
オブジェクト指向スクリプト言語 Ruby
Ähnlich wie How To Create Custom DSLs By PHP
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
mochiko AsTech
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
devsumi2009
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
terada
XS Japan 2008 Xen Mgmt Japanese
XS Japan 2008 Xen Mgmt Japanese
The Linux Foundation
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
Yusuke Wada
P2P Bug Tracking with SD
P2P Bug Tracking with SD
Jesse Vincent
What Can Compilers Do for Us?
What Can Compilers Do for Us?
National Cheng Kung University
Apache Tapestry
Apache Tapestry
Akio Katayama
Five Minutes Introduction For Rails
Five Minutes Introduction For Rails
Koichi ITO
Revisited
Revisited
Shunsaku Kudo
テンプレート管理ツール r3
テンプレート管理ツール r3
Ippei Ogiwara
20090313 Cakephpstudy
20090313 Cakephpstudy
Yusuke Ando
090309seminar talk about Cloud Computing
090309seminar talk about Cloud Computing
Kohei Nishikawa
Dynamic Language による Silverlight2 アプリケーション開発
Dynamic Language による Silverlight2 アプリケーション開発
terurou
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
devsumi2009
Ruby Postgres
Ruby Postgres
Akio Ishida
S2Flex2
S2Flex2
Masaaki Yonebayashi
20090410 Gree Opentech Main
20090410 Gree Opentech Main
Hideki Yamane
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理
Shinya Miyazaki
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese Version
Libin Pan
Ähnlich wie How To Create Custom DSLs By PHP
(20)
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
【13-A-2】 「Delphi for PHP のエバンジェリストが、日本の PHP エバンジェリストと、 PHP と IDE の今と未来を語る」~Em...
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
XS Japan 2008 Xen Mgmt Japanese
XS Japan 2008 Xen Mgmt Japanese
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
P2P Bug Tracking with SD
P2P Bug Tracking with SD
What Can Compilers Do for Us?
What Can Compilers Do for Us?
Apache Tapestry
Apache Tapestry
Five Minutes Introduction For Rails
Five Minutes Introduction For Rails
Revisited
Revisited
テンプレート管理ツール r3
テンプレート管理ツール r3
20090313 Cakephpstudy
20090313 Cakephpstudy
090309seminar talk about Cloud Computing
090309seminar talk about Cloud Computing
Dynamic Language による Silverlight2 アプリケーション開発
Dynamic Language による Silverlight2 アプリケーション開発
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
Ruby Postgres
Ruby Postgres
S2Flex2
S2Flex2
20090410 Gree Opentech Main
20090410 Gree Opentech Main
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese Version
Mehr von Atsuhiro Kubo
MPD Osaka Extra 5
MPD Osaka Extra 5
Atsuhiro Kubo
Enaction, Not Design on MPD Osaka Extra 1
Enaction, Not Design on MPD Osaka Extra 1
Atsuhiro Kubo
Enaction, Not Design on Symfony Meetup Kansai 2
Enaction, Not Design on Symfony Meetup Kansai 2
Atsuhiro Kubo
The Birth of FormalBears - A new META for BEAR.Sunday applications
The Birth of FormalBears - A new META for BEAR.Sunday applications
Atsuhiro Kubo
Lean Architecture / DCI Evening Report
Lean Architecture / DCI Evening Report
Atsuhiro Kubo
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Atsuhiro Kubo
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Atsuhiro Kubo
ジェネレーティブプログラミングの世界
ジェネレーティブプログラミングの世界
Atsuhiro Kubo
意図を表現するプログラミング
意図を表現するプログラミング
Atsuhiro Kubo
Software Development with Symfony
Software Development with Symfony
Atsuhiro Kubo
Introduction to Continuous Test Runner MakeGood
Introduction to Continuous Test Runner MakeGood
Atsuhiro Kubo
Getting Started with Testing using PHPUnit
Getting Started with Testing using PHPUnit
Atsuhiro Kubo
Introduction to Continuous Testing
Introduction to Continuous Testing
Atsuhiro Kubo
Symfony2でより良いソフトウェアを作るために
Symfony2でより良いソフトウェアを作るために
Atsuhiro Kubo
MakeGoodで快適なテスト駆動開発を
MakeGoodで快適なテスト駆動開発を
Atsuhiro Kubo
Eclipse PDT + MakeGoodによるPHPコードのテスト
Eclipse PDT + MakeGoodによるPHPコードのテスト
Atsuhiro Kubo
Eclipse PDT + MakeGood による PHP コードのテスト
Eclipse PDT + MakeGood による PHP コードのテスト
Atsuhiro Kubo
Piece Framework 2.0 Background
Piece Framework 2.0 Background
Atsuhiro Kubo
Mehr von Atsuhiro Kubo
(18)
MPD Osaka Extra 5
MPD Osaka Extra 5
Enaction, Not Design on MPD Osaka Extra 1
Enaction, Not Design on MPD Osaka Extra 1
Enaction, Not Design on Symfony Meetup Kansai 2
Enaction, Not Design on Symfony Meetup Kansai 2
The Birth of FormalBears - A new META for BEAR.Sunday applications
The Birth of FormalBears - A new META for BEAR.Sunday applications
Lean Architecture / DCI Evening Report
Lean Architecture / DCI Evening Report
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
ジェネレーティブプログラミングの世界
ジェネレーティブプログラミングの世界
意図を表現するプログラミング
意図を表現するプログラミング
Software Development with Symfony
Software Development with Symfony
Introduction to Continuous Test Runner MakeGood
Introduction to Continuous Test Runner MakeGood
Getting Started with Testing using PHPUnit
Getting Started with Testing using PHPUnit
Introduction to Continuous Testing
Introduction to Continuous Testing
Symfony2でより良いソフトウェアを作るために
Symfony2でより良いソフトウェアを作るために
MakeGoodで快適なテスト駆動開発を
MakeGoodで快適なテスト駆動開発を
Eclipse PDT + MakeGoodによるPHPコードのテスト
Eclipse PDT + MakeGoodによるPHPコードのテスト
Eclipse PDT + MakeGood による PHP コードのテスト
Eclipse PDT + MakeGood による PHP コードのテスト
Piece Framework 2.0 Background
Piece Framework 2.0 Background
Kürzlich hochgeladen
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
Zilliz
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Slibray Presentation
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
2toLead Limited
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
Alfredo García Lavilla
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
Lorenzo Miniero
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
null - The Open Security Community
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Hervé Boutemy
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
hariprasad279825
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Alex Barbosa Coqueiro
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
Manik S Magar
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
BookNet Canada
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
Fwdays
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
Commit University
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
Stephanie Beckett
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Sergiu Bodiu
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Fwdays
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
Padma Pradeep
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
Dubai Multi Commodity Centre
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Fwdays
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
BookNet Canada
Kürzlich hochgeladen
(20)
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
How To Create Custom DSLs By PHP
1.
PHP 関西勉強会 (2009/3/14) PHP
でメタプログラミング カスタム DSL 作成入門 株式会社アイテマン Piece Project 久保敦啓 <kubo@iteman.jp> Copyright © 2009 ITEMAN, Inc. All rights reserved. -1-
2.
メタプログラミングとは? 「他のプログラムや自分自身を記述し たり、操作するプログラムを記述す る」 -- 「ジェネレーティブプログラミング」より
Copyright © 2009 ITEMAN, Inc. All rights reserved. -2-
3.
メタプログラムとは? 「他のプログラムを記述したり操作し たりするプログラム」 -- 「ジェネレーティブプログラミング」より
Copyright © 2009 ITEMAN, Inc. All rights reserved. -3-
4.
メタプログラミング/メタプログラムの例 プログラムジェネレータ コンパイラ インタプリタ リフレクション アスペクト指向プログラミング (Aspect Oriented Programming) 言語指向プログラミング (Language
Oriented Programming) Copyright © 2009 ITEMAN, Inc. All rights reserved. -4-
5.
言語指向プログラミング 「言語指向プログラミングとは、ドメ イン特化言語を使ってソフトウェア構 築を行う一般的な開発スタイルのこと です。」 - http://capsctrl.que.jp/kdmsnr/wiki/bliki/?LanguageWorkbench より
Copyright © 2009 ITEMAN, Inc. All rights reserved. -5-
6.
ドメイン特化言語 「ドメイン特化言語(DSL:Domain Specific Language)とは、ある特 定の種類の問題に特化したコンピュー タ言語のことです。」 - http://capsctrl.que.jp/kdmsnr/wiki/bliki/?LanguageWorkbench
より Copyright © 2009 ITEMAN, Inc. All rights reserved. -6-
7.
ドメイン特化言語の例 TeX SQL Yacc Lex アクティブデータモデル XML 設定ファイル GUI ビルダ
Copyright © 2009 ITEMAN, Inc. All rights reserved. -7-
8.
言語指向プログラミング Intentional Software (Intentional
Software) MPS (JetBrains) Software Factories (Microsoft) Generative Programming Language Workbenches (Martin Fowler) Oslo (Microsoft) Copyright © 2009 ITEMAN, Inc. All rights reserved. -8-
9.
次期 Piece Framework
のアーキテクチャ Eclipse 抽象形 PHP abstract representation DSL スクリプト 保存 store 保存形 stored representation 復元 DSLの参照・編集 Piece_IDE with TMF 生成 generation ツリービュー 投影 projection PDT, The Language Toolkit, ... Piece Framework Webサービス Piece Framework ランタイムオブジェクト エディター 双方向の変更の反映 グラフィカルエディター 実行可能形 executable representation ソースコード、HTML ファイル、データベーススキーマ、... 編集可能形 editable representation Copyright © 2009 ITEMAN, Inc. All rights reserved. -9-
10.
PHP でカスタム DSL
を作成する 1. DSL の設計と Lexer および Parser の実装 2. セマンティックモデル (ドメイン モデル) の設計・実装 3. (オプション) Eclipse 上の DSL エディタの設計・実装 Copyright © 2009 ITEMAN, Inc. All rights reserved. - 10 -
11.
トランスフォーメーション
セマンティックモデル DSL スクリプト PHP スクリプト ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------ ------ Generate オプション Parse Populate AST Copyright © 2009 ITEMAN, Inc. All rights reserved. - 11 -
12.
DSL の設計と Lexer
および Parser の実装 1. 具体的な DSL スクリプトを書き ながら、 2. 同時に Parser を定義し、 3. 必要に応じて Lexer に手を加え て、 4. テストプログラムを実行する。 5. 以上を繰り返す Copyright © 2009 ITEMAN, Inc. All rights reserved. - 12 -
13.
Lexer Generator と
Parser Generator Lexer Generator - PHP_LexerGenerator Parser Generator - PHP_ParserGenerator - kmyacc + PHP 対応パッチ Copyright © 2009 ITEMAN, Inc. All rights reserved. - 13 -
14.
カスタム DSL の例 Employees.mapper
- Piece_ORM マッパー DSL association skills { table skills type manyToMany property skills } association computer { table computers type oneToOne property computer } method findByIdAndNote { query quot;SELECT * FROM $__table WHERE id = $id AND note = $notequot; } method findAllWithSkills1 { association skills } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 14 -
15.
Lexer 定義の例 MapperLexer.plex -
Piece_ORM マッパー DSL の Lexer 定義 ... /*!lex2php %input $this->_input %counter $this->_counter %token $this->token %value $this->value %line $this->line ID = /[a-zA-Z_][a-zA-Z_0-9]*/ WS = /[ trn]+/ STRING = /quot;[^[quot;]+quot;/ LCURLY = quot;{quot; RCURLY = quot;}quot; METHOD = quot;methodquot; ... SL_COMMENT = !//[^nr]*r?n! ML_COMMENT = !/*[^*]**+([^*/][^*]**+)*/! */ /*!lex2php %statename INITIAL ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 15 -
16.
Lexer 定義の例 MapperLexer.plex -
Piece_ORM マッパー DSL の Lexer 定義 ... /*!lex2php %statename INITIAL METHOD { if ($this->_debug) echo quot;found METHOD [ {$this->value} ]nquot;; $this->token = MapperParser::METHOD; } QUERY { if ($this->_debug) echo quot;found QUERY [ {$this->value} ]nquot;; $this->token = MapperParser::QUERY; } ORDER_BY { if ($this->_debug) echo quot;found ORDER_BY [ {$this->value} ]nquot;; $this->token = MapperParser::ORDER_BY; } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 16 -
17.
Parser 定義の例 MapperParser.y -
Piece_ORM マッパー DSL の Parser 定義 ... start ::= topStatementList. topStatementList ::= topStatementList topStatement. topStatementList ::= . topStatement ::= method. topStatement ::= association. method ::= METHOD ID(A) LCURLY methodStatementList(B) RCURLY. { if (array_key_exists(strtolower(A), $this->_methodDeclarations)) { throw new Exception(quot;Cannot redeclare the method [ {A} ] (previously declared on line quot; . $this->_methodDeclarations[ strtolower(A) ] . ')' ); } $this->_methodDeclarations[ strtolower(A) ] = $this->_mapperLexer->line; $this->_ast->addMethod(A, @B['query'], @B['orderBy'], @B['associations']); } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 17 -
18.
DSL ローダの実装 DSL ローダの制御フロー ... public
function load() { $this->_initializeAST(); $this->_loadAST(); $this->_loadSymbols(); $this->_createMapper(); } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 18 -
19.
DSL ローダの実装 AST (Abstract
Syntax Tree) の初期化 ... private function _initializeAST() { $this->_ast = new Ast(); foreach ($this->_metadata->getFieldNames() as $fieldName) { ... } $this->_ast->addMethod('findAll', 'SELECT * FROM $__table'); $this->_ast->addMethod('insert'); $this->_ast->addMethod('update'); $this->_ast->addMethod('delete'); } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 19 -
20.
DSL ローダの実装 Lexer と
Parser を実行し、DSL を AST に変換する ... private function _loadAST() { $mapperLexer = new MapperLexer(file_get_contents($this->_configFile)); $mapperParser = new MapperParser($mapperLexer, $this->_ast, $this- >_configFile); try { while ($mapperLexer->yylex()) { $mapperParser->doParse($mapperLexer->token, $mapperLexer->value); } } catch (Exception $e) { throw new Exception($e->getMessage() . quot; in {$this->_configFile} on line {$mapperLexer- >line}quot; ); } $mapperParser->doParse(0, 0); } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 20 -
21.
DSL ローダの実装 シンボルテーブルの作成とセマンティックモデルの作成 ... private function
_loadSymbols() { try { $this->_loadMethods(); } catch (Exception $e) { throw new Exception($e->getMessage() . quot; in {$this->_configFile}quot;); } } private function _createMapper() { $this->_mapper = new Mapper($this->_mapperID); foreach ($this->_methods as $method) { $this->_mapper->addMethod($method); } } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 21 -
22.
セマンティックモデル Operational Interface と
Population Interface ... // A operational interface public function executeQueryWithCriteria($methodName, $criteria, $isManip = false) { if (!$this->hasMethod($methodName)) { throw new Exception(quot;The method [ $methodName ] was not definedquot;); } $queryExecutor = new QueryExecutor($this, $isManip); return $queryExecutor->executeWithCriteria($this- >_getMethod($methodName)->getName(), $criteria); } // A population interface public function addMethod(Method $method) { $this->_methods[ strtolower($method->getName()) ] = $method; } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 22 -
23.
AST クラスの実装 AST extends
DOMDocument ... class AST extends DOMDocument { public function addMethod($name, $query = null, $orderBy = null, $associations = null) { $id = strtolower($name); $xpath = new DOMXPath($this); $methodNodeList = $xpath->query(quot;//method[@id='$id']quot;); if (!$methodNodeList->length) { $methodElement = $this->appendChild(new DOMElement('method')); $methodElement->setAttribute('id', $id); $methodElement->setAttribute('name', $name); } else { $methodElement = $methodNodeList->item(0); } ... } ... Copyright © 2009 ITEMAN, Inc. All rights reserved. - 23 -
24.
トランスフォーメーション
セマンティックモデル DSL スクリプト PHP スクリプト ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------ ------ Generate オプション Parse Populate AST Copyright © 2009 ITEMAN, Inc. All rights reserved. - 24 -
25.
Eclipse 上の DSL
エディタの設計・実装 1. TMF (Textual Modeling Framework) にDSL グラマーを移植する。 (グラマー言語は選択可能) 2. 補完、バリデーション、リファクタリングなどを 実装する。 DSL エディタとツリービューの完成 Copyright © 2009 ITEMAN, Inc. All rights reserved. - 25 -
26.
Eclipse 上の DSL
エディタの設計・実装 3. ページフローやワークフローのように可視化が効 果的であればグラフィカルエディタも実装、TMF と 統合する。 2 Way モデリングの完成 Copyright © 2009 ITEMAN, Inc. All rights reserved. - 26 -
27.
Eclipse 上の DSL
エディタの設計・実装 4. PDT, Aptana など他のプラグインと協調できる ように拡張する。 双方向の変更の反映 Copyright © 2009 ITEMAN, Inc. All rights reserved. - 27 -
28.
おわりに
Copyright © 2009 ITEMAN, Inc. All rights reserved. - 28 -
29.
参考文献 Krzysztof Czarnecki, Ulrich
Eisenecker, Generative Programming: Methods, Tools, and Applications, Addison-Wesley Pub (Sd), 2000, ISBN 978-0201309775 津田 義史、今関 剛、朝比奈 勲訳、『ジェネレーティブプロ グラミング』、翔泳社、2008年、ISBN 978-4798113319 http://capsctrl.que.jp/kdmsnr/wiki/bliki/?DomainSpecificLanguage http://www.martinfowler.com/articles/languageWorkbench.html http://capsctrl.que.jp/kdmsnr/wiki/bliki/?LanguageWorkbench http://martinfowler.com/dslwip/index.html Copyright © 2009 ITEMAN, Inc. All rights reserved. - 29 -
Jetzt herunterladen