Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:40:10+00:00 2026-06-06T17:40:10+00:00

I am trying to design a little DSL for checking constraints on variables. My

  • 0

I am trying to design a little DSL for checking constraints on variables. My grammar at the moment looks like this:

Start:
    varDeclarations += XVariableDeclaration*
    rules+=Constraint*;

Constraint:
    {Constraint}
    'FOR' 'PAYLOAD' payload=PAYLOAD 'ELEMENT' element=ID 'CONSTRAINED BY' constraint=XExpression;



PAYLOAD:
    "SimulationSessionEvents"
    |"stacons"
    |"any"
;

I want to generate instances of a class containing just one method that takes as input a value, maps it to the only variable contained in the constraint(which is also the only variable declared), and checks if the constraint is satisfied.

These instances will then be used by another class, which passes a value through each instance, checking if it’s constraint is satisfied.

As I see it I have 2 options:

  1. Explicitly generate code for a constraint class, in which case I can just use XBaseCompiler to generate the expression evaluation code. However I would then have to load these classes somehow, which seems inelegant, if there is a way to create in memory objects directly.

  2. Use the ModelInferrer to directly generate in memory objects which can be passed to the other class, so no class loading is required. I am not sure how to generate the xbase expression evaluation code in this case.

After reading all the xtext documentation/tutorials, and playing around with the examples, I am left with the following questions:

Which is the ‘best’ approach in terms of scalabilty (I may later want to extend the grammar, and/or the functions of he generated classes)?
How exactly would I go about things if I were to follow the ModelInferrer approach?
Is there any other way of doing this?

Any help would be much appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:40:12+00:00Added an answer on June 6, 2026 at 5:40 pm

    The best approach is to use the model inferer to create the Java representation of your DSL elements. The expression is usually assigned by means of the JvmTypeBuilder#setBody. Have a look at the domain model example where you’ll find the the assignment to the operation body:

    members += f.toMethod(f.name, f.type) [
        for (p : f.params) {
            parameters += p.toParameter(p.name, p.parameterType)
        }
        body = f.body
    ]
    

    Another option is to create the code manually:

    body = [
        append(varName).append(' = new ').append(typeName).append('();')
    ]
    

    The inferer approach allows for powerful Eclipse integration since type hierarchy, call hierarchy or go-to-declaration will all honor the derived Java things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading the design guidelines. I came across a little issue while trying to practice
i'm currently (trying) to program a little game. And i have a small design/deadlock
I'm trying to develop a slide gallery with image tooltips according to this design:
I'm trying to design a code where one guess a number. I defined the
I'm trying to design a Windows Forms application. By default, .NET had put Tahome
I'm trying to design an entity model for an application that uses ASP.Net membership
I am trying to design my first Android application with the use of GPS.
I am trying to design a dialog box for License aggrement and other dialog
I have been trying to design a WCF file upload service and am getting
I am trying to design a small site where most of (95%) of site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.