Xtext: DSL reference to attribute

JavaNullPointer

For example

i have a grammar like this one:

Bundle:
    'Bundle'
    name= ID '{'
    car+=Car+
    service +=Service*
    '}'
    ;

Car:
    'Car'
    name=ID
    extra+=Extra*
    '}'
;   

Extra:
    name= ID '=' type=STRING
;

Service:
    'Service' att=STRING 'for' ref+=Reference*
;

Reference:
    //Ref to car oder Ref to Car.Extra 
;

In my model i want to create a Service like:

Service "ServiceName" for car1
Service "ServiceName" for car2 (extra1 extra2)

How can i resolve the reference to Extras of a Car?

Christian Dietrich

this can be done with simple cross refs

Service:
    'Service' att=STRING 'for' car=[Car] ('(' extras+=[Extra]+ ')')?
;

And a corresponding scope provider

package org.xtext.example.mydsl.scoping

import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.xtext.example.mydsl.myDsl.Service

class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {

    def IScope scope_Service_extras(Service ctx, EReference ref) {
        return Scopes.scopeFor(ctx.car.extra)
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jackson, serialize one attribute of a reference

From Dev

Queryable attribute ambiguous Reference Error

From Dev

How to reference an attribute in xsd

From Dev

Integration of Xtext DSL editors and e4-based RCP

From Dev

Custom xml attribute to a @layout reference

From Dev

Xtext: Cannot resolve reference

From Dev

Create an expression to get a sub element from entity, using a Xtext DSL

From Dev

Xtext DSL: boolean rule with 2 different string

From Dev

XText cross-reference to an non-DSL resource

From Dev

use the name attribute to reference an iframe

From Dev

How to embed C++ code in a xtext DSL?

From Dev

Xtext: DSL reference to attribute

From Dev

Syntax coloring my DSL in Xtext

From Dev

Xtext DSL: boolean rule with 2 different string

From Dev

Create an expression to get a sub element from entity, using a Xtext DSL

From Dev

XText cross-reference to an non-DSL resource

From Dev

Xtext grammar variable definition/reference

From Dev

Xtext is not producing a complete class from my dsl

From Dev

DSL with XText for PlantUML

From Dev

Error when validating Xtext DSL in standalone Java project

From Dev

Xtext cross-reference to constants of Enum

From Dev

Xtext: Using syntactic predicates with cross-reference

From Dev

Xtext cross reference for language with enum types

From Dev

Xtext, multi-file Cross-reference

From Dev

Reference a DSL from another DSl and its model

From Dev

XText DSL with lookbehind

From Dev

Unresolved Attribute Reference

From Dev

Xtext cross reference with this keyword

From Dev

xtext couldn't resolve reference to Model