DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
Â
Re-engineering Eclipse MDT/OCL for Xtext
1. Re-engineering Eclipse MDT/OCL
for Xtext
Edward D Willink
MDT/OCL Project Lead
Eclipse Modeling Project
MODELS 2010
Workshop on OCL and Textual Modeling
3rd October 2010
2. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 2
Overview
â Eclipse MDT/OCL evolution to use Xtext
â Xtext impact
â Xtext/LPG performance comparison
â Xtext-mandated changes of approach
â Xtext-motivated revisions
3. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 3
MDT/OCL Evolution
Java API
OCL expressions
reuse by
QVT, MOFM2T
realisability
OCL spec
validation
OCL spec
useability
editors/evaluators
compliance
OCL spec
Custom Standard Library
Standard Library Editor
Essential OCL Editor
Complete OCL Editor
OCL in Ecore Editor
Missing OCL Meta-Models
Correct OCL Meta-Models
Complete OCL Meta-Models
Pivot Meta-Model
Evaluator
4. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 4
Adding Editors to MDT/OCL
â First attempt used basic SWT framework
â Second attempt used IMP
â re-uses existing LPG LALR parsers
â inherited realisation of editing idioms (highlighting)
â Third attempt uses Xtext
â requires migration to LL parser (ANTLR)
â inherited modeled generation of editing idioms
â modeled generation of syntactical constructs
â Contrast old LPG+IMP with new Xtext approach
5. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 5
Basic Parser Architecture
â Lexer: Text -> Tokens
â Parser: Tokens -> CST Nodes
â Analyzer: CST Nodes -> ASG Nodes
â Validator: ASG Nodes -> Diagnostics
[OCL is complex: CST very different to ASG]
6. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 6
LPG Parser with IMP Editor
â Manual provision of
â 2 lexer grammars and 1 parser grammar
â parser action code to populate CST
â Auto-generation of
â lexer, LALR parser
7. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 7
Xtext Parser and Editor Support
â Manual provision of
â combined parser grammar
â optional CST meta-model
â Auto-generation of
â lexer, LL parser, and analyzer framework
â editor with rich model-driven features
â Validation using CHECKS language or Java
8. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 8
LPG Action Code
â CollectionRange: 1..10
â CST access woven into code
â not checked till Java compiled/run
â Significant and repetitive actions
â fragile policies, casts, magic numbers
CollectionRangeCS ::= OclExpressionCS '..' OclExpressionCS
/.$BeginCode
CollectionRangeCS result = CSTFactory.eINSTANCE.createCollectionRangeCS();
result.setExpressionCS((OCLExpressionCS)getRhsSym(1));
result.setLastExpressionCS((OCLExpressionCS)getRhsSym(3));
setOffsets(result, (CSTNode)getRhsSym(1), (CSTNode)getRhsSym(3));
setResult(result);
$EndCode
./
9. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 9
Xtext 'Action Code'
CollectionRange: 1..10
â CST woven into grammar
â declarative: checkable / generateable
â No code
â In practice, two productions can be merged
CollectionLiteralPartCS ::= expressionCS=OclExpressionCS
('..' lastExpressionCS=OclExpressionCS)?
CollectionRangeCS ::= expressionCS=OclExpressionCS '..'
lastExpressionCS=OclExpressionCS
10. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 10
Cross-references
PathName A::B::c
â LPG - cross-reference is an unresolved String
â left recursion
â Xtext - cross-reference is a resolved EObject
â No code, CST Declarations woven into grammar
â EObject Reference Declarations woven into grammar
â =, += and ?= CS assignments
â (), *, +, ? BNF operators
pathNameCS ::= Identifier
/* Code not shown */
pathNameCS ::= pathNameCS '::' Identifier
/* Code not shown */
pathNameCS returns PathNameExpCS:
(namespace+=[Namespace|Identifier] '::')*
element=[NamedElement|Identifier];
11. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 11
Cross-reference impact
â Cross-reference requires analysis
â to locate the Namespace for an Identifier
â Xtext provides a default scope resolution
â OCL defines explicit Environment lookup
pathNameCS returns PathNameExpCS:
(namespace+=[Namespace|Identifier] '::')*
element=[NamedElement|Identifier];
12. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 12
Performance : Grammar Size
â Simple examples
â Xtext line count is three times smaller
â MDT/OCL 3.0.0 implementation comparisons
â Similar real application, similar editorial style
â Xtext at least 5 times smaller
â and it autogenerates an editor too
Line counts LPG 2.0.17 Xtext 1.0.0
Lexer grammars 251
395Parser grammar 1485
Templates 1000 library
Java support 1040+library library
Total ~2800 ~400
13. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 13
Performance : Parser Size
â MDT/OCL 3.0.0 implementation comparisons
â Similar grammar
â Xtext about 10 times larger
â different grammar generated for editor
â extra completion assist functionality
â another 1MB
class file sizes LPG 2.0.17 Xtext 1.0.0
Lexers and Parsers 221 kB 2370 kB
Semantic analysis excluded excluded
Total ~220 kB ~2400 kB
14. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 14
Performance : Speed
â 350 line Complete OCL example (Royal & Loyal)
â MDT/OCL 3.0.0 implementation comparisons
â Similar real application, same example
â Xtext about 11 times slower
Time in milliseconds LPG 2.0.17 Xtext 1.0.0
First parse 1800 4800
Files read for first parse 2 6
Average of 100 reparses 97 1114
Files read for reparse 1 1
15. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 15
Performance: Summary
â Xtext is 5 times smaller source size
â fundamental technology advance
â massive ergonomic gain
â Xtext is 10 times larger classes sizes
â Xtext is 11 times slower execution
â Xtext 1.0.0 is not perfect
â maybe better in Xtext 2.0
â use of ANTLR and LL is not fundamental
â maybe a conversion to LALR is appropriate
â size, at least, very sensitive to grammar approach
16. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 16
Left Recursion
â LALR uses left recursion extensively
â ANTLR can only right recurse, but in Xtext
â recursion replaced by repetition
multiplicativeCS ::= unaryCS
multiplicativeCS ::= multiplicativeCS '*' unaryCS
...
multiplicativeCS ::= multiplicativeCS '/' unaryCS
...
multiplicativeCS: unaryCS (('*'|'/') unaryCS)*;
17. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 17
Lookahead in OCL
a->b(c,d could be
a->b(c,d|e an IteratorExpCS
a->b(c,d,e an OperationCallExpCS
[iterator names (e.g. b) are not reserved/known]
â Difficult, inelegant to disambiguate with LALR(1)
â compile time integrity check
â Must use backtracking in LL
â Xtext hides any ANTLR checking
â use an LALR copy for checking
18. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 18
Flexible operation parsing 1
Concrete Syntax parsed as a larger language
ID ('.'|'->') ID '('
(expr (':' type)?
(',' expr (':' expr)?)*
(';' expr)*
('|' expr (',' expr)*)?
)?
')'
â a.b(c=5:d,e;f|g,h) is parsed successfully
â a semantic rather than syntactic error
19. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 19
Flexible operator parsing 2
OCL 2.0 and 2.2 (and QVT) change precedences
â different grammars
â one larger flexible grammar
infixOp ::= 'and'|'or'|'xor'|'implies'|'+'|'*'....
prefixOp ::= 'not'|'-'
expr ::= unary (infixOp unary)*
unary ::= (prefixOp)* atomic
all operators parsed with equal precedence
â 'standard' library defines precedence, associativity
â semantic analysis uses 'standard' library
â 5 fold reduction in ANTLR class sizes
â solves 65536 byte class size limit
20. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 20
Summary
â Xtext facilitates an IDE for Eclipse MDT/OCL
â Xtext does many things very well
â Xtext cannot emulate all traditional approaches
â Xtext seems to have a better way
â Xtext motivates a major rethink
21. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 21
Active OCL Participation
Open Source
Individual participation
Original code from IBM
maintained by IBM until 2009
(Christian Damus)
Intellectual Property checks
Eclipse/Modeling/MDT/OCL OMG OCL 2.3 RTF
Mariano Belaunde
(France Telecom)
Edward Willink (Thales part-time)
Adolfo SĂĄnchez-Barbudo Herrera (Open Canarias)
2 others IBM, NIST, SAP, Fujitsu
Borland, 88Solutions
lead
chair
Open Specification
Corporate participation
23. 3-Oct-2010 Re-Engineering Eclipse MDT/OCL for Xtext 23
OCL-driven validation
â Eclipse Helios adds Validation Delegate support
â OCL can be embedded in Ecore annotations
â OCL is then executed during model validation
â this works in Xtext
â Add a validation reason to Complete OCL
â Add OCL to Java code generation
â avoid performance penalties
context MyClass
inv UpperCaseName
(''' + name + '' is not uppercase in ' + toDiagnostic())
: name.toUpperCase() = name