第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解析限定名稱表達式中的字段

如何解析限定名稱表達式中的字段

呼喚遠方 2023-06-28 15:43:29
這是我的“類型”Xtext 語法:grammar sample.types.Types with org.eclipse.xtext.common.Terminalsgenerate types "http://www.types.sample/Types"Model:    structs     += Struct*    data        += Data*    assignments += Assignment*;Struct:    'struct' name=ID '{'        fields += Field*    '}';Field:    type=Type name=ID;Type:      'number'    | 'string';Data:    type=[Struct|ID] name=ID;Assignment:    qname=QName '=' value=Value;QName:    data=[Data|ID] '.' path=[Field|ID];Value:      INT    | STRING;這是“類型”語法的一個實例:struct SampleA {    number n    string s}struct SampleB {    number n    string s}SampleA sampleA1SampleA sampleA2SampleB sampleBsampleA1.n = 12sampleA1.s = "Hello"sampleA2.n = 12sampleA2.s = "Hello"sampleB.n  = 42sampleB.s  = "Hello"最后六行引用字段“n”和“s”,生成錯誤:無法解析對字段“x”的引用。我編寫了以下自定義范圍提供程序,但沒有成功:class TypesScopeProvider extends AbstractTypesScopeProvider {   override getScope( EObject context, EReference reference ) {      if( reference === TypesPackage.Literals.QNAME__PATH ) {         val model = EcoreUtil2.getContainerOfType(context, Model)         if( model !== null ) {            val result = newArrayList            for( data : model.data ) {               for( field : data.type.fields ) {                  result.add(                     EObjectDescription.create(                        QualifiedName.create( data.name, field.name ),                        field ))               }            }            return new SimpleScope(IScope.NULLSCOPE, result)         }      }      super.getScope( context, reference )   }}
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

在你的語法中你有


QName:

    data=[Data|ID] '.' path=[Field|ID]

;

因此a.b將成為兩個參考的范圍。因此你要么必須在你的范圍提供商中反映這一點


// TODO: context will be a qname. ask it for its data. ask that for its data and collect fields from there and then

// scope for path

EObjectDescription.create(

                    QualifiedName.create(field.name ),

                    field ))

例如


override getScope(EObject context, EReference reference) {

    if (reference === MyDslPackage.Literals.QNAME__PATH) {

        if (context instanceof QName) {

            val result = newArrayList

            for (field : context.data.type.fields) {

                result.add(EObjectDescription.create(QualifiedName.create(field.name), field))

            }

            System.err.println(result)

            return new SimpleScope(IScope.NULLSCOPE, result)


        }

    }

    super.getScope(context, reference)

}

或者你有語法來反映你的范圍


DataOrField: Data | Field;

QName: dataOrField=[DataOrField|FQN]

FQN: ID ("." ID)?;


查看完整回答
反對 回復(fù) 2023-06-28
  • 1 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號