简体   繁体   中英

Eclipse xtext- Xml grammar

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM