Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Rule written for DSL in xtext, It is not working as expected(Rule written for DSL in xtext, It is not working as expected)
Rule written for DSL in xtext, It is not working as expected [message #1300171] Thu, 17 April 2014 11:31 Go to next message
Kapil Sharma is currently offline Kapil SharmaFriend
Messages: 5
Registered: April 2014
Junior Member
I am trying -->> VL:'this is test dsl in xtext' IS ABC

TestLabelBase returns ResultExpressionRhs: 'VL:' path=stringRule;

The Rule I tried was: TestLabel returns ResultExpressionRhs: TestLabelBase ('IS' modifier=alphabateModifier)?;

alphabateModifier: (abc?='ABC' | def?='DEF' | ghi?='GHI');

It would recognize the 'IS' but not the 'ABC'.
Re: Rule written for DSL in xtext, It is not working as expected [message #1300369 is a reply to message #1300171] Thu, 17 April 2014 14:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

can you please share a complete reproducable example

btw your grammar looks very complictated

Stuff:
'VL'':' label=STRING 'IS' (abc?='ABC' | def?='DEF' | ghi?='GHI');


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rule written for DSL in xtext, It is not working as expected [message #1300605 is a reply to message #1300369] Thu, 17 April 2014 17:53 Go to previous messageGo to next message
Kapil Sharma is currently offline Kapil SharmaFriend
Messages: 5
Registered: April 2014
Junior Member
Hi,

Thanks for your interest.

xtext rule:

TestLabelBase returns ResultExpressionRhs: 'VL:' path=stringRule;

TestLabel returns ResultExpressionRhs: TestLabelBase ('IS' modifier=alphabateModifier)?;

alphabateModifier: (abc?='ABC' | def?='DEF' | ghi?='GHI');


DSL Sample:

VL:'this is test dsl in xtext' IS ABC

Problem is :

When I want to use ABC in dsl file at the end of statement , it does not allow it.
Re: Rule written for DSL in xtext, It is not working as expected [message #1300616 is a reply to message #1300605] Thu, 17 April 2014 18:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi, still cannot reproduce this,
please share a complete reproducable example

e.g.: what is the start (first) rule of your grammar.
if it is TestLabelBase this is your mistake


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rule written for DSL in xtext, It is not working as expected [message #1300639 is a reply to message #1300616] Thu, 17 April 2014 18:21 Go to previous messageGo to next message
Kapil Sharma is currently offline Kapil SharmaFriend
Messages: 5
Registered: April 2014
Junior Member

I used following import "http://www.eclipse.org/emf/2002/Ecore" as ecore in xtext.

Below is my xtext file I am using:

DSLDEMO:
(messgae+=Message)*;

Message:
element+=ResultExpression+
;

Product:
'ProductName:' name=OptEscapeString '[' group=OptQuoteString ']'
;

ResultExpression:
Product rhs=ResultExpressionRhs;

ResultExpressionRhs returns ResultExpressionRhs:
(Product | TestLabel | StringLiteral);

TestLabelBase returns ResultExpressionRhs:
'VL:' path=stringRule;

TestLabel returns ResultExpressionRhs:
TestLabelBase ('IS' modifier=alphabateModifier)?;

alphabateModifier:
(abc?='ABC' | def?='DEF' | ghi?='GHI');

StringLiteral returns ResultExpressionRhs:
value=OptEscapeString;

enum PaoParamOperator:
ASSIGN='=';

OptQuoteString:
(OptEscapeString | STRING_UNQUOTED);

OptEscapeString:
(STRING_NOESCAPE | STRING_ESCAPE);

terminal NUMBER:
('0'..'9')* ('.' ('0'..'9')+)?;

terminal INT returns ecore::EInt:
'this one has been deactivated';

terminal STRING_UNQUOTED:
('a'..'z' | 'A'..'Z' | '0'..'9') ('a'..'z' | 'A'..'Z' | '0'..'9' | ' ' | '\\')+;

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

terminal STRING_ESCAPE:
'"' ('\\' ('b' | 't' | 'n' | 'f' | 'r' | 'u' | '"' | "'" | '\\') | !('\\' | '"'))* '"';
Re: Rule written for DSL in xtext, It is not working as expected [message #1300640 is a reply to message #1300639] Thu, 17 April 2014 18:23 Go to previous messageGo to next message
Kapil Sharma is currently offline Kapil SharmaFriend
Messages: 5
Registered: April 2014
Junior Member
Hope now you will be able to understand.
Re: Rule written for DSL in xtext, It is not working as expected [message #1300670 is a reply to message #1300639] Thu, 17 April 2014 18:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
hi, this is still not complete . stringRule is missing.
and the info if you use terminals grammar or not.

then you have way to many terminals,
including critical ones like string unquoted.
it contains a ' ' (blank)

xtext works with lexer and parser,
the lexing is eager.

generating the grammar (asuming
TestLabelBase returns ResultExpressionRhs:
'VL:' path=STRING;)

gives a lot of ambiguity warnings

is this a existing language or a new one?

maybe you should start with an easier grammar
reusing the terminals defined in the terminal grammar

e.g:

NUMBER: INT? ('.' INT);
MY_STRING: STRING | (ID+);

stuff like 'this one has been deactivated'
is a bad idea (dont use blanks in strings)


--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rule written for DSL in xtext, It is not working as expected [message #1301454 is a reply to message #1300670] Fri, 18 April 2014 05:31 Go to previous messageGo to next message
Kapil Sharma is currently offline Kapil SharmaFriend
Messages: 5
Registered: April 2014
Junior Member
Sorry my mistake stringRule must be replaced by OptEscapeString.
Re: Rule written for DSL in xtext, It is not working as expected [message #1311169 is a reply to message #1300670] Wed, 23 April 2014 16:42 Go to previous messageGo to next message
Ricardo \\\"CaWal\\\" Cacheta Waldemarin is currently offline Ricardo \\\"CaWal\\\" Cacheta WaldemarinFriend
Messages: 29
Registered: January 2013
Junior Member
Christian Dietrich wrote on Thu, 17 April 2014 14:54
...
then you have way to many terminals,
including critical ones like string unquoted.
it contains a ' ' (blank)


(...)
xtext works with lexer and parser,
the lexing is eager.

generating the grammar (...) gives a lot of ambiguity warnings

is this a existing language or a new one?

maybe you should start with an easier grammar
reusing the terminals defined in the terminal grammar

(...)

stuff like 'this one has been deactivated'
is a bad idea (dont use blanks in strings)


Is possible to write a grammar that permits spaces in strings?

I have this problem: I need to write a grammar to load a OBO Flat File Format as an Ecore model. The OBOFFF has stanzas that are formatted as tag-value pairs that can be (or not) followed by modifiers (strings between brackets) and inline comments (string after an exclamation mark).

<tag>: <value> ['{'<modifier1>=<value1> ',' [<modifier2> '=' <value2>,...]'}'] ['!'<comment>]


The <value> part of the pair can be an ID (a unquoted string without whitespaces), a URI, a quoted string (whitespaces and escape characters allowed) or a unquoted string that should end at the end of the line or before the trailing modifiers/comment. Additionally, some values should use a combination of those strings, like:
subsetdef: GO_SLIM "GO SLIM"


I'd thought that I could write a rule to match it as

SubSetDefPair returns SubSetDefPair:
	tag='subsetdef:' WS_CHAR* subsetName=ID WS_CHAR description=QUOTED_STRING
;


terminal WS_CHAR :
	' ' | '\t' 
;
 
terminal ID  : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal QUOTED_STRING	:
	// A String that starts and ends with double quotation marks 
	'"' ( '\
\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"'
;
terminal UNBOUNDED_STRING:
// a string that should end at the ending of the line or before a comment
('a'..'z'|'A'..'Z'|'_'|'0'..'9')
(('a'..'z'|'A'..'Z'|'_'|'0'..'9' | WS_CHAR)*
('a'..'z'|'A'..'Z'|'_'|'0'..'9'))?
;

[/code]

But it's not working.
I expected to match something like

subsetdef: asd "asdssd" 


but it returns the following error:

Multiple markers at this line
- mismatched character '"' expecting set null
- mismatched character '<EOF>' expecting '"'


Does anyone have an idea of how I can address this issue?

Re: Rule written for DSL in xtext, It is not working as expected [message #1311207 is a reply to message #1311169] Wed, 23 April 2014 17:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

just one thing: not every thing must be in the grammar. you can write semantic checks/validations in java/Xtend too


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rule written for DSL in xtext, It is not working as expected [message #1311267 is a reply to message #1311207] Wed, 23 April 2014 18:00 Go to previous messageGo to next message
Ricardo \\\"CaWal\\\" Cacheta Waldemarin is currently offline Ricardo \\\"CaWal\\\" Cacheta WaldemarinFriend
Messages: 29
Registered: January 2013
Junior Member
Humm... This is something I still don't understand quite well how to do (or when I should do). What's the recommended documentation (or some example) about it?
Re: Rule written for DSL in xtext, It is not working as expected [message #1311298 is a reply to message #1311267] Wed, 23 April 2014 18:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

its in the docs, http://www.eclipse.org/Xtext/documentation.html#validation
searching for XText + Validator/Check should give many results


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:generate property from referenced object
Next Topic:reference whitespace issue
Goto Forum:
  


Current Time: Tue Apr 16 07:56:32 GMT 2024

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

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

Back to the top