Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

langium-cli

Package Overview
Dependencies
Maintainers
4
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

langium-cli - npm Package Compare versions

Comparing version 3.0.0-next.79e4301 to 3.0.0-next.cc1a49c

30

lib/generate.js

@@ -8,4 +8,4 @@ /******************************************************************************

import { loadConfig } from './package.js';
import { copyAstNode, getDocument, GrammarAST, linkContentToContainer } from 'langium';
import { createLangiumGrammarServices, resolveImport, resolveTransitiveImports } from 'langium/grammar';
import { AstUtils, GrammarAST } from 'langium';
import { createLangiumGrammarServices, resolveImport, resolveImportUri, resolveTransitiveImports } from 'langium/grammar';
import { NodeFileSystem } from 'langium/node';

@@ -97,3 +97,3 @@ import { generateAst } from './generator/ast-generator.js';

const documents = sharedServices.workspace.LangiumDocuments;
function eagerLoad(document, uris = new Set()) {
async function eagerLoad(document, uris = new Set()) {
const uriString = document.uri.toString();

@@ -105,6 +105,6 @@ if (!uris.has(uriString)) {

for (const imp of grammar.imports) {
const importedGrammar = resolveImport(documents, imp);
if (importedGrammar) {
const importedDoc = getDocument(importedGrammar);
eagerLoad(importedDoc, uris);
const importUri = resolveImportUri(imp);
if (importUri) {
const document = await sharedServices.workspace.LangiumDocuments.getOrCreateDocument(importUri);
await eagerLoad(document, uris);
}

@@ -122,3 +122,3 @@ }

for (const grammar of grammars) {
const doc = getDocument(grammar);
const doc = AstUtils.getDocument(grammar);
const uriString = doc.uri.toString();

@@ -144,3 +144,3 @@ if (!visited.has(uriString)) {

for (const element of grammarElements) {
const copy = copyAstNode(element, buildReference);
const copy = AstUtils.copyAstNode(element, buildReference);
// Deactivate copied entry rule

@@ -167,3 +167,3 @@ if (GrammarAST.isParserRule(copy)) {

// Link newly added elements to grammar
linkContentToContainer(grammarCopy);
AstUtils.linkContentToContainer(grammarCopy);
return grammarCopy;

@@ -184,3 +184,3 @@ }

const newDocuments = grammars.map(e => {
const uri = getDocument(e).uri;
const uri = AstUtils.getDocument(e).uri;
const newDoc = documentFactory.fromModel(e, uri);

@@ -202,4 +202,4 @@ e.$document = newDoc;

const absGrammarPath = URI.file(path.resolve(relPath, languageConfig.grammar));
const document = documents.getOrCreateDocument(absGrammarPath);
eagerLoad(document, uris);
const document = await documents.getOrCreateDocument(absGrammarPath);
await eagerLoad(document, uris);
}

@@ -378,3 +378,3 @@ for (const doc of documents.all) {

}
const grammarDoc = await doLoadAndUpdate(documents.getOrCreateDocument(URI.file(grammarPath)));
const grammarDoc = await doLoadAndUpdate(await documents.getOrCreateDocument(URI.file(grammarPath)));
const genTypes = generateTypesFile(grammarServices, [grammarDoc.parseResult.value]);

@@ -389,3 +389,3 @@ await writeWithFail(typesFilePath, genTypes, { watch: false });

async function doLoadAndUpdate(grammarDoc) {
const allUris = eagerLoad(grammarDoc);
const allUris = await eagerLoad(grammarDoc);
await sharedServices.workspace.DocumentBuilder.update(allUris, []);

@@ -392,0 +392,0 @@ for (const doc of documents.all) {

@@ -6,5 +6,5 @@ /******************************************************************************

******************************************************************************/
import type { Grammar, LangiumServices } from 'langium';
import type { Grammar, LangiumCoreServices } from 'langium';
import type { LangiumConfig } from '../package.js';
export declare function generateAst(services: LangiumServices, grammars: Grammar[], config: LangiumConfig): string;
export declare function generateAst(services: LangiumCoreServices, grammars: Grammar[], config: LangiumConfig): string;
//# sourceMappingURL=ast-generator.d.ts.map
import { expandToNode, joinToNode, toString } from 'langium/generate';
import { streamAllContents, MultiMap, GrammarAST } from 'langium';
import { AstUtils, MultiMap, GrammarAST } from 'langium';
import { collectAst, collectTypeHierarchy, findReferenceTypes, isAstType, mergeTypesAndInterfaces } from 'langium/grammar';

