简体   繁体   中英

Xtext assign object in xtext file

Trying to make a meta model for Mongoose and MondoDb, using metamodeling concepts, eclipse and xtext.

I am trying to assign object that i created in my test.mydsl file to another object in the same file, but i get error in my test.mydsl file.

I am trying to assign created Schema(sc1) object to Collection(col) object, but currently getting an error

error message

the feature 'validate' of 'paket.impl.NCollectionImpl@67d76e14{platform:/resource/test/classes/test.mydsl#//@collections.0}' contains an unresolved proxy 'paket.impl.SchemaImpl@361d8284{platform:/resource/test/classes/test.mydsl#|0}'

my grammar for Schema and Collection

Schema returns Schema:
    {Schema}
    ('Schema' '<' Name=EString) '>'
    '{'
        (schemaExpression+=Expression ( "," schemaExpression+=Expression)*)?
        (verificationDocumentElement+=VerDocElement ( "," verificationDocumentElement+=VerDocElement)*)?
    '}';

NCollection returns NCollection:
    {NCollection}
    ('Collection' '<' Name=EString) ',' (validate=[Schema|EString])? '>'
    '{'
        (document+=Document ( "," document+=Document)*)?
    '}';

my test.mydsl

Database<db1>{

    Schema<sc1>{
        var ja=lp   
        ime:{
            type:String,
            min:123.0
        }

    }
    Collection<col, sc1> 
    {

    }
}

I tried all, but unsuccessful.

Any ideas what to do?

Thanks

EDIT:

Maybe I was not clear enough. The major problem is with "validate" attribute in NCollection rule. When I create my Schema object(sc1 in test.mydsl) and then try to pass it to Collection(col in test.mydsl) as a "sc1", the "validate" attribute cannot accept it like string, and I don't know how to pass it like Schema object. I hope this explanation helps.

Please try to use name=EString instead of Name=EString as Xtext imposes a special default semantics for the attribute name . Also I recommend to look into the documentation.

The code

validate=[Schema|EString]

says: I want a schema reference via a String, ie "sc1" instead of the name. Xtext doesn't know how to convert a string into a reference. Use this instead:

validate=[Schema]

which is short for

validate=[Schema|ID]

That will use the name of the Schema as reference. Note that you have to write

('Schema' '<' name=EString) '>'

ie lower case name to make it work. Xtext has special handling for properties called name .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM