Trying to write a DSL with Xtext to specify an XML-like language [message #1781902] |
Wed, 14 February 2018 13:41 |
Juha Kari 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?
|
|
|
Powered by
FUDForum. Page generated in 0.02807 seconds