Support
Quality
Security
License
Reuse
kandi has reviewed packtpubxtextbookexamples and discovered the below as its top functions. This is intended to give you an instant insight into packtpubxtextbookexamples implemented functionality, and help decide if they suit your requirements.
in the files org.eclipse.jdt.core.prefs you need to replace 1.5 with 1.6
in MANIFEST.MF and .classpath files you need to replace J2SE1.5 with JavaSE1.6
default
fragment = ecore.EcoreGeneratorFragment autoinject {
Range Specification in Xtext
Model:
(expressions+=Comparison ";")*;
Comparison returns Expression:
Range ({Comparison.left=current} op=(">="  "<="  ">"  "<"  "=>"  "<=>"  "xor"  "=") right=Range)*;
Range:
(leftBracket=('['  ']') left=Atomic '' right=Atomic rightBracket=('['  ']'))

Atomic;
Atomic:
value=INT;
[12];
]35[;
[14[ < ]16];
6;
1 < 2;

Model:
(expressions+=Comparison ";")*;
Comparison returns Expression:
Range ({Comparison.left=current} op=(">="  "<="  ">"  "<"  "=>"  "<=>"  "xor"  "=") right=Range)*;
Range:
(leftBracket=('['  ']') left=Atomic '' right=Atomic rightBracket=('['  ']'))

Atomic;
Atomic:
value=INT;
[12];
]35[;
[14[ < ]16];
6;
1 < 2;
QUESTION
Range Specification in Xtext
Asked 2017Mar24 at 08:44I am new to XText and want to define a language element for specifying ranges of values. Examples: [12] or ]0.10.3[
I have the following rule for this purpose:
Range returns Expression:
Atomic (leftBracket=('['  ']') left=Atomic '' right=Atomic rightBracket=('['  ']'))*;
Atomic here refers basically to the primitive float and int types. I have two problems:
The expression works only in standalone manner (in one row), but not in connection with the rest of the language elements. E.g. in connection with the element right before:
Comparison returns Expression:
Range ({Comparison.left=current} op=(">=""<="">""<""=>"" <=>""xor""=") right=Range)*;
This means, if such an operation is before the Range element in my input of the second Eclipse window, I get the error "No viable alternative at input".
Any ideas? Thanks for any hints and advices!
Some more information: I took this example and changed it: https://github.com/LorenzoBettini/packtpubxtextbookexamples/blob/master/org.example.expressions/src/org/example/expressions/Expressions.xtext
Full code:
grammar org.example.expressions.Expressions with org.eclipse.xtext.common.Terminals
generate expressions "http://www.example.org/expressions/Expressions"
ExpressionsModel:
expressions+=Expression*;
Expression: Or;
Or returns Expression:
And ({Or.left=current} "" right=And)*
;
And returns Expression:
Equality ({And.left=current} "&&" right=Equality)*
;
Equality returns Expression:
Comparison (
{Equality.left=current} op=("==")
right=Comparison
)*
;
Comparison returns Expression:
Range ({Comparison.left=current} op=(">=""<="">""<""=>""<=>""xor""=") right=Range)*
;
Range returns Expression:
Primary (leftBracket=('['  ']') left=Primary '' right=Primary rightBracket=('['  ']'))*
;
Primary returns Expression:
'(' Expression ')' 
{Not} "!" expression=Primary 
Atomic
;
Atomic returns Expression:
{IntConstant} value=INT 
{StringConstant} value=STRING 
{BoolConstant} value=('true''false')
;
Example where it fails: (1 = [12]) however [12] in a row works fine.
ANSWER
Answered 2017Mar23 at 17:21i cannot really follow you but your grammar looks strange to me
Model:
(expressions+=Comparison ";")*;
Comparison returns Expression:
Range ({Comparison.left=current} op=(">="  "<="  ">"  "<"  "=>"  "<=>"  "xor"  "=") right=Range)*;
Range:
(leftBracket=('['  ']') left=Atomic '' right=Atomic rightBracket=('['  ']'))

Atomic;
Atomic:
value=INT;
works fine with
[12];
]35[;
[14[ < ]16];
6;
1 < 2;
so can you give some more context
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit