Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » EByte(Setting a range as EInt)
EByte [message #1804352] Sat, 23 March 2019 18:32 Go to next message
Eugen Betuch is currently offline Eugen BetuchFriend
Messages: 8
Registered: March 2019
Junior Member
Hello,
i am trying to create a byte representation with xtext. I tried using ecore::EByte but couldn't find any example. So now i am using EInt.

WB:
	'WB' name=BYTE
;

terminal BYTE returns ecore::EInt:
	('1')?('0'..'9')?('0'..'9') | ('2')('0'..'4')('0'..'9') | ('2')('0'..'5')('0'..'5')
;


This grammar gives me some warnings like this one:
Decision can match input such as "'1'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

So i can use this rule but only one case gives an error:
WB 1
mismatched character '<EOF>' expecting set '0'..'9'

So i can type WB 0 to WB 255 but only the upper case throws an error message.
Does somebody have an example for EByte or knows why WB 1 is not correct?


Re: EByte [message #1804415 is a reply to message #1804352] Mon, 25 March 2019 19:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

is there any reason you want to solve this on lexer side?
if yes the problem is that (0..9) matches 1 too so you would have to consider that too
terminal BYTE returns ecore::EInt:
('1' .. '9')?('0..9') |
'1' ('0' .. '9')('0..9') |
'2' ('0'..'4')('0'..'9') |
('2')('5')('0'..'5')

did you implement a value converter?
do you inherit from terminals grammar? if yes your rule might conflict with int.
did you consider to use a datatype rule and restrict range in valueconverter?
did you import the ecore package and use EByte?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: EByte [message #1804468 is a reply to message #1804415] Tue, 26 March 2019 12:55 Go to previous message
Eugen Betuch is currently offline Eugen BetuchFriend
Messages: 8
Registered: March 2019
Junior Member
Hey,

thanks for your respond, its similar to my solution i got after some more thinking:
	('0'..'9') | ('1'..'9')('0'..'9') | ('1')('0'..'9')('0'..'9') | ('2')('0'..'4')('0'..'9') | ('2')('5')('0'..'5')


i want to create a language for generating binary files, example an arp packet or simple png file.
so i thought i will be good when the user sees an error or maybe an warning when writing the code, like "WB 266" shouldnt be possible.
So i will create a plugin for the user.

A value converter?
I am casting the Integer to a byte and create a byte array to write it later in a file.
No i didn't inherit from terminal just the standard grammar import.

Sorry i am new to this framework and have to find out whats the best way to solve my requirements. Like the validation in my java compiler for the expression "WB 266" to throw an exception if the user ignores the error/or maybe later warnings. Now its loading my model/ast and if there is an argument like "WB 266" its just ignoring it but writes the other bytes.

So thank you very much for your solution.
Previous Topic:Troubles understanding Qualified Name
Next Topic:Functions
Goto Forum:
  


Current Time: Thu Mar 28 12:28:15 GMT 2024

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

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

Back to the top