410 likes | 712 Views
Elevator Simulator DSL Project. Presented by Miguel Garzón and Stéphane Leblanc. Elevator Simulator. Framework to test the behaviors of elevators in different scenarios Open Source (LGPL) Java Project Authors: Neil McKellar and Chris Dailey
E N D
Elevator SimulatorDSL Project Presented by Miguel Garzón and Stéphane Leblanc
Elevator Simulator • Framework to test the behaviors of elevators in different scenarios • Open Source (LGPL) • Java Project • Authors: Neil McKellar and Chris Dailey • More details can be found athttp://elevatorsim.sourceforge.net/
Elevator Simulator DSL • Domain Specific Language (DSL) over the Elevator Simulator API • Allow to create elevator simulation scenarios
Introductory Example • View the example
Goals of the DSL • Easy to read • Concise • Easy to write • Maintainable • Easy to parse
Target Audience • Developers • Who want to create scenarios for the Elevator Simulator • Who want to look at a DSL implementation example • Non-programmers not taken into account
DSL Metamodel (2) • User Variables
DSL Creation Technology (2) • Eclipse IDE The Elevator Simulator DSL is deeply integrated with Eclipse. Our DSL comes in the form of an Eclipse Plug-in.
DSL Creation Technology (3) • Xtext for definition of BNF Grammar and Metamodel generation.Xtext is an Eclipse-based DSL generator that was released in 2006 and is built on top of Antlr and other famous Eclipse projects. • One can create Xtext Projects from ecoremodel or a grammardefinition.
Xtext- Generated Artefacts xText OPTIONAL BNF GRAMMAR SEMANTIC MODEL (ECORE) Generates Generates EDITOR PARSER
Xtext- Generated Artefacts xText PARSER EDITOR SEMANTIC MODEL (ECORE) BNF GRAMMAR EMF Model Code
EMF Code Generation • The generated code will consists out of the following: • Interfacesand the Factory to create the Java classes • Concrete implementation of the interfaces defined in model • Utilities • Possibility to modify and extend generated code. • Code that is explicitly marked as @generated NOT is not overwritten.
Xtext- DSL Processing xText EDITOR PARSER BNF GRAMMAR SEMANTIC MODEL (ECORE) Generated Interpreted ESIM file Generated Java Class
DSL Creation Technology (4) • JET (Java Emitter Templates):For Code Generation. • JET will be used to translate our domain specific language into Java classes representing the scenarios that will work with the Elevator Simulator.
JET (Java Emitter Templates) <%@ jet package="org.intranet.sim.dsl.codegen" class="ScenarioGenerator" imports="org.intranet.sim.dsl.scenarioGenerator.*" skeleton="generator.skeleton" %> <% Model model = (Model) argument; Scenario scenario = model.getScenario(); String displayName = scenario.getDisplayName(); String className = scenario.getName(); ... %> public class <%=className%> extends Simulator { … }
Xtext Features (1) • Code Completion • Syntax Highlighting • Linking • Scoping • IntelliSense • Quick Fix • Warnings
Xtext Features (2) • Test cases: (for testing the editor)
Xtext Features –Validation (1) • Semantic Validation: From OCL constraints defined in the Ecore Model, validation code is generated.
Extension Points • Eclipse provides the concept of "extension points“. • Elevator Simprovides menu actions, icons to enhance the user experience. • org.eclipse.ui.actionSets
Semantic Error: Makes No Sense Semantic Error: Makes No Sense
Strategies for LanguageEvolution (1) • Incremental Migrations[FowlerMig] V1.1 V1.0 V2.0
Strategies for LanguageEvolution (2) • Model-based migrations [FowlerMig] V1.0 V2.0 V1.1
Strategies for LanguageEvolution (3) • Maintain backward compatibility (Selected) V2.0 V1.1 V1.0
Conclusion • Elevator Simulator DSL simplifies the creation of scenarios • Powered by XText • Allows for model interpretationand for code generation
References • [FowlerDsl] Martin, Fowler, Domain-specificlanguage, ISBN 0321712943 • [FowlerMig] Fowler, Martin, DSL Migration, 2009/02/05http://martinfowler.com/bliki/DslMigration.html • Bell, Peter, DSL Evolution, 2009/12/22http://www.infoq.com/articles/dsl-evolution • Tolvanen, JP, DSL in Practice, 2008/12/07, Software Engineering Radio, episode 119http://www.se-radio.net/?s=DSL