Xtext Documentation.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Xtext Documentation September 26, 2014 Contents I. Getting Started 9 1. 5 Minutes Tutorial 10 1.1. Creating A New Xtext Project . 10 1.2. Generating The Language Infrastructure . 10 1.3. Try The Editor . 11 1.4. Conclusion . 12 2. 15 Minutes Tutorial 14 2.1. Create A New Xtext Project . 14 2.2. Write Your Own Grammar . 16 2.3. Generate Language Artifacts . 19 2.4. Run the Generated IDE Plug-in . 20 2.5. Second Iteration: Adding Packages and Imports . 20 3. 15 Minutes Tutorial - Extended 27 3.1. Writing a Code Generator With Xtend . 29 3.2. Unit Testing the Language . 34 3.3. Creating Custom Validation Rules . 35 4. Five simple steps to your JVM language 37 4.1. Step One: Create A New Xtext Project . 38 4.2. Step Two: Write the Grammar . 38 4.3. Step Three: Generate Language Artifacts . 43 4.4. Step Four: Define the Mapping to JVM Concepts . 43 4.5. Step Five : Try the Editor! . 48 II. Seven JVM Languages Built With Xbase 50 5. Introduction 51 5.1. Write the Grammar . 51 5.2. Map to Java . 51 5.3. CAUTION: This is Provisional API . 52 5.4. Common Requirements . 52 5.5. Getting the Code . 53 2 5.6. A Short Xtend Primer . 53 6. Scripting Language 57 6.1. Overview . 57 6.2. Running the Example . 58 6.3. Grammar . 58 6.4. Translation to Java . 59 7. Build Language 61 7.1. Overview . 61 7.2. Running the Example . 62 7.3. Grammar . 62 7.4. Translation to Java . 63 7.5. Validation . 65 7.6. Imports . 66 7.7. Operator Overloading . 67 7.8. Run as... Integration . 67 8. DSL for MongoDB 68 8.1. Overview . 69 8.2. Running the Example . 70 8.3. Grammar . 70 8.4. Translation to Java . 72 8.5. Qualified Name Provider . 77 8.6. Validation . 78 8.7. IDE Enhancements . 79 9. DSL for Guice 81 9.1. Overview . 81 9.2. Running the Example . 82 9.3. Grammar . 83 9.4. Translation to Java . 84 9.5. Validation . 88 10.Http Routing Language 89 10.1. Overview . 89 10.2. Running the Example . 90 10.3. Grammar . 90 10.4. Translation to Java . 91 11.Template Language 95 11.1. Overview . 95 11.2. Running the Example . 96 11.3. Grammar . 96 11.4. Translation to Java . 97 3 11.5. Extending the Compiler . 100 11.6. Type Computation . 102 11.7. Value Converter . 103 11.8. Content Assist . 103 11.9. Syntax Highlighting . 104 12.Little Tortoise 105 12.1. Overview . 105 12.2. Running the Example . 107 12.3. Grammar . 107 12.4. Translation to Java . 108 12.5. Interpreter . 109 12.6. Literal Classes . 111 III. Reference Documentation 112 13.Overview 113 13.1. What is Xtext? . 113 13.2. How Does It Work? . 113 13.3. Xtext is Highly Configurable . 113 13.4. Who Uses Xtext? . 114 13.5. Who is Behind Xtext? . 114 13.6. What is a Domain-Specific Language . 114 14.The Grammar Language 116 14.1. A First Example . 116 14.2. The Syntax . 118 14.2.1. Language Declaration . 118 14.2.2. EPackage Declarations . 118 14.2.3. Rules . 123 14.2.4. Parser Rules . 127 14.2.5. Hidden Terminal Symbols . 134 14.2.6. Data Type Rules . 135 14.2.7. Enum Rules . 136 14.2.8. Syntactic Predicates . 137 14.3. Ecore Model Inference . 138 14.3.1. Type and Package Generation . 138 14.3.2. Feature and Type Hierarchy Generation . 139 14.3.3. Enum Literal Generation . 140 14.3.4. Feature Normalization . 140 14.3.5. Error Conditions . 141 14.4. Grammar Mixins . 141 14.5. Common Terminals . 142 4 15.Configuration 144 15.1. The Language Generator . 144 15.1.1. A Short Introduction to MWE2 . 144 15.1.2. General Architecture . 146 15.1.3. Standard Generator Fragments . 149 15.2. Dependency Injection in Xtext with Google Guice . 149 15.2.1. The Module API . 150 15.2.2. Obtaining an Injector . 152 15.3. Continuous Integration (with Maven) . 153 15.3.1. An overview of the example projects . 153 15.3.2. Building an Xtext language with Maven and Tycho . 153 15.3.3. Integration in Standard Maven Builds . 157 16.Runtime Concepts 159 16.1. Runtime Setup (ISetup) . 159 16.2. Setup within Eclipse-Equinox (OSGi) . 159 16.3. Logging . 160 16.4. Code Generation / Compilation . 160 16.4.1. IGenerator . ..