我有一个xtext语法,我打算在应用程序中使用它。但是,当我检查生成的类时,有些项目丢失了。
这是语法:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
model += ModelBlock+
;
ModelBlock:
SystemBlock | DataSetBlock | RelationshipBlock
;
SystemBlock:
'Systems' systemGroup=ID
systems+=System+
;
DataSetBlock:
'DataSets' datasetGroup=ID
datasets+=DataSet+
;
RelationshipBlock:
'Relationships' relationshipGroup=ID
relationships+=Relationship+
;
System:
name = ID ':'
'name:' nm = STRING
('description:' description = STRING)?
;
DataSet:
name = ID ':'
'name:' nm = STRING
;
Function:
name = ID ':'
'name:' nm = STRING
;
Relationship:
SystemCONNECTSSystem |
SystemCONSUMESDataSet |
SystemPRODUCESDataSet
;
SystemCONNECTSSystem:
rel=ID
':' lhs = [System]
'CONNECTS' rhs = [System]
;
SystemCONSUMESDataSet:
rel=ID ':' lhs = [System] 'CONSUMES' rhs = [DataSet]
('WITH' 'frequency:' frequency = INT)?
;
SystemPRODUCESDataSet:
rel=ID ':' lhs = [System] 'PRODUCES' rhs = [DataSet]
('WITH' 'frequency:' frequency = INT
('risk:' risk = RiskEnum)?
)?
;
enum RiskEnum:
h="high" | m="med" | l="low"
;
您会注意到SystemCONNECTSSystem,SystemPRODUCESDataSet和SystemCONSUMESDataSet类没有生成属性lhs,而是生成属性rhs。请参阅下面的SystemPRODCUESDataSet,其他人也遇到同样的问题。
/**
*/
package org.xtext.example.mydsl.myDsl;
/**
* <!-- begin-user-doc -->
* A representation of the model object '<em><b>System PRODUCES Data Set</b></em>'.
* <!-- end-user-doc -->
*
* <p>
* The following features are supported:
* </p>
* <ul>
* <li>{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getRhs <em>Rhs</em>}</li>
* <li>{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getFrequency <em>Frequency</em>}</li>
* <li>{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getRisk <em>Risk</em>}</li>
* </ul>
*
* @see org.xtext.example.mydsl.myDsl.MyDslPackage#getSystemPRODUCESDataSet()
* @model
* @generated
*/
public interface SystemPRODUCESDataSet extends Relationship
{
/**
* Returns the value of the '<em><b>Rhs</b></em>' reference.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Rhs</em>' reference isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Rhs</em>' reference.
* @see #setRhs(DataSet)
* @see org.xtext.example.mydsl.myDsl.MyDslPackage#getSystemPRODUCESDataSet_Rhs()
* @model
* @generated
*/
DataSet getRhs();
/**
* Sets the value of the '{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getRhs <em>Rhs</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Rhs</em>' reference.
* @see #getRhs()
* @generated
*/
void setRhs(DataSet value);
/**
* Returns the value of the '<em><b>Frequency</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Frequency</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Frequency</em>' attribute.
* @see #setFrequency(int)
* @see org.xtext.example.mydsl.myDsl.MyDslPackage#getSystemPRODUCESDataSet_Frequency()
* @model
* @generated
*/
int getFrequency();
/**
* Sets the value of the '{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getFrequency <em>Frequency</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Frequency</em>' attribute.
* @see #getFrequency()
* @generated
*/
void setFrequency(int value);
/**
* Returns the value of the '<em><b>Risk</b></em>' attribute.
* The literals are from the enumeration {@link org.xtext.example.mydsl.myDsl.RiskEnum}.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Risk</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Risk</em>' attribute.
* @see org.xtext.example.mydsl.myDsl.RiskEnum
* @see #setRisk(RiskEnum)
* @see org.xtext.example.mydsl.myDsl.MyDslPackage#getSystemPRODUCESDataSet_Risk()
* @model
* @generated
*/
RiskEnum getRisk();
/**
* Sets the value of the '{@link org.xtext.example.mydsl.myDsl.SystemPRODUCESDataSet#getRisk <em>Risk</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Risk</em>' attribute.
* @see org.xtext.example.mydsl.myDsl.RiskEnum
* @see #getRisk()
* @generated
*/
void setRisk(RiskEnum value);
} // SystemPRODUCESDataSet
任何人都可以了解这里发生的事情吗?
答案 0 :(得分:2)
属性LHS
在超级SystemPRODUCESDataSet
和朋友上可用。 Relationship
应该为它公开一个getter。这是因为Relationship
的所有子类型都有LHS,所以它会自动拉到超类型。