Skip to content

Commit

Permalink
Remove keywords from reserved names
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Nov 2, 2022
1 parent 48b6787 commit 17699dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 71 deletions.
74 changes: 6 additions & 68 deletions packages/langium/src/grammar/langium-grammar-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class LangiumGrammarValidationRegistry extends ValidationRegistry {
validator.checkHiddenTerminalRule,
validator.checkEmptyTerminalRule
],
InferredType: validator.checkReservedTypeName,
InferredType: validator.checkTypeReservedName,
Keyword: validator.checkKeyword,
UnorderedGroup: validator.checkUnorderedGroup,
Grammar: [
Expand All @@ -69,9 +69,9 @@ export class LangiumGrammarValidationRegistry extends ValidationRegistry {
],
GrammarImport: validator.checkPackageImport,
CharacterRange: validator.checkInvalidCharacterRange,
Interface: validator.checkReservedTypeName,
Type: validator.checkReservedTypeName,
TypeAttribute: validator.checkReservedTypeName,
Interface: validator.checkTypeReservedName,
Type: validator.checkTypeReservedName,
TypeAttribute: validator.checkTypeReservedName,
RuleCall: [
validator.checkUsedHiddenTerminalRule,
validator.checkUsedFragmentTerminalRule,
Expand Down Expand Up @@ -566,7 +566,7 @@ export class LangiumGrammarValidator {
}
}

checkReservedTypeName(type: ast.Interface | ast.TypeAttribute | ast.Type | ast.InferredType, accept: ValidationAcceptor): void {
checkTypeReservedName(type: ast.Interface | ast.TypeAttribute | ast.Type | ast.InferredType, accept: ValidationAcceptor): void {
this.checkReservedName(type, 'name', accept);
}

Expand Down Expand Up @@ -723,57 +723,6 @@ function isEmptyRule(rule: ast.AbstractRule): boolean {
}

const reservedNames = new Set([
// Keywords
'abstract',
'arguments',
'async',
'await',
'break',
'byte',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'enum',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'implements',
'import',
'in',
'instanceof',
'interface',
'let',
'long',
'new',
'null',
'package',
'private',
'protected',
'public',
'return',
'static',
'super',
'switch',
'this',
'throw',
'try',
'typeof',
'var',
'void',
'while',
'with',
'yield',
// Built-in objects, properties and methods
// Collections
'Array',
Expand Down Expand Up @@ -845,16 +794,5 @@ const reservedNames = new Set([
'Date',
'Intl',
'eval',
'prototype',
'hasOwnProperty',
'isPrototypeOf',
'length',
'toString',
'undefined',
'valueOf',
'clearInterval',
'setInterval',
'clearTimeout',
'setTimeout',
'process',
'undefined'
]);
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('Reserved names', () => {
});

test('Reserved assignment feature', async () => {
const text = 'X: await="X";';
const text = 'X: Map="X";';
expectReservedName(await validate(text), GrammarAST.isAssignment, 'feature');
});

Expand All @@ -340,7 +340,7 @@ describe('Reserved names', () => {
});

test('Reserved action feature', async () => {
const text = 'X: Y {infer Z.async=current} name="X"; Y: name="Y";';
const text = 'X: Y {infer Z.Map=current} name="X"; Y: name="Y";';
expectReservedName(await validate(text), GrammarAST.isAction, 'feature');
});

Expand All @@ -356,7 +356,7 @@ describe('Reserved names', () => {
});

test('Reserved type attribute name', async () => {
const text = 'interface X { async: number }';
const text = 'interface X { Map: number }';
expectReservedName(await validate(text), GrammarAST.isTypeAttribute, 'name');
});

Expand Down

0 comments on commit 17699dc

Please sign in to comment.