"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const model = require("./lib-src-model.cjs");
const some = require("../../lodash-es/some2.cjs");
const includes = require("../../lodash-es/includes2.cjs");
const every = require("../../lodash-es/every2.cjs");
function isSequenceProd(prod) {
  return prod instanceof model.Alternative || prod instanceof model.Option || prod instanceof model.Repetition || prod instanceof model.RepetitionMandatory || prod instanceof model.RepetitionMandatoryWithSeparator || prod instanceof model.RepetitionWithSeparator || prod instanceof model.Terminal || prod instanceof model.Rule;
}
function isOptionalProd(prod, alreadyVisited = []) {
  const isDirectlyOptional = prod instanceof model.Option || prod instanceof model.Repetition || prod instanceof model.RepetitionWithSeparator;
  if (isDirectlyOptional) {
    return true;
  }
  if (prod instanceof model.Alternation) {
    return some.default(prod.definition, (subProd) => {
      return isOptionalProd(subProd, alreadyVisited);
    });
  } else if (prod instanceof model.NonTerminal && includes.default(alreadyVisited, prod)) {
    return false;
  } else if (prod instanceof model.AbstractProduction) {
    if (prod instanceof model.NonTerminal) {
      alreadyVisited.push(prod);
    }
    return every.default(prod.definition, (subProd) => {
      return isOptionalProd(subProd, alreadyVisited);
    });
  } else {
    return false;
  }
}
function isBranchingProd(prod) {
  return prod instanceof model.Alternation;
}
function getProductionDslName(prod) {
  if (prod instanceof model.NonTerminal) {
    return "SUBRULE";
  } else if (prod instanceof model.Option) {
    return "OPTION";
  } else if (prod instanceof model.Alternation) {
    return "OR";
  } else if (prod instanceof model.RepetitionMandatory) {
    return "AT_LEAST_ONE";
  } else if (prod instanceof model.RepetitionMandatoryWithSeparator) {
    return "AT_LEAST_ONE_SEP";
  } else if (prod instanceof model.RepetitionWithSeparator) {
    return "MANY_SEP";
  } else if (prod instanceof model.Repetition) {
    return "MANY";
  } else if (prod instanceof model.Terminal) {
    return "CONSUME";
  } else {
    throw Error("non exhaustive match");
  }
}
exports.getProductionDslName = getProductionDslName;
exports.isBranchingProd = isBranchingProd;
exports.isOptionalProd = isOptionalProd;
exports.isSequenceProd = isSequenceProd;
//# sourceMappingURL=lib-src-helpers.cjs.map
