import ohmGrammar from '../dist/ohm-grammar.js';import {buildGrammar} from './buildGrammar.js';import * as common from './common.js';import * as errors from './errors.js';import {Grammar} from './Grammar.js';import * as pexprs from './pexprs.js';import * as util from './util.js';
import './semanticsDeferredInit.js'; Grammar.initApplicationParser(ohmGrammar, buildGrammar);
const isBuffer = obj => !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
function compileAndLoad(source, namespace) { const m = ohmGrammar.match(source, 'Grammars'); if (m.failed()) { throw errors.grammarSyntaxError(m); } return buildGrammar(m, namespace);}
export function grammar(source, optNamespace) { const ns = grammars(source, optNamespace);
const grammarNames = Object.keys(ns); if (grammarNames.length === 0) { throw new Error('Missing grammar definition'); } else if (grammarNames.length > 1) { const secondGrammar = ns[grammarNames[1]]; const interval = secondGrammar.source; throw new Error( util.getLineAndColumnMessage(interval.sourceString, interval.startIdx) + 'Found more than one grammar definition -- use ohm.grammars() instead.', ); } return ns[grammarNames[0]]; }
export function grammars(source, optNamespace) { const ns = Object.create(optNamespace || {}); if (typeof source !== 'string') { if (isBuffer(source)) { source = source.toString(); } else { throw new TypeError( 'Expected string as first argument, got ' + common.unexpectedObjToString(source), ); } } compileAndLoad(source, ns); return ns;}
export {buildGrammar as _buildGrammar};
export * from './main-kernel.js';export {IndentationSensitive as ExperimentalIndentationSensitive} from './IndentationSensitive.js';export {ohmGrammar};export {pexprs};export {version} from './version.js';