Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trying to write a DSL with Xtext to specify an XML-like language
Trying to write a DSL with Xtext to specify an XML-like language [message #1781902] Wed, 14 February 2018 13:41
Juha Kari is currently offline Juha KariFriend
Messages: 1
Registered: February 2018
Junior Member
I have been trying to implement in Xtext an XML-like domain specific language with two types of elements.

These two types of elements are: 1) XML-like elements with a namespace before a function name, and 2) HTML tags without a namespace.

An excerpt of this language:

--- begin example 1 ---

<namespace:function1 fooparam="$(var)" bazparam="xyzzy" barparam="123" />
<html>
<head>
<title>Test</title>
</head>
<body>
<namespace:function2 barparam="321">
<p>Some random text...</p>
</namespace:function2>
</body>
</html>


--- end example 1 ---

I would like to write a DSL specification in Xtext for this language to validate written code against the specification.

It would be important to make difference between the two types of elements. I want to ignore HTML tags and their content but validate XML-like elements with namespaces according to the DSL specification.

Following is my first attempt to write the DSL specification in Xtext:

--- begin example 2 ---

grammar foo.bar.test.testweb.TestWeb with org.eclipse.xtext.common.Terminals

generate testDsl "here would be the url to testDsl"

Model:
statements+=Statement*;

Statement:
BasicStatement | OtherStatement;

BasicStatement:
'<namespace:' FunctionCall ('/')? '>' ((cdata=ANY_OTHER) ('</namespace:' (function=ID) '>'))?;

OtherStatement:
'<' (tagbegin=ID) ('/')? '>' ((cdata=ANY_OTHER) ('</' (tagend=ID) '>'))?;

FunctionCall:
functionCall=function1 | function2;

function1:
{function1} 'function1' parameters+=function1Parameters*;

function1Parameters:
('fooparam' | 'barparam' | 'bazparam') '=' (value = STRING);

function2:
{function2} 'function2' parameters+=function2Parameters*;

function2Parameters:
('fooparam' | 'barparam' | 'bazparam') '=' (value = STRING);


--- end example 2 ---

However, this Xtext code does not work as I want.

Can you help me in fixing this DSL specification to describe the language in first example of this post?

Previous Topic:Clickable link in LabelProvider
Next Topic:generated ParsetreeConstructor file doesn't compile after upgrade from xtext 2.9.2 to xtext 2.13
Goto Forum:
  


Current Time: Thu Mar 28 19:15:03 GMT 2024

Powered by FUDForum. Page generated in 0.03253 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top