Skip to content

fix: Validation errors when using true or false as prefix of id #530

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

Merged
merged 2 commits into from
Jul 1, 2023
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
16 changes: 7 additions & 9 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export function isAttributeName(item: unknown): item is AttributeName {
return isDataModelAttributeName(item) || isDataModelFieldAttributeName(item) || isInternalAttributeName(item);
}

export type Boolean = boolean;

export function isBoolean(item: unknown): item is Boolean {
return typeof item === 'boolean';
}

export type BuiltinType = 'BigInt' | 'Boolean' | 'Bytes' | 'DateTime' | 'Decimal' | 'Float' | 'Int' | 'Json' | 'String';

export function isBuiltinType(item: unknown): item is BuiltinType {
Expand Down Expand Up @@ -422,7 +428,7 @@ export function isInvocationExpr(item: unknown): item is InvocationExpr {
export interface LiteralExpr extends AstNode {
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | DataSourceField | FieldInitializer | FunctionDecl | GeneratorField | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType;
readonly $type: 'LiteralExpr';
value: boolean | number | string
value: Boolean | number | string
}

export const LiteralExpr = 'LiteralExpr';
Expand Down Expand Up @@ -856,14 +862,6 @@ export class ZModelAstReflection extends AbstractAstReflection {
]
};
}
case 'LiteralExpr': {
return {
name: 'LiteralExpr',
mandatory: [
{ name: 'value', type: 'boolean' }
]
};
}
case 'Model': {
return {
name: 'Model',
Expand Down
40 changes: 25 additions & 15 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
"$ref": "#/rules@55"
},
"arguments": []
},
Expand Down Expand Up @@ -3258,28 +3258,38 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"wildcard": false
},
{
"$type": "TerminalRule",
"hidden": true,
"name": "WS",
"$type": "ParserRule",
"name": "Boolean",
"dataType": "boolean",
"definition": {
"$type": "RegexToken",
"regex": "\\\\s+"
"$type": "Alternatives",
"elements": [
{
"$type": "Keyword",
"value": "true"
},
{
"$type": "Keyword",
"value": "false"
}
]
},
"fragment": false
"definesHiddenTokens": false,
"entry": false,
"fragment": false,
"hiddenTokens": [],
"parameters": [],
"wildcard": false
},
{
"$type": "TerminalRule",
"name": "BOOLEAN",
"type": {
"$type": "ReturnType",
"name": "boolean"
},
"hidden": true,
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "true|false"
"regex": "\\\\s+"
},
"fragment": false,
"hidden": false
"fragment": false
},
{
"$type": "TerminalRule",
Expand Down
6 changes: 4 additions & 2 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Expression:
LogicalExpr;

LiteralExpr:
value=(BOOLEAN | NUMBER | STRING);
value=(Boolean | NUMBER | STRING);

ArrayExpr:
'[' (items+=Expression (',' items+=Expression)*)? ']';
Expand Down Expand Up @@ -255,8 +255,10 @@ ExpressionType returns string:
BuiltinType returns string:
'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Decimal' | 'DateTime' | 'Json' | 'Bytes';

Boolean returns boolean:
'true' | 'false';

hidden terminal WS: /\s+/;
terminal BOOLEAN returns boolean: /true|false/;
terminal NULL: 'null';
terminal THIS: 'this';
terminal ID: /[_a-zA-Z][\w_]*/;
Expand Down
13 changes: 13 additions & 0 deletions packages/schema/tests/schema/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,17 @@ describe('Parsing Tests', () => {
`;
await loadModel(content, false);
});

it('boolean prefix id', async () => {
const content = `
model trueModel {
id String @id
isPublic Boolean @default(false)
trueText String?
falseText String?
@@allow('all', isPublic == true)
}
`;
await loadModel(content, false);
});
});