SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An...
-
Upload
abbigail-pacer -
Category
Documents
-
view
214 -
download
0
Transcript of SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An...
![Page 1: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/1.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Bottom Up Creation of a DSL Using JSON Templates
An workbench with a novel editor
http://ltiwww.epfl.ch/BUDE
1
![Page 2: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/2.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Javascript object
JSON
Generated filesGenerated files
TemplateTemplateTemplateTemplate
Descriptionfile
Descriptionfile
Generated filesGenerated files
Template Based Development Environment
2
ExpansionExpansion
Editor / generatorTemplateTemplate Enhanced object
Specification objectSpecification object
Enhancement
SourceSourceGenerationGeneration
DSLcompiler
DSLcompiler
![Page 3: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/3.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
The JSON Objects and the Templates(Introduction)
3
1. JSON expansion
2. Templates
3. Specification object
4. Description file
![Page 4: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/4.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
ExpansionExpansion
Principle of the Expansion of the JSON Templates!
4
a: [ {item: "carots", price: 12}, {item: "onions", price: 20}, {item: "spinachs", price: 15} ]
a: [ {item: "carots", price: 12}, {item: "onions", price: 20}, {item: "spinachs", price: 15} ]
{.repeated section a}The price of {item} is {price} RS{.end}
{.repeated section a}The price of {item} is {price} RS{.end}
The price of carots is 12 RSThe price of onions is 20 RS The price of spinachs is 15 RS
The price of carots is 12 RSThe price of onions is 20 RS The price of spinachs is 15 RS
Resulting page
JSON description
Template
http://json.org
![Page 5: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/5.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Template Commands
{name}
{.section name} {.or}
{.end}
{.repeated section name}{.or} {.alternates with}
{.end}
{.include "filename"}
5
![Page 6: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/6.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
JSON (Javascript) Objects are recursive
6
{ create : { id : "customer", inputVar : "customerName", attributes : [ { intAttribute : { varName : "number" } } ] } [ . . . ] array} { . . . } object
![Page 7: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/7.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Empty Attribute: conditional generation
7
{ create : { id : "customer", selector: { }, inVar : "cName" }}
{.section selector} String {inVar};{.end}
{ create : { selector: { id : "customer", inVar : "cName" } }}
// same code generated// with both objects
![Page 8: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/8.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Ordered Sequence
8
attributes : [ { stringAttribute: { varName : "name" } }, { intAttribute: { varName : "number" } } ]
public class Customer { String name = ""; int number = 0;}
{.repeated section attributes} {.section intAttribute} int {varName} = 0; {.end} {.section stringAttribute} String {varName} = ""; {.end}{.end}
ExpansionExpansion
![Page 9: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/9.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Other Example
9
dataTables : [ { id : "customer", attributes : [ { stringAttribute: { varName : "name", finder: { } } }, { intAttribute: { varName : "number" } } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] }
public class Customer { String name = ""; int number = 0;
public static findByName(String name) { query = "select * from customer where name='"+name+"'"; result = execute(query); }
@OneToMany public Collection confirmedOrder;}
Result of the expansion
![Page 10: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/10.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Generation of an Application (requires a set of files)
10
{ dataTables: [ { id : "customer", inpVar : "custName" } ]}
{ dataTables: [ { id : "customer", inpVar : "custName" } ]}
aaa bbb abcd cccddd
aaa bbb abcd cccddd
aaa bbb abcd cccddd
aaa bbb abcd cccddd
aaa bbb abcd ccc ddd
aaa bbb abcd ccc ddd
class Customer { String customerName;}
class Customer { String customerName;}
ExpansionExpansion
{.section create} class {Id} { String {inpVar}} {.end}
{.section create} class {Id} { String {inpVar}} {.end}
File description
foreach dataTables expand "dataTemplate.java" to "src/data/"+Id+".java"
for whole expand "taskTemplate.java" to "src/data/Task.java"
![Page 11: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/11.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Our Enhancements to the Specification Object
11
![Page 12: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/12.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Computation of the Object Arguments
12
TemplateTemplate
Generated files
ExpansionDescriptionfile
Extended specification objectExtended specification objectTemplates
Generated files
Specification objectSpecification object
Enhancement
Computations are made in the specification object, not in the templates
![Page 13: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/13.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Computation of Object Arguments
13
{ create : { id : "customer", Id : "Customer",
inputVar : "customerName", InputVar : "CustomerName",
attributes : [ { intAttribute : { varName : "number" }, _index : "0" } ],
myObject : "CUSTOMER_NAME" }}
{ create : {
id : "customer",
inputVar : "customerName",
#attributes : "dataTables[customer].attributes",
#myObject : "myMethod(inputVar)"}
uppercase {equals (id, inputVar)}
![Page 14: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/14.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
BUDE: an Eclipse Plugin
14
Double-click: selection of a file
![Page 15: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/15.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
BUDE
15
selectionmarked if found
highlighted if error
![Page 16: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/16.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Scope of the approach
• Intra-file levelduplication of parts such as menus and sub-menus in a GUI
• Application levelduplication of files and repetitive components within the files
• Architecture levelextension of an application, creation of another
application from a set of predefined components
16
![Page 17: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/17.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
More Examples
17
1. Tutorial , tutorial file
2. Menus and submenus in a GUI (intra-file)
3. General Ressort (application level)
4. The DSL compiler itself
![Page 18: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/18.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
2) Menus of a GUI
18
private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JMenuBar GUIMenuBar = null;
{.repeated section menus} private JMenu j{id}Menu = null; {.repeated section items} private JMenuItem j{itemId}Item = null; {.end}{.end}
{ menus : [ { id : "Files", items : [ { itemId: "Load" }, { itemId: "Save" } ] } , { . . . } ]}
ExpansionExpansion
![Page 19: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/19.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
TaskTask
3) A Workflow: Company General Ressort
19
Customer name
Customer record
Customer part id
Part record
Confirmed order
Customer order
(paper)
found
create
found
create
enter
enter
createR
not
not
PreconditionsPreconditions(work with A.Wegmann and B.Bajic)
![Page 20: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/20.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Implementation
x
![Page 21: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/21.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
List of the Entity Names
21
roles actions temporary variables data tables
secretary enterCustomerName customerName Customer
findCustomer customerPartId name
createCustomer number
enterCustomerData Part
enterCustomerPartId partID
findPart ConfirmedOrder
engineer createPart comment
enterPartData ManyToOne customer
ManyToOne part
![Page 22: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/22.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Specification Object
22
{ application : { version_id : "memory", memory: { }, database : "test", username : "" }, dataTables : [ { id : "customer", attributes : [ { stringAttribute: { }, varName : "name", finder }, { intAttribute: { }, varName : "number" } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] }, { . . .
actions : [ { enterAndFind, inputVar : "customerName", #insert : "dataTables[customer]" precondition : [ { stringNotAvailable : "customerPartId" } ] }, { create, inputVar : "customerName", #insert : "dataTables[customer]", transfers : [ { fromAttribute : "customerName", toAttribute : "name" } ], precondition : [ { stringAvailable : "customerName" }, { recordNotAvailable : "customer" } ], #enterAttr : "setSubtract(attributes,\"varName\" ,attributes,\"finder.varName\")" }, { . . .
![Page 23: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/23.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Specification Object: Continuation
23
roles : [ { id : "secretary", roleActionList : [ { #enterAndFind : "actions[enterAndFind.customer]" }, { #create : "actions[create.customer]" }, { #enterAndFind : "actions[enterAndFind.part]" }, { confirmed : { #dataTables : "dataTables" } } ] }, { id : "engineer", roleActionList : [ { #create : "actions[create.part]" } ] } ]
![Page 24: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/24.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Architecture
24
HomePage.jsp
createIdRecord.jsp
logicData.java
enterInputVar.jsp
EnterIdData.jsp
IdRole.jsp
Manager.jsp
jump to
calls
logicServlet.java
![Page 25: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/25.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Description File
25
output directory ".." // relative to the directory of this file
uppercase {equals (id, tableName, inputVar, varName, to)}
foreach dataTables, application expand application.version_id + "/Customer.java" to "src/data/"+Id+".java"
for whole expand application.version_id+"/Task.java" to "src/data/Task.java"
for whole expand "business/LogicServlet.java" to "src/business/LogicServlet.java"
for whole expand "business/LogicData.java" to "src/business/LogicData.java"
foreach roles, actions, dataTables expand "WebContent/SecretaryRole.jsptmpl" to "WebContent/"+Id+"Role.jsp"
for whole expand "WebContent/ERP.jsptmpl" to "WebContent/ERP.jsp"
foreach actions where enterAndFind != null expand "WebContent/Enter.jsptmpl" to "WebContent/Enter"+InputVar+".jsp"
foreach actions where createRecord != null expand "WebContent/CreateRecord.jsptmpl" to "WebContent/Create"+Id+".jsp"
foreach actions where create != null expand "WebContent/EnterData.jsptmpl" to "WebContent/Enter"+Id+"Data.jsp"
for whole expand "WebContent/Manager.jspTmpl" to "WebContent/Manager.jsp"
for application, dataTables where JPA!=null expand "JPA/persistence.xmlTmpl" to "src/META-INF/persistence.xml"
copyfile "WebContent/web.xml" "WebContent/WEB-INF/web.xml"copyfile "JPA/Manager.java" "src/weblangUtils/Manager.java"copyfile "SQL/DBConnection.java" "src/weblangUtils/DBConnection.java"copydir "lib" "/WebContent/WEB-INF/lib"
![Page 26: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/26.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
4) DSL : tables
26
dataTable customer { finder string name; int number; OneToMany to confirmedOrder}dataTable part { finder string partId; string grPartInfo; OneToMany to confirmedOrder}dataTable confirmedOrder { string comment; ManyToOne to customer ManyToOne to part}
dataTables : [ { id : "customer", attributes : [ { stringAttribute, varName : "name", finder }, { intAttribute, varName : "number" } ], relationships : [ { OneToMany : { to : "confirmedOrder" } } ] }, {
![Page 27: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/27.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Creation of the DSL
27
Specification Object
Specification Object
Linear ObjectLinear Object
DSL Template
DSL Template
SourceSource
ASTAST
CompilerCompiler
![Page 28: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/28.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Compiler – JavaCC(generated by templates)
28
{ "attributes" "{" ( // guarded object obj = stringAttributeProd()
{ ((JSONObject)obj).names.add(0,"stringAttribute"); ((JSONObject)obj).objects.add(0,new Highlight()); }
{ attributes.put(obj); } | obj = intAttributeProd()
{ ((JSONObject)obj).names.add(0,"intAttribute"); ((JSONObject)obj).objects.add(0,new Highlight()); }
{ attributes.put(obj); } )+ "}" { return attributes; }}
optimisation of the language
![Page 29: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/29.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
actions { enterAndFind { inputVar customerName table customer precondition { stringNotAvailable customerPartId } } enterAndFind { . . . } create { inputVar customerName tableToCreate customer transfers { from customerName to name; } precondition { stringAvailable customerName recordNotAvailable customer } } create { . . . } createRecord { . . . }}
General Ressort DSL: actions and roles
29
roles secretary { enterAndFind customer enterAndFind part create customer createRecord confirmedOrder } roles engineer { create part }
![Page 30: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/30.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Remarks About the Approach
30
• The description file provides the list of all the kinds of components and defines thus the architecture
• The specification object gives the customer's view
• The templates implement the platform view
![Page 31: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/31.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Generation of Web Applications
• RAD tools: Eclipse/WTP, Ruby on Rails, Spring Roo, Tutorials (quick start + copy and paste)
• Successful former experience with WebLang
• A Web application built with our approach and using either SQL, JPA, JSF or PHP from the same object
31
![Page 32: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/32.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Conclusions
• The approach only uses elementary statements (like if then else or inherit)
• No specific library or package required – only (visible) templates
• Templates have been pulled out of the RAD tool and transferred into the developer's space
• These templates are highly customizable and reusable
32
![Page 33: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/33.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Conclusion's Conclusion
• Programming languages have been developed layer after layer: Modula, Java, Scala (procedure, object, inheritance, genericity, annotations)
• A simple version of DSM can be developed from the JSON templates and make a greater leap forward
33
![Page 34: SPLASH-DSM'11 Faculté I&C, Claude Petitpierre Bottom Up Creation of a DSL Using JSON Templates An workbench with a novel editor .](https://reader036.fdocuments.in/reader036/viewer/2022062511/551c2c74550346ad4f8b60ee/html5/thumbnails/34.jpg)
SPLASH-DSM'11 Faculté I&C, Claude Petitpierre
Demo ?
(Eclipse/TutorialExample)
34