Skip to content

Commit

Permalink
Always generate the mode meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Sep 19, 2024
1 parent 781d365 commit 5547dab
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion examples/arithmetics/src/language-server/generated/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { ArithmeticsGrammar } from './grammar.js';
export const ArithmeticsLanguageMetaData = {
languageId: 'arithmetics',
fileExtensions: ['.calc'],
caseInsensitive: true
caseInsensitive: true,
mode: 'development'
} as const satisfies LanguageMetaData;

export const ArithmeticsGeneratedSharedModule: Module<LangiumSharedCoreServices, LangiumGeneratedSharedCoreServices> = {
Expand Down
3 changes: 2 additions & 1 deletion examples/domainmodel/src/language-server/generated/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { DomainModelGrammar } from './grammar.js';
export const DomainModelLanguageMetaData = {
languageId: 'domain-model',
fileExtensions: ['.dmodel'],
caseInsensitive: false
caseInsensitive: false,
mode: 'development'
} as const satisfies LanguageMetaData;

export const parserConfig: IParserConfig = {
Expand Down
6 changes: 4 additions & 2 deletions examples/requirements/src/language-server/generated/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { RequirementsGrammar, TestsGrammar } from './grammar.js';
export const RequirementsLanguageMetaData = {
languageId: 'requirements-lang',
fileExtensions: ['.req'],
caseInsensitive: false
caseInsensitive: false,
mode: 'development'
} as const satisfies LanguageMetaData;

export const TestsLanguageMetaData = {
languageId: 'tests-lang',
fileExtensions: ['.tst'],
caseInsensitive: false
caseInsensitive: false,
mode: 'development'
} as const satisfies LanguageMetaData;

export const RequirementsAndTestsGeneratedSharedModule: Module<LangiumSharedCoreServices, LangiumGeneratedSharedCoreServices> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { StatemachineGrammar } from './grammar.js';
export const StatemachineLanguageMetaData = {
languageId: 'statemachine',
fileExtensions: ['.statemachine'],
caseInsensitive: false
caseInsensitive: false,
mode: 'development'
} as const satisfies LanguageMetaData;

export const StatemachineGeneratedSharedModule: Module<LangiumSharedCoreServices, LangiumGeneratedSharedCoreServices> = {
Expand Down
7 changes: 4 additions & 3 deletions packages/langium-cli/src/generator/module-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import type { Grammar, IParserConfig } from 'langium';
import { EOL, type Generated, expandToNode, joinToNode, toString } from 'langium/generate';
import { type Generated, expandToNode, joinToNode, toString } from 'langium/generate';
import type { LangiumConfig, LangiumLanguageConfig } from '../package-types.js';
import { generatedHeader } from './node-util.js';

Expand Down Expand Up @@ -42,13 +42,14 @@ export function generateModule(grammars: Grammar[], config: LangiumConfig, gramm
grammarsWithName,
grammar => {
const config = grammarConfigMap.get(grammar)!;
const modeValue = mode ? `,${EOL} mode: '${mode}'` : '';
const modeValue = mode === 'production' ? mode : 'development';
return expandToNode`
export const ${ grammar.name }LanguageMetaData = {
languageId: '${config.id}',
fileExtensions: [${config.fileExtensions && joinToNode(config.fileExtensions, e => appendQuotesAndDot(e), { separator: ', ' })}],
caseInsensitive: ${Boolean(config.caseInsensitive)}${modeValue}
caseInsensitive: ${Boolean(config.caseInsensitive)},
mode: '${modeValue}'
} as const satisfies LanguageMetaData;
`;
},
Expand Down
3 changes: 2 additions & 1 deletion packages/langium/src/grammar/generated/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { LangiumGrammarGrammar } from './grammar.js';
export const LangiumGrammarLanguageMetaData = {
languageId: 'langium',
fileExtensions: ['.langium'],
caseInsensitive: false
caseInsensitive: false,
mode: 'development'
} as const satisfies LanguageMetaData;

export const LangiumGrammarParserConfig: IParserConfig = {
Expand Down
6 changes: 3 additions & 3 deletions packages/langium/src/languages/language-meta-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export interface LanguageMetaData {
caseInsensitive: boolean;
/**
* Mode used to optimize code for development or production environments.
*
* In production mode, all lexer/parser validations are disabled.
*
* In production mode, all Chevrotain lexer/parser validations are disabled.
*/
mode?: 'development' | 'production';
mode: 'development' | 'production';
}

0 comments on commit 5547dab

Please sign in to comment.