Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use "with" keyword to define an Entity implements a trait #361

Open
simonwfarrow opened this issue Oct 24, 2024 · 8 comments
Open

Comments

@simonwfarrow
Copy link

Describe the bug
I have defined a Trait and I am trying to use the with keyword of an Entity definition to implement the Trait.
I get the following error mismatched input 'ith' expecting RULE_CLOSE(org.eclipse.xtext.diagnostics.Diagnostic.Syntax)

To Reproduce
Steps to reproduce the behavior:

  1. Define a Trait Trait newTrait {}
  2. Define a Entity Entity newEntity with newTrait {}

Expected behavior
An Entity can implement a Trait with the with keyword
Looking at the DSL java docs I can see a getTraits() function of the DomainObject type https://www.javadoc.io/doc/org.contextmapper/context-mapper-dsl/latest/org/contextmapper/tactic/dsl/tacticdsl/DomainObject.html

IDE and Plugin (please complete the following information):
I am using the ContextMapper plugin for VSCode @ v6.12.0

@CesarD
Copy link

CesarD commented Oct 27, 2024

I'm experiencing the same on my side. Latest version to date of the VSCode extension.

@astmuc
Copy link

astmuc commented Nov 12, 2024

This snippet

BoundedContext PartyManagementContext {
	Aggregate Party {
		Trait Extensible {
			String type_
			String baseType
			URI schemaLocation
		}
		Trait Addressable {
			String id
			BigDecimal href
		}
		Entity Individual {
			aggregateRoot
			String firstname size =	"30"
			String lastname
			- List<Address> addresses
		}
		Entity Address with@Addressable with@Extensible {
			String street
			String city
		}

	}
}

works in my context-mapper 6.12.0 plugin. I did not yet investigate if the traits are really arriving in the model.

@CesarD
Copy link

CesarD commented Nov 12, 2024

Is that syntax valid, though? Seems weird to me, but I can't find any reference in the website docs, only a single mention in the Freemarker Generator section.
The code, however, displays as that's the syntax it's currently using, but I'd still like to know if that's the intended syntax or is an implementation error (I'd expect a space between "with" and the trait name):

@simonwfarrow
Copy link
Author

Thank you @astmuc for uncovering the supported syntax. I agree with @CesarD that it looks a bit odd, especially given the extends @SomeEntity (with space before @) syntax.

But happy it works at least!

I can confirm it is exposed in the model.

Should I leave this issue open given the above suspicions?

@astmuc
Copy link

astmuc commented Nov 13, 2024

I suggest to keep the ticket open as question about the right syntax. Sculpture documentation says the @ is needed for internal references. On the other hand it is optional in the xtext syntax definition.

@stefan-ka
Copy link
Member

It is optional, but then it is not a reference. With the @, the a validator actually checks that the type is modelled. Without the @ you can write any type without having to model it explicitely.

@simonwfarrow
Copy link
Author

Ok thanks - will leave open.

I guess the outstanding question is , why is does the syntax differ between:

Entity NewEntity extends @SomeEntity
Entity NewEntity with@SomeTrait

@astmuc
Copy link

astmuc commented Dec 9, 2024

The reason for this strange behavior seems to be a special meaning of 'with' inside of a DSL created by Xtext. If i replace 'with' by 'using' in the tactics language definition file, then one can use the space after 'using' as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants