3

So I have the default example of a xtext grammar.

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
    greetings+=Greeting*;

Greeting:
    'Hello' name=ID '!';

I'd like to view the abstract syntax tree - in particular I'd like the corresponding xtend file, which looks like

package org.xtext.example.mydsl.generator

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess

class MyDslGenerator implements IGenerator {

    override void doGenerate(Resource resource, IFileSystemAccess fsa) {
        //TODO implement me
    }
}

To printout a textual version of the AST whenever doGenerate is called. I've been hacking at this for about two days and I'm clearly missing something fundamental - someone take pity on me? What would go in the doGenerate Function?

Joe
  • 4,367
  • 7
  • 33
  • 52

1 Answers1

0

The parameters of the doGenerate functions are the EMF-based resource (basically a model representation of the textual file - in other words, an AST with the links resolved) and a helper class for writing into the file system.

The generators task is to create the generated source code (typically Java, but that is not required). For an example, see the blog post http://www.rcp-vision.com/?p=1573 - at the end there is a sample code generator used.

Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37