gpt4 book ai didi

java - Xtext 没有从我的 dsl 生成完整的类

转载 作者:行者123 更新时间:2023-12-02 04:10:42 25 4
gpt4 key购买 nike

我有一个 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

有人能解释一下这里发生了什么吗?

最佳答案

属性LHSSystemPRODUCESDataSet及其 friend 的父类(super class)型上可用。 Relationship 应该为其公开一个 getter。这是因为 Relationship 的所有子类型都具有共同的 LHS,因此它会自动拉入父类(super class)型。

关于java - Xtext 没有从我的 dsl 生成完整的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33828914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com