@@ -28,3 +28,3 @@ import { collectTerminalRegexps, generatedHeader } from './util.js';

function hasCrossReferences(grammar) {
return Boolean(streamAllContents(grammar).find(GrammarAST.isCrossReference));
return Boolean(AstUtils.streamAllContents(grammar).find(GrammarAST.isCrossReference));
}

@@ -68,3 +68,3 @@ function generateAstReflection(config, astTypes) {

${joinToNode(astTypes.interfaces, interfaceType => {
const props = interfaceType.properties;
const props = interfaceType.superProperties;
return (props.length > 0)

@@ -71,0 +71,0 @@ ? expandToNode `

@@ -6,5 +6,5 @@ /******************************************************************************

******************************************************************************/
import type { Grammar, LangiumServices } from 'langium';
import type { Grammar, LangiumCoreServices } from 'langium';
import type { LangiumConfig } from '../package.js';
export declare function serializeGrammar(services: LangiumServices, grammars: Grammar[], config: LangiumConfig): string;
export declare function serializeGrammar(services: LangiumCoreServices, grammars: Grammar[], config: LangiumConfig): string;
//# sourceMappingURL=grammar-serializer.d.ts.map

@@ -29,2 +29,3 @@ /******************************************************************************

space: production ? undefined : 2,
comments: true,
uriConverter

@@ -31,0 +32,0 @@ });

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import { getTerminalParts, isCommentTerminal, escapeRegExp, GrammarAST, isWhitespaceRegExp, terminalRegex } from 'langium';
import { GrammarAST, GrammarUtils, RegExpUtils } from 'langium';
import { expandToNode, joinToNode, toString } from 'langium/generate';

@@ -128,3 +128,3 @@ import { collectKeywords } from '../util.js';

${ /* special case, identify symbols via singular regex*/undefined}
symbols: ${new RegExp(languageDef.symbols.map(escapeRegExp).join('|')).toString()},
symbols: ${new RegExp(languageDef.symbols.map(RegExpUtils.escapeRegExp).join('|')).toString()},
`;

@@ -217,4 +217,4 @@ }

if (GrammarAST.isTerminalRule(rule)) {
const regex = terminalRegex(rule);
if (!isCommentTerminal(rule) && !isWhitespaceRegExp(regex)) {
const regex = GrammarUtils.terminalRegex(rule);
if (!GrammarUtils.isCommentTerminal(rule) && !RegExpUtils.isWhitespace(regex)) {
// skip rules that are not comments or whitespace

@@ -224,6 +224,6 @@ continue;

// token name is either comment or whitespace
const tokenName = isCommentTerminal(rule) ? 'comment' : 'white';
const part = getTerminalParts(regex)[0];
const tokenName = GrammarUtils.isCommentTerminal(rule) ? 'comment' : 'white';
const part = RegExpUtils.getTerminalParts(regex)[0];
// check if this is a comment terminal w/ a start & end sequence (multi-line)
if (part.start !== '' && part.end !== '' && isCommentTerminal(rule)) {
if (part.start !== '' && part.end !== '' && GrammarUtils.isCommentTerminal(rule)) {
// state-based comment rule, only add push to jump into it

@@ -255,5 +255,5 @@ rules.push({

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && isCommentTerminal(rule)) {
if (GrammarAST.isTerminalRule(rule) && GrammarUtils.isCommentTerminal(rule)) {
const tokenName = 'comment';
const part = getTerminalParts(terminalRegex(rule))[0];
const part = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(rule))[0];
if (part.start !== '' && part.end !== '') {

@@ -292,5 +292,5 @@ // rules to manage comment start/end

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && !isCommentTerminal(rule)) {
const regex = terminalRegex(rule);
if (isWhitespaceRegExp(regex)) {
if (GrammarAST.isTerminalRule(rule) && !GrammarUtils.isCommentTerminal(rule)) {
const regex = GrammarUtils.terminalRegex(rule);
if (RegExpUtils.isWhitespace(regex)) {
// disallow terminal rules that match whitespace

@@ -297,0 +297,0 @@ continue;

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import { terminalRegex, GrammarAST, escapeRegExp, isCommentTerminal } from 'langium';
import { GrammarAST, GrammarUtils, RegExpUtils } from 'langium';
import { expandToNode, joinToNode, toString } from 'langium/generate';

@@ -18,6 +18,6 @@ import _ from 'lodash';

const modifier = config.caseInsensitive ? 'i' : '';
const commentTerminals = terminals.filter(isCommentTerminal);
const commentTerminals = terminals.filter(GrammarUtils.isCommentTerminal);
if (commentTerminals.length === 1) {
highlighter.comment = {
pattern: terminalRegex(commentTerminals[0]).toString(),
pattern: GrammarUtils.terminalRegex(commentTerminals[0]).toString(),
greedy: true

@@ -28,3 +28,3 @@ };

highlighter.comment = commentTerminals.map(e => ({
pattern: terminalRegex(e).toString(),
pattern: GrammarUtils.terminalRegex(e).toString(),
greedy: true

@@ -36,7 +36,7 @@ }));

highlighter.string = {
pattern: terminalRegex(stringTerminal).toString(),
pattern: GrammarUtils.terminalRegex(stringTerminal).toString(),
greedy: true
};
}
const filteredKeywords = keywords.filter(e => idRegex.test(e)).sort((a, b) => b.length - a.length).map(escapeRegExp);
const filteredKeywords = keywords.filter(e => idRegex.test(e)).sort((a, b) => b.length - a.length).map(RegExpUtils.escapeRegExp);
highlighter.keyword = {

@@ -43,0 +43,0 @@ pattern: `/\\b(${filteredKeywords.join('|')})\\b/${modifier}`

@@ -1,2 +0,2 @@

import { escapeRegExp, getCaseInsensitivePattern, getTerminalParts, GrammarAST, isCommentTerminal, stream, terminalRegex } from 'langium';
import { GrammarAST, GrammarUtils, RegExpUtils, stream } from 'langium';
import { collectKeywords } from '../util.js';

@@ -28,4 +28,4 @@ export function generateTextMate(grammar, config) {

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && isCommentTerminal(rule)) {
const parts = getTerminalParts(terminalRegex(rule));
if (GrammarAST.isTerminalRule(rule) && GrammarUtils.isCommentTerminal(rule)) {
const parts = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(rule));
for (const part of parts) {

@@ -92,3 +92,3 @@ if (part.end) {

keywords.forEach(keyword => {
const keywordPattern = caseInsensitive ? getCaseInsensitivePattern(keyword) : escapeRegExp(keyword);
const keywordPattern = caseInsensitive ? RegExpUtils.getCaseInsensitivePattern(keyword) : RegExpUtils.escapeRegExp(keyword);
if (/\w/.test(keyword[0])) {

@@ -127,3 +127,3 @@ if (/\w/.test(keyword[keyword.length - 1])) {

if (stringTerminal) {
const parts = getTerminalParts(terminalRegex(stringTerminal));
const parts = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(stringTerminal));
for (const part of parts) {

@@ -130,0 +130,0 @@ if (part.end) {

@@ -21,3 +21,4 @@ /******************************************************************************

import type { Module } from '../../dependency-injection${config.importExtension}';
import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices } from '../../services${config.importExtension}';
import type { LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices } from '../../services${config.importExtension}';
import type { LangiumSharedServices, LangiumServices } from '../../lsp/lsp-services${config.importExtension}';
`.appendTemplateIf(hasIParserConfigImport) `

@@ -28,3 +29,4 @@

import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module${hasIParserConfigImport ? ', IParserConfig' : ''} } from 'langium';
import type { LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices, LanguageMetaData, Module${hasIParserConfigImport ? ', IParserConfig' : ''} } from 'langium';
import type { LangiumSharedServices, LangiumServices } from 'langium/lsp';
import { ${config.projectName}AstReflection } from './ast${config.importExtension}';

@@ -67,3 +69,3 @@ `.appendTemplate `

export const ${config.projectName}GeneratedSharedModule: Module<LangiumSharedServices, LangiumGeneratedSharedServices> = {
export const ${config.projectName}GeneratedSharedModule: Module<LangiumSharedServices, LangiumGeneratedSharedCoreServices> = {
AstReflection: () => new ${config.projectName}AstReflection()

@@ -75,3 +77,3 @@ };

export const ${grammar.name}GeneratedModule: Module<LangiumServices, LangiumGeneratedServices> = {
export const ${grammar.name}GeneratedModule: Module<LangiumServices, LangiumGeneratedCoreServices> = {
Grammar: () => ${grammar.name}Grammar(),

@@ -78,0 +80,0 @@ LanguageMetaData: () => ${grammar.name}LanguageMetaData,

@@ -6,4 +6,4 @@ /******************************************************************************

******************************************************************************/
import type { Grammar, LangiumServices } from 'langium';
export declare function generateTypesFile(services: LangiumServices, grammars: Grammar[]): string;
import type { Grammar, LangiumCoreServices } from 'langium';
export declare function generateTypesFile(services: LangiumCoreServices, grammars: Grammar[]): string;
//# sourceMappingURL=types-generator.d.ts.map

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import { getAllReachableRules, GrammarAST, stream, streamAllContents, terminalRegex } from 'langium';
import { AstUtils, GrammarAST, GrammarUtils, stream } from 'langium';
import { expandToNode } from 'langium/generate';

@@ -55,6 +55,6 @@ import fs from 'fs-extra';

const keywords = new Set();
const reachableRules = getAllReachableRules(grammar, false);
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false);
for (const keyword of stream(reachableRules)
.filter(GrammarAST.isParserRule)
.flatMap(rule => streamAllContents(rule).filter(GrammarAST.isKeyword))) {
.flatMap(rule => AstUtils.streamAllContents(rule).filter(GrammarAST.isKeyword))) {
keywords.add(keyword.value);

@@ -89,6 +89,6 @@ }

const result = {};
const reachableRules = getAllReachableRules(grammar, false);
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false);
for (const terminalRule of stream(reachableRules).filter(GrammarAST.isTerminalRule)) {
const name = terminalRule.name;
const regexp = terminalRegex(terminalRule);
const regexp = GrammarUtils.terminalRegex(terminalRule);
result[name] = regexp;

@@ -95,0 +95,0 @@ }

@@ -7,2 +7,3 @@ /******************************************************************************

import fs from 'fs-extra';
import { EOL } from 'os';
import * as path from 'path';

@@ -31,2 +32,5 @@ import { log } from './generator/util.js';

const relativePath = path.dirname(filePath);
if (!path.isAbsolute(filePath)) {
filePath = path.resolve(process.cwd(), filePath);
}
log('log', options, `Reading config from ${chalk.white.bold(filePath)}`);

@@ -36,2 +40,5 @@ try {

const config = path.basename(filePath) === 'package.json' ? obj.langium : obj;
if (!config) {
throw new Error('Langium config is missing.');
}
config[RelativePath] = relativePath;

@@ -42,3 +49,6 @@ (_a = config.importExtension) !== null && _a !== void 0 ? _a : (config.importExtension = '.js');

catch (err) {
log('error', options, chalk.red('Failed to read config file.'), err);
const suffix = options.file
? path.basename(filePath) === 'package.json' ? `an object named 'langium' in ${filePath}` : filePath
: `${path.resolve(path.dirname(filePath), 'langium-config.json')} or an object named 'langium' in ${path.resolve(path.dirname(filePath), 'package.json')}`;
log('error', options, chalk.red(`Failed to read Langium config: Could not find ${suffix}.${EOL}`), err);
process.exit(1);

@@ -45,0 +55,0 @@ }

@@ -1,2 +0,2 @@

import { getDocument, GrammarAST, prepareLangiumParser } from 'langium';
import { AstUtils, GrammarAST, prepareLangiumParser } from 'langium';
import { createServicesForGrammar } from 'langium/grammar';

@@ -29,3 +29,3 @@ import { getFilePath } from './package.js';

if (rule && rule.$cstNode) {
const filePath = getFilePath(getDocument(rule).uri.fsPath, config);
const filePath = getFilePath(AstUtils.getDocument(rule).uri.fsPath, config);
const line = rule.$cstNode.range.start.line + 1;

@@ -32,0 +32,0 @@ message += `${filePath}:${line} - `;

{
"name": "langium-cli",
"version": "3.0.0-next.79e4301",
"version": "3.0.0-next.cc1a49c",
"description": "CLI for Langium - the language engineering tool",

@@ -46,4 +46,4 @@ "homepage": "https://langium.org",

"jsonschema": "~1.4.1",
"langium": "3.0.0-next.79e4301",
"langium-railroad": "3.0.0-next.79e4301",
"langium": "3.0.0-next.cc1a49c",
"langium-railroad": "3.0.0-next.cc1a49c",
"lodash": "~4.17.21"

@@ -50,0 +50,0 @@ },

@@ -11,4 +11,4 @@ /******************************************************************************

import { loadConfig } from './package.js';
import { copyAstNode, getDocument, GrammarAST, linkContentToContainer } from 'langium';
import { createLangiumGrammarServices, resolveImport, resolveTransitiveImports } from 'langium/grammar';
import { AstUtils, GrammarAST } from 'langium';
import { createLangiumGrammarServices, resolveImport, resolveImportUri, resolveTransitiveImports } from 'langium/grammar';
import { NodeFileSystem } from 'langium/node';

@@ -127,3 +127,3 @@ import { generateAst } from './generator/ast-generator.js';

function eagerLoad(document: LangiumDocument, uris: Set<string> = new Set()): URI[] {
async function eagerLoad(document: LangiumDocument, uris: Set<string> = new Set()): Promise<URI[]> {
const uriString = document.uri.toString();

@@ -135,6 +135,6 @@ if (!uris.has(uriString)) {

for (const imp of grammar.imports) {
const importedGrammar = resolveImport(documents, imp);
if (importedGrammar) {
const importedDoc = getDocument(importedGrammar);
eagerLoad(importedDoc, uris);
const importUri = resolveImportUri(imp);
if (importUri) {
const document = await sharedServices.workspace.LangiumDocuments.getOrCreateDocument(importUri);
await eagerLoad(document, uris);
}

@@ -154,3 +154,3 @@ }

for (const grammar of grammars) {
const doc = getDocument(grammar);
const doc = AstUtils.getDocument(grammar);
const uriString = doc.uri.toString();

@@ -179,3 +179,3 @@ if (!visited.has(uriString)) {

for (const element of grammarElements) {
const copy = copyAstNode(element, buildReference);
const copy = AstUtils.copyAstNode(element, buildReference);
// Deactivate copied entry rule

@@ -202,3 +202,3 @@ if (GrammarAST.isParserRule(copy)) {

// Link newly added elements to grammar
linkContentToContainer(grammarCopy);
AstUtils.linkContentToContainer(grammarCopy);
return grammarCopy;

@@ -220,3 +220,3 @@ }

const newDocuments = grammars.map(e => {
const uri = getDocument(e).uri;
const uri = AstUtils.getDocument(e).uri;
const newDoc = documentFactory.fromModel(e, uri);

@@ -239,4 +239,4 @@ (e as Mutable<AstNode>).$document = newDoc;

const absGrammarPath = URI.file(path.resolve(relPath, languageConfig.grammar));
const document = documents.getOrCreateDocument(absGrammarPath);
eagerLoad(document, uris);
const document = await documents.getOrCreateDocument(absGrammarPath);
await eagerLoad(document, uris);
}

@@ -430,4 +430,3 @@ for (const doc of documents.all) {

}
const grammarDoc = await doLoadAndUpdate(documents.getOrCreateDocument(URI.file(grammarPath)));
const grammarDoc = await doLoadAndUpdate(await documents.getOrCreateDocument(URI.file(grammarPath)));
const genTypes = generateTypesFile(grammarServices, [grammarDoc.parseResult.value as Grammar]);

@@ -443,3 +442,3 @@ await writeWithFail(typesFilePath, genTypes, { watch: false });

async function doLoadAndUpdate(grammarDoc: LangiumDocument): Promise<LangiumDocument> {
const allUris = eagerLoad(grammarDoc);
const allUris = await eagerLoad(grammarDoc);
await sharedServices.workspace.DocumentBuilder.update(allUris, []);

@@ -446,0 +445,0 @@ for (const doc of documents.all) {

@@ -6,11 +6,11 @@ /******************************************************************************

******************************************************************************/
import type { Grammar, LangiumServices } from 'langium';
import type { Grammar, LangiumCoreServices } from 'langium';
import { type Generated, expandToNode, joinToNode, toString } from 'langium/generate';
import type { AstTypes, Property, PropertyDefaultValue } from 'langium/grammar';
import type { LangiumConfig } from '../package.js';
import { streamAllContents, MultiMap, GrammarAST } from 'langium';
import { AstUtils, MultiMap, GrammarAST } from 'langium';
import { collectAst, collectTypeHierarchy, findReferenceTypes, isAstType, mergeTypesAndInterfaces } from 'langium/grammar';
import { collectTerminalRegexps, generatedHeader } from './util.js';
export function generateAst(services: LangiumServices, grammars: Grammar[], config: LangiumConfig): string {
export function generateAst(services: LangiumCoreServices, grammars: Grammar[], config: LangiumConfig): string {
const astTypes = collectAst(grammars, services.shared.workspace.LangiumDocuments);

@@ -41,3 +41,3 @@ const crossRef = grammars.some(grammar => hasCrossReferences(grammar));

function hasCrossReferences(grammar: Grammar): boolean {
return Boolean(streamAllContents(grammar).find(GrammarAST.isCrossReference));
return Boolean(AstUtils.streamAllContents(grammar).find(GrammarAST.isCrossReference));
}

@@ -86,3 +86,3 @@

interfaceType => {
const props = interfaceType.properties;
const props = interfaceType.superProperties;
return (props.length > 0)

@@ -89,0 +89,0 @@ ? expandToNode`

@@ -7,3 +7,3 @@ /******************************************************************************

import type { Grammar, LangiumServices, Reference } from 'langium';
import type { Grammar, LangiumCoreServices, Reference } from 'langium';
import { expandToNode, joinToNode, normalizeEOL, toString } from 'langium/generate';

@@ -14,3 +14,3 @@ import type { URI } from 'vscode-uri';

export function serializeGrammar(services: LangiumServices, grammars: Grammar[], config: LangiumConfig): string {
export function serializeGrammar(services: LangiumCoreServices, grammars: Grammar[], config: LangiumConfig): string {
const node = expandToNode`

@@ -41,2 +41,3 @@ ${generatedHeader}

space: production ? undefined : 2,
comments: true,
uriConverter

@@ -43,0 +44,0 @@ });

@@ -7,3 +7,3 @@ /******************************************************************************

import { type Grammar, getTerminalParts, isCommentTerminal, escapeRegExp, GrammarAST, isWhitespaceRegExp, terminalRegex } from 'langium';
import { type Grammar, GrammarAST, GrammarUtils, RegExpUtils } from 'langium';
import { type Generated, expandToNode, joinToNode, toString } from 'langium/generate';

@@ -229,3 +229,3 @@ import type { LangiumLanguageConfig } from '../../package.js';

${/* special case, identify symbols via singular regex*/ undefined}
symbols: ${new RegExp(languageDef.symbols.map(escapeRegExp).join('|')).toString()},
symbols: ${new RegExp(languageDef.symbols.map(RegExpUtils.escapeRegExp).join('|')).toString()},
`;

@@ -320,5 +320,5 @@ }

if (GrammarAST.isTerminalRule(rule)) {
const regex = terminalRegex(rule);
const regex = GrammarUtils.terminalRegex(rule);
if (!isCommentTerminal(rule) && !isWhitespaceRegExp(regex)) {
if (!GrammarUtils.isCommentTerminal(rule) && !RegExpUtils.isWhitespace(regex)) {
// skip rules that are not comments or whitespace

@@ -329,8 +329,8 @@ continue;

// token name is either comment or whitespace
const tokenName = isCommentTerminal(rule) ? 'comment' : 'white';
const tokenName = GrammarUtils.isCommentTerminal(rule) ? 'comment' : 'white';
const part = getTerminalParts(regex)[0];
const part = RegExpUtils.getTerminalParts(regex)[0];
// check if this is a comment terminal w/ a start & end sequence (multi-line)
if (part.start !== '' && part.end !== '' && isCommentTerminal(rule)) {
if (part.start !== '' && part.end !== '' && GrammarUtils.isCommentTerminal(rule)) {
// state-based comment rule, only add push to jump into it

@@ -363,5 +363,5 @@ rules.push({

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && isCommentTerminal(rule)) {
if (GrammarAST.isTerminalRule(rule) && GrammarUtils.isCommentTerminal(rule)) {
const tokenName = 'comment';
const part = getTerminalParts(terminalRegex(rule))[0];
const part = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(rule))[0];
if (part.start !== '' && part.end !== '') {

@@ -406,6 +406,6 @@ // rules to manage comment start/end

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && !isCommentTerminal(rule)) {
const regex = terminalRegex(rule);
if (GrammarAST.isTerminalRule(rule) && !GrammarUtils.isCommentTerminal(rule)) {
const regex = GrammarUtils.terminalRegex(rule);
if (isWhitespaceRegExp(regex)) {
if (RegExpUtils.isWhitespace(regex)) {
// disallow terminal rules that match whitespace

@@ -412,0 +412,0 @@ continue;

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import { terminalRegex, GrammarAST, escapeRegExp, isCommentTerminal, type Grammar } from 'langium';
import { GrammarAST, type Grammar, GrammarUtils, RegExpUtils } from 'langium';
import { expandToNode, joinToNode, toString, type Generated } from 'langium/generate';

@@ -27,6 +27,6 @@ import _ from 'lodash';

const commentTerminals = terminals.filter(isCommentTerminal);
const commentTerminals = terminals.filter(GrammarUtils.isCommentTerminal);
if (commentTerminals.length === 1) {
highlighter.comment = {
pattern: terminalRegex(commentTerminals[0]).toString(),
pattern: GrammarUtils.terminalRegex(commentTerminals[0]).toString(),
greedy: true

@@ -36,3 +36,3 @@ };

highlighter.comment = commentTerminals.map(e => ({
pattern: terminalRegex(e).toString(),
pattern: GrammarUtils.terminalRegex(e).toString(),
greedy: true

@@ -44,7 +44,7 @@ }));

highlighter.string = {
pattern: terminalRegex(stringTerminal).toString(),
pattern: GrammarUtils.terminalRegex(stringTerminal).toString(),
greedy: true
};
}
const filteredKeywords = keywords.filter(e => idRegex.test(e)).sort((a, b) => b.length - a.length).map(escapeRegExp);
const filteredKeywords = keywords.filter(e => idRegex.test(e)).sort((a, b) => b.length - a.length).map(RegExpUtils.escapeRegExp);
highlighter.keyword = {

@@ -51,0 +51,0 @@ pattern: `/\\b(${filteredKeywords.join('|')})\\b/${modifier}`

@@ -7,3 +7,3 @@ /******************************************************************************

import type { Grammar } from 'langium';
import { escapeRegExp, getCaseInsensitivePattern, getTerminalParts, GrammarAST, isCommentTerminal, stream, terminalRegex } from 'langium';
import { GrammarAST, GrammarUtils, RegExpUtils, stream } from 'langium';
import type { LangiumLanguageConfig } from '../../package.js';

@@ -78,4 +78,4 @@ import { collectKeywords } from '../util.js';

for (const rule of grammar.rules) {
if (GrammarAST.isTerminalRule(rule) && isCommentTerminal(rule)) {
const parts = getTerminalParts(terminalRegex(rule));
if (GrammarAST.isTerminalRule(rule) && GrammarUtils.isCommentTerminal(rule)) {
const parts = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(rule));
for (const part of parts) {

@@ -149,3 +149,3 @@ if (part.end) {

keywords.forEach(keyword => {
const keywordPattern = caseInsensitive ? getCaseInsensitivePattern(keyword) : escapeRegExp(keyword);
const keywordPattern = caseInsensitive ? RegExpUtils.getCaseInsensitivePattern(keyword) : RegExpUtils.escapeRegExp(keyword);
if (/\w/.test(keyword[0])) {

@@ -179,3 +179,3 @@ if (/\w/.test(keyword[keyword.length - 1])) {

if (stringTerminal) {
const parts = getTerminalParts(terminalRegex(stringTerminal));
const parts = RegExpUtils.getTerminalParts(GrammarUtils.terminalRegex(stringTerminal));
for (const part of parts) {

@@ -182,0 +182,0 @@ if (part.end) {

@@ -28,3 +28,4 @@ /******************************************************************************

import type { Module } from '../../dependency-injection${config.importExtension}';
import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices } from '../../services${config.importExtension}';
import type { LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices } from '../../services${config.importExtension}';
import type { LangiumSharedServices, LangiumServices } from '../../lsp/lsp-services${config.importExtension}';
`.appendTemplateIf(hasIParserConfigImport)`

@@ -36,3 +37,4 @@

import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module${hasIParserConfigImport ? ', IParserConfig' : ''} } from 'langium';
import type { LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices, LanguageMetaData, Module${hasIParserConfigImport ? ', IParserConfig' : ''} } from 'langium';
import type { LangiumSharedServices, LangiumServices } from 'langium/lsp';
import { ${config.projectName}AstReflection } from './ast${config.importExtension}';

@@ -82,3 +84,3 @@ `.appendTemplate`

export const ${config.projectName}GeneratedSharedModule: Module<LangiumSharedServices, LangiumGeneratedSharedServices> = {
export const ${config.projectName}GeneratedSharedModule: Module<LangiumSharedServices, LangiumGeneratedSharedCoreServices> = {
AstReflection: () => new ${config.projectName}AstReflection()

@@ -92,3 +94,3 @@ };

export const ${grammar.name}GeneratedModule: Module<LangiumServices, LangiumGeneratedServices> = {
export const ${grammar.name}GeneratedModule: Module<LangiumServices, LangiumGeneratedCoreServices> = {
Grammar: () => ${grammar.name}Grammar(),

@@ -95,0 +97,0 @@ LanguageMetaData: () => ${grammar.name}LanguageMetaData,

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import type { Grammar, LangiumServices } from 'langium';
import type { Grammar, LangiumCoreServices } from 'langium';
import { joinToNode, toString } from 'langium/generate';

@@ -12,3 +12,3 @@ import { collectAst, LangiumGrammarGrammar } from 'langium/grammar';

export function generateTypesFile(services: LangiumServices, grammars: Grammar[]): string {
export function generateTypesFile(services: LangiumCoreServices, grammars: Grammar[]): string {
const { unions, interfaces } = collectAst(grammars, services.shared.workspace.LangiumDocuments);

@@ -15,0 +15,0 @@ const reservedWords = new Set(collectKeywords(LangiumGrammarGrammar()));

@@ -6,3 +6,3 @@ /******************************************************************************

******************************************************************************/
import { type Grammar, getAllReachableRules, GrammarAST, stream, streamAllContents, terminalRegex } from 'langium';
import { AstUtils, type Grammar, GrammarAST, GrammarUtils, stream } from 'langium';
import { type Generated, expandToNode } from 'langium/generate';

@@ -63,7 +63,7 @@ import fs from 'fs-extra';

const keywords = new Set<string>();
const reachableRules = getAllReachableRules(grammar, false);
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false);
for (const keyword of stream(reachableRules)
.filter(GrammarAST.isParserRule)
.flatMap(rule => streamAllContents(rule).filter(GrammarAST.isKeyword))) {
.flatMap(rule => AstUtils.streamAllContents(rule).filter(GrammarAST.isKeyword))) {
keywords.add(keyword.value);

@@ -102,6 +102,6 @@ }

const result: Record<string, RegExp> = {};
const reachableRules = getAllReachableRules(grammar, false);
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false);
for (const terminalRule of stream(reachableRules).filter(GrammarAST.isTerminalRule)) {
const name = terminalRule.name;
const regexp = terminalRegex(terminalRule);
const regexp = GrammarUtils.terminalRegex(terminalRule);
result[name] = regexp;

@@ -108,0 +108,0 @@ }

@@ -9,2 +9,3 @@ /******************************************************************************

import type { IParserConfig } from 'langium';
import { EOL } from 'os';
import * as path from 'path';

@@ -96,6 +97,12 @@ import type { GenerateOptions } from './generate.js';

const relativePath = path.dirname(filePath);
if (!path.isAbsolute(filePath)) {
filePath = path.resolve(process.cwd(), filePath);
}
log('log', options, `Reading config from ${chalk.white.bold(filePath)}`);
try {
const obj = await fs.readJson(filePath, { encoding: 'utf-8' });
const config: LangiumConfig = path.basename(filePath) === 'package.json' ? obj.langium : obj;
const config: LangiumConfig | undefined = path.basename(filePath) === 'package.json' ? obj.langium : obj;
if (!config) {
throw new Error('Langium config is missing.');
}
config[RelativePath] = relativePath;

@@ -105,5 +112,8 @@ config.importExtension ??= '.js';

} catch (err) {
log('error', options, chalk.red('Failed to read config file.'), err);
const suffix = options.file
? path.basename(filePath) === 'package.json' ? `an object named 'langium' in ${filePath}` : filePath
: `${path.resolve(path.dirname(filePath), 'langium-config.json')} or an object named 'langium' in ${path.resolve(path.dirname(filePath), 'package.json')}`;
log('error', options, chalk.red(`Failed to read Langium config: Could not find ${suffix}.${EOL}`), err);
process.exit(1);
}
}

@@ -8,3 +8,3 @@ /******************************************************************************

import type { LangiumConfig, LangiumLanguageConfig } from './package.js';
import { getDocument, GrammarAST, prepareLangiumParser } from 'langium';
import { AstUtils, GrammarAST, prepareLangiumParser } from 'langium';
import type { LangiumGrammarServices} from 'langium/grammar';

@@ -43,3 +43,3 @@ import { createServicesForGrammar } from 'langium/grammar';

if (rule && rule.$cstNode) {
const filePath = getFilePath(getDocument(rule).uri.fsPath, config);
const filePath = getFilePath(AstUtils.getDocument(rule).uri.fsPath, config);
const line = rule.$cstNode.range.start.line + 1;

@@ -46,0 +46,0 @@ message += `${filePath}:${line} - `;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc