Xtext 没有从我的 dsl 生成完整的 class
Xtext is not producing a complete class from my dsl
我有一个 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
任何人都可以阐明这里发生的事情吗?
属性 LHS
在 SystemPRODUCESDataSet
和朋友的超类型上可用。 Relationship
应该为它公开一个 getter。那是因为 Relationship
的所有子类型都有共同的 LHS,因此它会自动拉入超类型。
我有一个 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
任何人都可以阐明这里发生的事情吗?
属性 LHS
在 SystemPRODUCESDataSet
和朋友的超类型上可用。 Relationship
应该为它公开一个 getter。那是因为 Relationship
的所有子类型都有共同的 LHS,因此它会自动拉入超类型。