|
|
|
Re: Lexer problem [message #1722833 is a reply to message #1722797] |
Tue, 09 February 2016 14:15   |
Daniel Cardin Messages: 109 Registered: July 2009 |
Senior Member |
|
|
The suggestion is interesting, but cannot work in practice. Because my units are very common, the parser gets confused in many places like
val m = 293 mm
m is in the Unit enum, which is definitely not good.
That's why I was using terminals. to force the input to be tokenized before the parser sees it. I'm happy writing 100mm or 293.293kg.
terminal MT: DOUBLEVALUE UNIT;
terminal DOUBLEVALUE returns ecore::EDouble:
'-'? INT ('.' INT)?;
terminal UNIT:
'in'|'mm'|'cm'|'dm'|'m'
|'in2'|'mm2'|'cm2'|'dm2'|'m2'
|'in3'|'mm3'|'cm3'|'dm3'|'m3'
|'lb'|'mg'|'g'|'kg';
Does the same thing as my previous rules.
Is there any way to force a longer lookahead for the tokenizer ?
Thanks!
[Updated on: Tue, 09 February 2016 14:16] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Lexer problem [message #1722868 is a reply to message #1722866] |
Tue, 09 February 2016 20:01   |
|
the problem is
that
1 mm
could be
var mm = "Hello"
1
mm
but yes
XExpressionOrVarDeclaration returns xbase::XExpression:
=>XDistanceLiteral | super;
XDistanceLiteral:
=>value=Measure
;
Measure:
=>(INT UNIT)
;
ValidID:
ID | 'in'|'mm'|'cm'|'dm'|'m'
|'in2'|'mm2'|'cm2'|'dm2'|'m2'
|'in3'|'mm3'|'cm3'|'dm3'|'m3'
|'lb'|'mg'|'g'|'kg'
;
UNIT:
'in'|'mm'|'cm'|'dm'|'m'
|'in2'|'mm2'|'cm2'|'dm2'|'m2'
|'in3'|'mm3'|'cm3'|'dm3'|'m3'
|'lb'|'mg'|'g'|'kg';
seems fine as well
Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.20497 seconds