Tree Parsing in the Eclipse Modeling Framework with Ecore Metamodel
I am trying to write a plugin to the Open Source AADL Tool Environment (OSATE) which is a plugin to Eclipse to parse an annex sublanguage. Â (AADL is Architecture Analysis and Design Language for embedded systems. Â AADL allows definition of custom annex sublanguages for which OSATE will invoke a custom parser.) Â OSATE itself parses AADL generating trees conforming to an Ecore/EMF metamodel defined using the Topcased graphical Ecore editor. Â OSATE expects custom annex sublanguage parsers to generate EMF as well.
The example AADL annex sublanguage plugin uses ANTLR (v2) to define a parser which constructs an abstract syntax tree with tree nodes generated by factories automatically generated from the Ecore metamodel: http://la.sei.cmu.edu/aadl-wiki/index.php/Sublanguage_Example
The hand-written example unparser tests EMF tree nodes using "instanceof".
I wrote a parser for my annex sublanguage using ANTLR v3 that generates ASTs of nodes that are a subclass of CommonTree, and an unparser using a tree parser that invokes string templates. Â My test rig reads files, parses and unparses, and writes pretty-printed files that look great.
I can't figure out how to create an Ecore metamodel that implements the Tree interface so that an ANTLR v3 tree parser can walk them. Â Ecore/EMF defines everything with its own E-objects (EClass, EPackage, EDataType, EString, EOperation, etc.).
ANTLR v3 tree parsers are perfect for testing whether an AST has a certain form or property, and for building a new AST while walking another one.
How can I get ANTLR v3 tree parsers to walk EMF trees?