Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function isDataModel(item: unknown): item is DataModel {
}

export interface DataModelAttribute extends AstNode {
readonly $container: DataModel;
readonly $container: DataModel | Enum;
readonly $type: 'DataModelAttribute';
args: Array<AttributeArg>
decl: Reference<Attribute>
Expand Down Expand Up @@ -204,7 +204,7 @@ export function isDataModelField(item: unknown): item is DataModelField {
}

export interface DataModelFieldAttribute extends AstNode {
readonly $container: DataModelField;
readonly $container: DataModelField | EnumField;
readonly $type: 'DataModelFieldAttribute';
args: Array<AttributeArg>
decl: Reference<Attribute>
Expand Down Expand Up @@ -260,6 +260,8 @@ export function isDataSourceField(item: unknown): item is DataSourceField {
export interface Enum extends AstNode {
readonly $container: Model;
readonly $type: 'Enum';
attributes: Array<DataModelAttribute>
comments: Array<string>
fields: Array<EnumField>
name: string
}
Expand All @@ -273,6 +275,8 @@ export function isEnum(item: unknown): item is Enum {
export interface EnumField extends AstNode {
readonly $container: DataModel | Enum | FunctionDecl;
readonly $type: 'EnumField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
name: string
}

Expand Down Expand Up @@ -697,10 +701,21 @@ export class ZModelAstReflection extends AbstractAstReflection {
return {
name: 'Enum',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' },
{ name: 'fields', type: 'array' }
]
};
}
case 'EnumField': {
return {
name: 'EnumField',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' }
]
};
}
case 'FunctionDecl': {
return {
name: 'FunctionDecl',
Expand Down
143 changes: 105 additions & 38 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,13 +1603,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
},
{
Expand Down Expand Up @@ -1638,11 +1647,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": []
},
"arguments": [],
"cardinality": "*"
},
{
Expand All @@ -1666,16 +1680,33 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"value": "{"
},
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@30"
"$type": "Alternatives",
"elements": [
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@30"
},
"arguments": []
}
},
"arguments": []
},
{
"$type": "Assignment",
"feature": "attributes",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@43"
},
"arguments": []
}
}
],
"cardinality": "+"
},
{
Expand All @@ -1698,11 +1729,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": []
},
"arguments": [],
"cardinality": "*"
},
{
Expand All @@ -1716,6 +1752,19 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
},
"arguments": []
}
},
{
"$type": "Assignment",
"feature": "attributes",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@42"
},
"arguments": []
},
"cardinality": "*"
}
]
},
Expand Down Expand Up @@ -1937,13 +1986,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
}
]
Expand Down Expand Up @@ -2334,13 +2392,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
},
{
Expand Down
18 changes: 12 additions & 6 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fragment ReferenceArgList:
args+=ReferenceArg (',' args+=ReferenceArg)*;

ReferenceArg:
name=('sort') ':' value=('Asc'| 'Desc');
name=('sort') ':' value=('Asc' | 'Desc');

InvocationExpr:
function=[FunctionDecl] '(' ArgumentList? ')';
Expand Down Expand Up @@ -145,14 +145,20 @@ DataModelField:
name=ID type=DataModelFieldType (attributes+=DataModelFieldAttribute)*;

DataModelFieldType:
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[]')? (optional?='?')?;
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[' ']')? (optional?='?')?;

// enum
Enum:
TRIPLE_SLASH_COMMENT* 'enum' name=ID '{' (fields+=EnumField)+ '}';
(comments+=TRIPLE_SLASH_COMMENT)*
'enum' name=ID '{' (
fields+=EnumField
| attributes+=DataModelAttribute
)+
'}';

EnumField:
TRIPLE_SLASH_COMMENT* name=ID;
(comments+=TRIPLE_SLASH_COMMENT)*
name=ID (attributes+=DataModelFieldAttribute)*;

// function
FunctionDecl:
Expand All @@ -162,7 +168,7 @@ FunctionParam:
TRIPLE_SLASH_COMMENT* name=ID ':' type=FunctionParamType;

FunctionParamType:
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[]')?;
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[' ']')?;

QualifiedName returns string:
ID ('.' ID)*;
Expand Down Expand Up @@ -192,7 +198,7 @@ AttributeParam:
// FieldReference refers to fields declared in the current model
// TransitiveFieldReference refers to fields declared in the model type of the current field
AttributeParamType:
(type=(ExpressionType | 'FieldReference' | 'TransitiveFieldReference' | 'ContextType') | reference=[TypeDeclaration:ID]) (array?='[]')? (optional?='?')?;
(type=(ExpressionType | 'FieldReference' | 'TransitiveFieldReference' | 'ContextType') | reference=[TypeDeclaration:ID]) (array?='[' ']')? (optional?='?')?;

type TypeDeclaration = DataModel | Enum;

Expand Down
Loading