0

I am writing a project using Eclipse xtext framework. I want to make a grammar for XML language.

How can I parse open and close tags ?

When I give something like this:

Body: '<'Type'>''</'type=[Type]'>';

Type: name=ID;

It allows to have tags like that:

<foo></foo> <bar></foo>

I would like to have only the possibility like that:

<foo></foo> <bar></bar>

What is the best way to do that?

ruhungry
  • 4,506
  • 20
  • 54
  • 98

1 Answers1

3

I'd just parse any identifier in the closing tag and do a validation after parsing.

Element : 
  '<' type=[Type] '>
    children+=Element*
  '</' closingTagName=ID '>';

You'd also need to adjust content assist accordingly.

Sven Efftinge
  • 3,065
  • 17
  • 17