'use strict';

var defaultModule = require('../default-module.js');
var dependencyInjection = require('../dependency-injection.js');
var ast = require('../languages/generated/ast.js');
var fileSystemProvider = require('../workspace/file-system-provider.js');
require('./uri-utils.js');
var index = require('../../../../../vscode-uri@3.0.8/node_modules/vscode-uri/lib/esm/index.js');

/******************************************************************************
 * Copyright 2023 TypeFox GmbH
 * This program and the accompanying materials are made available under the
 * terms of the MIT License, which is available in the project root.
 ******************************************************************************/
const minimalGrammarModule = {
    Grammar: () => undefined,
    LanguageMetaData: () => ({
        caseInsensitive: false,
        fileExtensions: ['.langium'],
        languageId: 'langium'
    })
};
const minimalSharedGrammarModule = {
    AstReflection: () => new ast.LangiumGrammarAstReflection()
};
function createMinimalGrammarServices() {
    const shared = dependencyInjection.inject(defaultModule.createDefaultSharedCoreModule(fileSystemProvider.EmptyFileSystem), minimalSharedGrammarModule);
    const grammar = dependencyInjection.inject(defaultModule.createDefaultCoreModule({ shared }), minimalGrammarModule);
    shared.ServiceRegistry.register(grammar);
    return grammar;
}
/**
 * Load a Langium grammar for your language from a JSON string. This is used by several services,
 * most notably the parser builder which interprets the grammar to create a parser.
 */
function loadGrammarFromJson(json) {
    var _a;
    const services = createMinimalGrammarServices();
    const astNode = services.serializer.JsonSerializer.deserialize(json);
    services.shared.workspace.LangiumDocumentFactory.fromModel(astNode, index.URI.parse(`memory://${(_a = astNode.name) !== null && _a !== void 0 ? _a : 'grammar'}.langium`));
    return astNode;
}

exports.loadGrammarFromJson = loadGrammarFromJson;
