Replies: 2 comments 5 replies
-
Hey @nbrouwers, looking at the generated export function isType_BigDecimal(item: unknown): item is Type_BigDecimal {
return item === 'BigDecimal';
} Can you confirm that this is generated for your language as well? Can you also confirm (maybe via debugging or similar) that the values you pass in there are actually what you think you're passing in there? Given that the generated checking function is pretty simple, I assume there's something else going on. |
Beta Was this translation helpful? Give feedback.
-
Hi @msujew, thanks for your quick reply. The generateType function is called from the generateAttribute function as shown below: generateAttribute(gen) {
return toNode `${gen.name} ${this.generateType(gen.type)}`;
} In this context, the most generic type to pass is Type, generalizing both TypeReference and BasicType. Note that the check isTypeReference in the beginning works as expected; in case the type parameter is of type TypeReference, the expression evaluates to true. And yes, I can confirm that these check functions are generated for all BasicType types. export type BasicType = 'BigDecimal' | 'BigInteger' | 'Date' | 'DateTime' | 'Timestamp' | 'boolean' | 'double' | 'float' | 'int' | 'long' | 'string'; export type Type_BigDecimal = 'BigDecimal';
export function isType_BigDecimal(item: unknown): item is Type_BigDecimal {
return item === 'BigDecimal';
}
export type Type_BigInteger = 'BigInteger';
export function isType_BigInteger(item: unknown): item is Type_BigInteger {
return item === 'BigInteger';
}
export type Type_Boolean = 'boolean';
export function isType_Boolean(item: unknown): item is Type_Boolean {
return item === 'boolean';
}
export type Type_Date = 'Date';
export function isType_Date(item: unknown): item is Type_Date {
return item === 'Date';
}
export type Type_DateTime = 'DateTime';
export function isType_DateTime(item: unknown): item is Type_DateTime {
return item === 'DateTime';
}
export type Type_Double = 'double';
export function isType_Double(item: unknown): item is Type_Double {
return item === 'double';
}
export type Type_Float = 'float';
export function isType_Float(item: unknown): item is Type_Float {
return item === 'float';
}
export type Type_Integer = 'int';
export function isType_Integer(item: unknown): item is Type_Integer {
return item === 'int';
}
export type Type_Long = 'long';
export function isType_Long(item: unknown): item is Type_Long {
return item === 'long';
}
export type Type_String = 'string';
export function isType_String(item: unknown): item is Type_String {
return item === 'string';
}
export type Type_Timestamp = 'Timestamp';
export function isType_Timestamp(item: unknown): item is Type_Timestamp {
return item === 'Timestamp';
} |
Beta Was this translation helpful? Give feedback.
-
Hi all,
We are developing a DSL for the domain of Domain Driven Design. Amongst others, it contains Entities that have Attributes. Attributes have a name and type property. See below for a small example:
The attribute's type can be a TypeReference, e.g. referencing ValueObject Barcode, or a primitive/basic type, e.g. like assigning it a type like int.
For the development of a code generator for this DSL, we need to check the value of the Attribute's type. Specially, we'd like to do something like this:
The problem is that the isType_ variants from the generated ast.ts never evaluate to true.
We suspect this has to do with BasicType not being considered as a specific type of Type, maybe since BasicType is a Langium type and not a parser rule?
So the question: could someone recommend a robust way to check on the value of a BasicType?
For reference, the relevant grammar is the following:
Beta Was this translation helpful? Give feedback.
All reactions