blended-modeling / eatxt

Eclipse Public License 2.0
1 stars 1 forks source link

Boolean and Numerical Rules Insufficient #13

Closed joerg-holtmann closed 2 years ago

joerg-holtmann commented 3 years ago

Two issues with the following production / terminal rules (Xtext generated ToDo's for them to implement the rule or an IValueConverter):

Wilson008 commented 2 years ago

After investigating, the rule for Boolean should be:

Boolean returns Boolean: 'true' | 'false' ;

Because Boolean here does actually come from java.lang.Boolean (see in eastadl22.ecore, i.e. the metamodel). And the rule for Numerical should be:

Numerical returns Numerical: ID ;

Because the Numerical does actually come from java.lang.String in metamodel.

Just tested the new rules and look good, so close the issue for the time being. We use this editor in future is somehow a deep test for this. If there is still anything unsuitable, then back here and reopen it.

joerg-holtmann commented 2 years ago

Regarding the Numerical rule, please check https://www.eclipse.org/Xtext/documentation/301_grammarlanguage.html, sections "Terminal Rules" for terminal rules ID and String and also "Return Types" for learning about default String datatypes and the implementation of value converters.

Wilson008 commented 2 years ago

The difference between ID and String could be figured out by watching at their definitions, ID could start with a hat '^', but then has to have English letters, however, String could have more freedom. terminal ID: '^'? ('a'..'z'|'A'..'Z'|'$'|'') ('a'..'z'|'A'..'Z'|'$'|''|'0'..'9')*;

terminal STRING: '"' ( '\' . / ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\') / | !('\'|'"') ) '"'? | "'" ( '\' . / ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\') / | !('\'|"'") ) "'"?; Usually, ID rule could be enough for the use on the Identifiers, and as well as enough for String0 in EastAdlSimplified. There is a possibility that the users want their String0 have more freedom, then they just need modify the String0 rule from: String0 returns String: ID; to: String0 returns String: ID | STRING;

Wilson008 commented 2 years ago

Then the rule of Numerical is more complicated, which could be a binary/octal/decimal/hex/exponent number. I create rules for the binary/octal/hex number/exponent numbers as follows: image so finally, the rule Numerical is: image And there is no need to customize value converter to them. Then see the results: image

Wilson008 commented 2 years ago

The clue for figuring out the Numerical rule locates in the textual mode of the meta-model, see the following figure: image