import lexicalAnalysis from "./lexical-analysis/node.mjs";
import syntacticAnalysis from "./syntactic-analysis/indirect/index.mjs";
export { mediaTypes, namespace } from "./adapter.mjs";
export { lexicalAnalysis, syntacticAnalysis };

/**
 * @public
 */
export const detect = async source => {
  const cst = await lexicalAnalysis(source);
  try {
    return !cst.rootNode.isError;
  } catch {
    return false;
  } finally {
    cst.delete();
  }
};

/**
 * @public
 */

/**
 * @public
 */

/**
 * @public
 */
export const parse = async (source, {
  sourceMap = false
} = {}) => {
  const cst = await lexicalAnalysis(source);
  try {
    return syntacticAnalysis(cst, {
      sourceMap
    });
  } finally {
    cst.delete();
  }
};