0

I have the following Xtext2 grammar:

Bibliography:
  macros += Macro*
;

Macro:
  "@string{" name = ID "=" value = LATEXSTRING "}"
;

terminal LATEXSTRING:
  '"' (!('"'))* '"' 
;

When parsing a the string

@string{ABBREV = "Some Long Text"}

and storing it in some object macro of type Macro it has the following values:

macro.name: ABBREV
macro.value: "Some Long Text"

both of type String (EString). I would like to have the value without quotes though. How can I achieve that?

Mathias Soeken
  • 1,293
  • 2
  • 8
  • 22

1 Answers1

1

You have to register a value convert for the rule LATEXSTRING. According to the docs, it should look like this:

@Inject
private LatexStringConverter latexStringConverter; 

@ValueConverter(rule = "LATEXSTRING")
public IValueConverter<String> converterForLatexString() {
  return latexStringConverter;
}

with

public class LatexStringConverter extends AbstractLexerBasedConverter<String> {
  @Override
  protected String toEscapedString(String value) {
    ..      
  }

  public String toValue(String string, INode node) {
    ..
  }
}
Sebastian Zarnekow
  • 6,609
  • 20
  • 23
  • That is exactly what I needed. I also found some source code at http://code.google.com/p/protobuf-dt/source/browse/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/?name=26c3a4fce05f&r=26c3a4fce05fa9a6ccf8322064f8876ece6e1e91 that shows how to apply it. – Mathias Soeken Jul 12 '12 at 13:28