xtext problem for definition terminal string [message #669958] |
Thu, 12 May 2011 07:51 |
tian1qi Messages: 21 Registered: May 2011 |
Junior Member |
|
|
hi!
i'm a new in xtext,and i have a big problem that i have no idear how i can resolve it
i have a grammar in which i define some rules. for exemple: i have a rule name "Clock_fonct"
Clock_fonct returns Clock_fonct:
{Clock_fonct}
'CLOCK'
name = EString
operateur=Operateur_Relationnel
'.'clock_attri=[AttributsDelegation]
;
and i define EString like terminal rule:
EString returns ecore::EString: ID ;
[Updated on: Thu, 12 May 2011 07:55] Report message to a moderator
|
|
|
Re: xtext problem for definition terminal string [message #669960 is a reply to message #669958] |
Thu, 12 May 2011 07:57 |
tian1qi Messages: 21 Registered: May 2011 |
Junior Member |
|
|
terminal ID returns ecore::EString: '^'?('a'..'z'|'A'..'Z'|'_'|':'|'$'|'`'|'#'|'é'|'è'|'ç'|'ù'|'à'|'ô'|"'"|'"'|'%'|'-') ('a'..'z'|'A'..'Z'|'_'|':'|'$'|'#'|'é'|'è'|'ç'|'ù'|'ê'|'à'|'ô'|'-'|'%'|'='|'<'|' '|'0'..'9'|'`')*;
"Operateur_relationnel" is the type enum:
enum Operateur_Relationnel returns Operateur_Relationnel:
egal='=' |presque_egal='<>' |different='/=' |inferieur='<' |inferieur_egal='<=' |superieur='>' |superieur_egal='>='
;
now the problem comes, the type "EString" can take all the carecters includes the operator, but if i define all the operator in the "EString", my grammar can't take the type enum "Operateur_Relationnel" as a enum but a "Estring", which is normal for it,i want to know if there is some way to resolve this problem, i tried lots of things but none if them works, can anyone helps me please?
[Updated on: Thu, 12 May 2011 07:59] Report message to a moderator
|
|
|
Re: xtext problem for definition terminal string [message #669965 is a reply to message #669960] |
Thu, 12 May 2011 08:22 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
please see my reply to the post by Ed (forwarded to this forum). For any normal grammar, your terminal definition is unusable. Do you really want an ID to start with quotation marks?? Use datatype rules.
What you might want is something like the clocks name to be MyString and
MyString: STRING|MyId
(with the regular STRING definition and a sensible MyId definition)
Alex
[Updated on: Thu, 12 May 2011 08:24] Report message to a moderator
|
|
|
|
|
|
|
Re: xtext problem for definition terminal string [message #670060 is a reply to message #670038] |
Thu, 12 May 2011 14:32 |
tian1qi Messages: 21 Registered: May 2011 |
Junior Member |
|
|
I'm sorry, I didn't explain clearly.
this is parts of the grammar with the 2 type string:
Modele returns Modele:
{Modele}
'[OBJET'identifiant=EString']'
'<NATURE>'('='|'^') nature=type_model
'<.NOM>''=' nom=EStringNewID
('<.LIBELLE>''=' libelle=EString)?
'<.CLASSES>''{' (classes+=Classe)* '}'
;
Classe returns Classe:
('<.+>'|'<.'EInt'>')'{'
('<.NOM>''=' name=EString &
(('<.LIBELLE>''=' libel=EStringNewID)? ) &
(('<.PERSISTANT>''='persistant?=EBooleanUPPER)?) &
(('<.MERE>''=' mere=[Classe])? ) &
('<.ATTRIBUTS>''{' attributs+=Attribut+ '}') )
'}'
;
enum type_model returns type_model:
BOA_MODELE = '#BOA_MODELE';
Attribut returns Attribut:
('<.+>'|'<.'EInt'>') '{'
(('<.NOM>''=' name=EString) &
(('<.LIBELLE>''=' libelle=EStringNewID)?) &
(('<.CACHE>''=' cache ?=EBooleanUPPER)?) &
('<.RESSOURCE>''=' la_ressource=[Ressource]) &
('<.NATURE>''=' nature=type_nature) &
('<.VUE.' vues+=Vue_syntaxe_two)* &
('<.VUE>''{'(vues_type_cle+=Vue_syntaxe_one)+ '}')? )
'}'
;
when i apply the grammar to a file with extension .bdl
[OBJET #UTA_SDR]
<NATURE> =#BOA_MODELE
<.NOM> =#UTA_SDR
<.LIBELLE> =Modèle Redondance [color=red]]error mismatched input 'Mod' expecting RULE_ID[/color]
<.CLASSES>{ [color=red]The feature 'attributs' of 'com.atosorigin.vigile.bdloc.modele_serv.impl.ClasseImpl@1348b49{platform:/resource/model/src_stsldas/prj-red/boa-red.bdl#//@loc_modeles.0/@classes.0}'
with 0 values must have at least 1 values[/color]
--****************************************************************************
-- Classe UTA_Etat_SDR --
--****************************************************************************
<.1>{
<.NOM> =#UTA_Etat_SDR
<.LIBELLE> =service de redondance
<.MERE> =#UTA_SYSTEME:#UTA_INTERFACE_CLIENT
<.ATTRIBUTS>{
-- ------------------------------------------------------------------------------
-- attribut lu périodiquement pour connaître l'état de vie du serveur
-- ------------------------------------------------------------------------------
<.1>{
<.NOM> =AuditVg
<.NATURE> =V
<.RESSOURCE> =#UTA_SDR:#UTA_Etat_SDR:VAL_TEXTE
}
in the "attribut" all the values are define, and the "libelle" it want the type ID
[Updated on: Thu, 12 May 2011 14:34] Report message to a moderator
|
|
|
|
|
|
|
|
Re: xtext problem for definition terminal string [message #670932 is a reply to message #670910] |
Mon, 16 May 2011 09:18 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
I have had a quick look at the grammar. You are aware that it is highly ambiguous and that without the backtracking options turned on, it is very likely that the model is instantiated incorrectly.
I find your current ID definition highly dangerous... you really want to allow white spaces in an ID??
The error you get in the sample model is caused by your ID-Definition. You allow dash/minus (-) as the first symbol of an ID but not later on, so how do you think the "ID" #UTA_MSG_STSGEN-MODEL-INTERFACE is to be accepted.
The minimal adaption to make more of the input being accepted is
//this rule is still no good idea as "-25" suddenly becomes an ID token
//do you really need "-" as the first character of an ID
terminal ID returns ecore::EString: ('a'..'z'|'A'..'Z'|'_'|'-'|':'|'#') ('a'..'z'|'A'..'Z'|'_'|':'|' '|'0'..'9'|'-'|"'")*;
EStringNewID returns ecore::EString: (ID|ANY_OTHER)+;
But again, a space in an ID will bring you only trouble. Further problems will be caused because single letters like "R", "D" are keywords in your grammar. Hence "Début" will not be accepted as an ID (or EStringNewID, as the first single D is not contained in the alternatives).
Getting the terminal and datatype rules straightened out will be quite an effort and it is much more than you can expect anyone in this forum to do for you. Here are some steps I find necessary.
-Remove the white space from the ID-terminal
-Split the WS-terminal in a SPACE and a OTHERWS terminal, so that spaces are not consumed along with tabs and new lines.
-make both white space terminals hidden by default (hidden(SPACE, OTHERWS)), but only hide tab/new-line white spaces in your EString datatype rules (regular space should be included in the alternatives)
--DatatypeRule hidden(OTHERWS): (WS|ID|ANYOTHER|...)+;
-go through the grammar and add all keywords ('R', 'D', '%' are also keywords) that should be allowed to the EString/NewID datatype rules
-write unit tests that check whether IDs and labels you expect to be accepted actually match the rules that should consume them.
Alex
|
|
|
|
Powered by
FUDForum. Page generated in 0.04355 seconds