/* Copyright © 2020 Splunk Inc.
SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
in part without a valid written license from Splunk Inc. is PROHIBITED. */
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __esm = (fn, res) => function __init() {
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// <define:global>
var init_define_global = __esm({
  "<define:global>"() {
  }
});

// src/nearley/generated/vizparser.js
var require_vizparser = __commonJS({
  "src/nearley/generated/vizparser.js"(exports, module2) {
    init_define_global();
    (function() {
      function arrpush(d) {
        return d[0].concat([d[1]]);
      }
      function id(x) {
        return x[0];
      }
      function parseNull() {
        return null;
      }
      function parseString(d) {
        return { type: "string", v: d[0] };
      }
      function parseJoin(d) {
        return d[1].join("");
      }
      var grammar2 = {
        Lexer: void 0,
        ParserRules: [
          { name: "_$ebnf$1", symbols: [] },
          {
            name: "_$ebnf$1",
            symbols: ["_$ebnf$1", "wschar"],
            postprocess: arrpush
          },
          {
            name: "_",
            symbols: ["_$ebnf$1"],
            postprocess: parseNull
          },
          { name: "__$ebnf$1", symbols: ["wschar"] },
          {
            name: "__$ebnf$1",
            symbols: ["__$ebnf$1", "wschar"],
            postprocess: arrpush
          },
          {
            name: "__",
            symbols: ["__$ebnf$1"],
            postprocess: parseNull
          },
          { name: "wschar", symbols: [/[ \t\n\v\f]/], postprocess: id },
          { name: "dqstring$ebnf$1", symbols: [] },
          {
            name: "dqstring$ebnf$1",
            symbols: ["dqstring$ebnf$1", "dstrchar"],
            postprocess: arrpush
          },
          {
            name: "dqstring",
            symbols: [{ literal: '"' }, "dqstring$ebnf$1", { literal: '"' }],
            postprocess: parseJoin
          },
          { name: "sqstring$ebnf$1", symbols: [] },
          {
            name: "sqstring$ebnf$1",
            symbols: ["sqstring$ebnf$1", "sstrchar"],
            postprocess: arrpush
          },
          {
            name: "sqstring",
            symbols: [{ literal: "'" }, "sqstring$ebnf$1", { literal: "'" }],
            postprocess: parseJoin
          },
          { name: "btstring$ebnf$1", symbols: [] },
          {
            name: "btstring$ebnf$1",
            symbols: ["btstring$ebnf$1", /[^`]/],
            postprocess: arrpush
          },
          {
            name: "btstring",
            symbols: [{ literal: "`" }, "btstring$ebnf$1", { literal: "`" }],
            postprocess: parseJoin
          },
          { name: "dstrchar", symbols: [/[^\\"\n]/], postprocess: id },
          {
            name: "dstrchar",
            symbols: [{ literal: "\\" }, "strescape"],
            postprocess: function(d) {
              return JSON.parse('"' + d.join("") + '"');
            }
          },
          { name: "sstrchar", symbols: [/[^\\'\n]/], postprocess: id },
          {
            name: "sstrchar",
            symbols: [{ literal: "\\" }, "strescape"],
            postprocess: function(d) {
              return JSON.parse('"' + d.join("") + '"');
            }
          },
          {
            name: "sstrchar$string$1",
            symbols: [{ literal: "\\" }, { literal: "'" }],
            postprocess: function joiner(d) {
              return d.join("");
            }
          },
          {
            name: "sstrchar",
            symbols: ["sstrchar$string$1"],
            postprocess: function(d) {
              return "'";
            }
          },
          { name: "strescape", symbols: [/["\\/bfnrt]/], postprocess: id },
          {
            name: "strescape",
            symbols: [{ literal: "u" }, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/, /[a-fA-F0-9]/],
            postprocess: function(d) {
              return d.join("");
            }
          },
          { name: "unsigned_int$ebnf$1", symbols: [/[0-9]/] },
          {
            name: "unsigned_int$ebnf$1",
            symbols: ["unsigned_int$ebnf$1", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "unsigned_int",
            symbols: ["unsigned_int$ebnf$1"],
            postprocess: function(d) {
              return parseInt(d[0].join(""));
            }
          },
          { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "-" }] },
          { name: "int$ebnf$1$subexpression$1", symbols: [{ literal: "+" }] },
          { name: "int$ebnf$1", symbols: ["int$ebnf$1$subexpression$1"], postprocess: id },
          {
            name: "int$ebnf$1",
            symbols: [],
            postprocess: parseNull
          },
          { name: "int$ebnf$2", symbols: [/[0-9]/] },
          {
            name: "int$ebnf$2",
            symbols: ["int$ebnf$2", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "int",
            symbols: ["int$ebnf$1", "int$ebnf$2"],
            postprocess: function(d) {
              if (d[0]) {
                return parseInt(d[0][0] + d[1].join(""));
              } else {
                return parseInt(d[1].join(""));
              }
            }
          },
          { name: "unsigned_decimal$ebnf$1", symbols: [/[0-9]/] },
          {
            name: "unsigned_decimal$ebnf$1",
            symbols: ["unsigned_decimal$ebnf$1", /[0-9]/],
            postprocess: arrpush
          },
          { name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
          {
            name: "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1",
            symbols: ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "unsigned_decimal$ebnf$2$subexpression$1",
            symbols: [{ literal: "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]
          },
          {
            name: "unsigned_decimal$ebnf$2",
            symbols: ["unsigned_decimal$ebnf$2$subexpression$1"],
            postprocess: id
          },
          {
            name: "unsigned_decimal$ebnf$2",
            symbols: [],
            postprocess: parseNull
          },
          {
            name: "unsigned_decimal",
            symbols: ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"],
            postprocess: function(d) {
              return parseFloat(d[0].join("") + (d[1] ? "." + d[1][1].join("") : ""));
            }
          },
          { name: "decimal$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
          {
            name: "decimal$ebnf$1",
            symbols: [],
            postprocess: parseNull
          },
          { name: "decimal$ebnf$2", symbols: [/[0-9]/] },
          {
            name: "decimal$ebnf$2",
            symbols: ["decimal$ebnf$2", /[0-9]/],
            postprocess: arrpush
          },
          { name: "decimal$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
          {
            name: "decimal$ebnf$3$subexpression$1$ebnf$1",
            symbols: ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "decimal$ebnf$3$subexpression$1",
            symbols: [{ literal: "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"]
          },
          { name: "decimal$ebnf$3", symbols: ["decimal$ebnf$3$subexpression$1"], postprocess: id },
          {
            name: "decimal$ebnf$3",
            symbols: [],
            postprocess: parseNull
          },
          {
            name: "decimal",
            symbols: ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"],
            postprocess: function(d) {
              return parseFloat((d[0] || "") + d[1].join("") + (d[2] ? "." + d[2][1].join("") : ""));
            }
          },
          {
            name: "percentage",
            symbols: ["decimal", { literal: "%" }],
            postprocess: function(d) {
              return d[0] / 100;
            }
          },
          { name: "jsonfloat$ebnf$1", symbols: [{ literal: "-" }], postprocess: id },
          {
            name: "jsonfloat$ebnf$1",
            symbols: [],
            postprocess: parseNull
          },
          { name: "jsonfloat$ebnf$2", symbols: [/[0-9]/] },
          {
            name: "jsonfloat$ebnf$2",
            symbols: ["jsonfloat$ebnf$2", /[0-9]/],
            postprocess: arrpush
          },
          { name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1", symbols: [/[0-9]/] },
          {
            name: "jsonfloat$ebnf$3$subexpression$1$ebnf$1",
            symbols: ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "jsonfloat$ebnf$3$subexpression$1",
            symbols: [{ literal: "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]
          },
          { name: "jsonfloat$ebnf$3", symbols: ["jsonfloat$ebnf$3$subexpression$1"], postprocess: id },
          {
            name: "jsonfloat$ebnf$3",
            symbols: [],
            postprocess: parseNull
          },
          { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1", symbols: [/[+-]/], postprocess: id },
          {
            name: "jsonfloat$ebnf$4$subexpression$1$ebnf$1",
            symbols: [],
            postprocess: parseNull
          },
          { name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2", symbols: [/[0-9]/] },
          {
            name: "jsonfloat$ebnf$4$subexpression$1$ebnf$2",
            symbols: ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/],
            postprocess: arrpush
          },
          {
            name: "jsonfloat$ebnf$4$subexpression$1",
            symbols: [
              /[eE]/,
              "jsonfloat$ebnf$4$subexpression$1$ebnf$1",
              "jsonfloat$ebnf$4$subexpression$1$ebnf$2"
            ]
          },
          { name: "jsonfloat$ebnf$4", symbols: ["jsonfloat$ebnf$4$subexpression$1"], postprocess: id },
          {
            name: "jsonfloat$ebnf$4",
            symbols: [],
            postprocess: parseNull
          },
          {
            name: "jsonfloat",
            symbols: ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"],
            postprocess: function(d) {
              return parseFloat(
                (d[0] || "") + d[1].join("") + (d[2] ? "." + d[2][1].join("") : "") + (d[3] ? "e" + (d[3][1] || "+") + d[3][2].join("") : "")
              );
            }
          },
          { name: "Pipeline$ebnf$1", symbols: [] },
          { name: "Pipeline$ebnf$1$subexpression$1", symbols: [{ literal: "|" }, "Expr"] },
          {
            name: "Pipeline$ebnf$1",
            symbols: ["Pipeline$ebnf$1", "Pipeline$ebnf$1$subexpression$1"],
            postprocess: arrpush
          },
          {
            name: "Pipeline",
            symbols: ["Expr", "Pipeline$ebnf$1"],
            postprocess: (d) => {
              return [d[0], ...d[1].map((e) => e[1])];
            }
          },
          { name: "Expr", symbols: ["_", "Identifier", "_"], postprocess: (d) => d[1] },
          { name: "Expr", symbols: ["_", "Method", "_"], postprocess: (d) => d[1] },
          { name: "Expr", symbols: ["_", "Literal", "_"], postprocess: (d) => d[1] },
          { name: "Method$ebnf$1", symbols: ["Arg"], postprocess: id },
          {
            name: "Method$ebnf$1",
            symbols: [],
            postprocess: parseNull
          },
          { name: "Method$ebnf$2", symbols: [] },
          { name: "Method$ebnf$2$subexpression$1", symbols: ["_", { literal: "," }, "_", "Arg"] },
          {
            name: "Method$ebnf$2",
            symbols: ["Method$ebnf$2", "Method$ebnf$2$subexpression$1"],
            postprocess: arrpush
          },
          {
            name: "Method",
            symbols: [
              "Identifier",
              { literal: "(" },
              "_",
              "Method$ebnf$1",
              "Method$ebnf$2",
              "_",
              { literal: ")" }
            ],
            postprocess: (d) => {
              let arg0 = d[3];
              let otherArgs = d[4];
              let args = [];
              arg0 && args.push(arg0);
              if (otherArgs) {
                args = args.concat(otherArgs.map((e) => e[3]));
              }
              let r = { type: "method", name: d[0].v, args };
              return r;
            }
          },
          { name: "Arg", symbols: ["Identifier"], postprocess: (d) => d[0] },
          { name: "Arg", symbols: ["Literal"], postprocess: (d) => d[0] },
          { name: "Identifier$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$subexpression$1", symbols: ["Star"] },
          { name: "Identifier$ebnf$1", symbols: [] },
          { name: "Identifier$ebnf$1$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$1$subexpression$1", symbols: ["Digit"] },
          { name: "Identifier$ebnf$1$subexpression$1", symbols: ["Star"] },
          {
            name: "Identifier$ebnf$1",
            symbols: ["Identifier$ebnf$1", "Identifier$ebnf$1$subexpression$1"],
            postprocess: arrpush
          },
          {
            name: "Identifier",
            symbols: ["Identifier$subexpression$1", "Identifier$ebnf$1"],
            postprocess: (d) => {
              return { type: "identifier", v: d[0] + d[1].join("") };
            }
          },
          { name: "Identifier$subexpression$2", symbols: ["Letter"] },
          { name: "Identifier$subexpression$2", symbols: ["Star"] },
          { name: "Identifier$ebnf$2", symbols: [] },
          { name: "Identifier$ebnf$2$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$2$subexpression$1", symbols: ["Digit"] },
          { name: "Identifier$ebnf$2$subexpression$1", symbols: ["Star"] },
          {
            name: "Identifier$ebnf$2",
            symbols: ["Identifier$ebnf$2", "Identifier$ebnf$2$subexpression$1"],
            postprocess: arrpush
          },
          { name: "Identifier$ebnf$3$subexpression$1$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$3$subexpression$1$subexpression$1", symbols: ["Star"] },
          { name: "Identifier$ebnf$3$subexpression$1$ebnf$1", symbols: [] },
          { name: "Identifier$ebnf$3$subexpression$1$ebnf$1$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$3$subexpression$1$ebnf$1$subexpression$1", symbols: ["Digit"] },
          { name: "Identifier$ebnf$3$subexpression$1$ebnf$1$subexpression$1", symbols: ["Star"] },
          {
            name: "Identifier$ebnf$3$subexpression$1$ebnf$1",
            symbols: [
              "Identifier$ebnf$3$subexpression$1$ebnf$1",
              "Identifier$ebnf$3$subexpression$1$ebnf$1$subexpression$1"
            ],
            postprocess: arrpush
          },
          {
            name: "Identifier$ebnf$3$subexpression$1",
            symbols: [
              "Dot",
              "Identifier$ebnf$3$subexpression$1$subexpression$1",
              "Identifier$ebnf$3$subexpression$1$ebnf$1"
            ]
          },
          { name: "Identifier$ebnf$3", symbols: ["Identifier$ebnf$3$subexpression$1"] },
          { name: "Identifier$ebnf$3$subexpression$2$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$3$subexpression$2$subexpression$1", symbols: ["Star"] },
          { name: "Identifier$ebnf$3$subexpression$2$ebnf$1", symbols: [] },
          { name: "Identifier$ebnf$3$subexpression$2$ebnf$1$subexpression$1", symbols: ["Letter"] },
          { name: "Identifier$ebnf$3$subexpression$2$ebnf$1$subexpression$1", symbols: ["Digit"] },
          { name: "Identifier$ebnf$3$subexpression$2$ebnf$1$subexpression$1", symbols: ["Star"] },
          {
            name: "Identifier$ebnf$3$subexpression$2$ebnf$1",
            symbols: [
              "Identifier$ebnf$3$subexpression$2$ebnf$1",
              "Identifier$ebnf$3$subexpression$2$ebnf$1$subexpression$1"
            ],
            postprocess: arrpush
          },
          {
            name: "Identifier$ebnf$3$subexpression$2",
            symbols: [
              "Dot",
              "Identifier$ebnf$3$subexpression$2$subexpression$1",
              "Identifier$ebnf$3$subexpression$2$ebnf$1"
            ]
          },
          {
            name: "Identifier$ebnf$3",
            symbols: ["Identifier$ebnf$3", "Identifier$ebnf$3$subexpression$2"],
            postprocess: arrpush
          },
          {
            name: "Identifier",
            symbols: ["Identifier$subexpression$2", "Identifier$ebnf$2", "Identifier$ebnf$3"],
            postprocess: (d) => {
              function flat(input, depth = 1, stack = []) {
                for (let item of input) {
                  if (item instanceof Array && depth > 0) {
                    flat(item, depth - 1, stack);
                  } else {
                    stack.push(item);
                  }
                }
                return stack;
              }
              const r = flat(d, Infinity);
              return { type: "identifier", v: r.join("") };
            }
          },
          {
            name: "Literal",
            symbols: ["jsonfloat"],
            postprocess: (d) => {
              return { type: "number", v: d[0] };
            }
          },
          {
            name: "Literal",
            symbols: ["dqstring"],
            postprocess: parseString
          },
          {
            name: "Literal",
            symbols: ["sqstring"],
            postprocess: parseString
          },
          {
            name: "Literal",
            symbols: ["btstring"],
            postprocess: parseString
          },
          { name: "Letter", symbols: [/[a-zA-Z_]/], postprocess: (d) => d[0] },
          { name: "Digit", symbols: [/[0-9]/], postprocess: (d) => d[0] },
          { name: "Dot", symbols: [/[\.]/], postprocess: (d) => d[0] },
          { name: "Star", symbols: [{ literal: "*" }] }
        ],
        ParserStart: "Pipeline"
      };
      if (typeof module2 !== "undefined" && typeof module2.exports !== "undefined") {
        module2.exports = grammar2;
      } else {
        window.grammar = grammar2;
      }
    })();
  }
});

// src/EncodingParser.ts
var EncodingParser_exports = {};
__export(EncodingParser_exports, {
  default: () => EncodingParser
});
module.exports = __toCommonJS(EncodingParser_exports);
init_define_global();

// src/DslParser.ts
init_define_global();

// esm-externals:nearley
var nearley_exports = {};
__export(nearley_exports, {
  default: () => nearley_default
});
init_define_global();
var defaultImport = __toESM(require("nearley"));
__reExport(nearley_exports, require("nearley"));
var nearley_default = "default" in defaultImport ? defaultImport.default : defaultImport;

// src/DslParser.ts
var grammar = require_vizparser();
var _DslParser = class _DslParser {
  static parse(dsl) {
    if (_DslParser.cache[dsl]) {
      return [..._DslParser.cache[dsl]];
    }
    const parser = new nearley_exports.Parser(grammar);
    parser.feed(dsl);
    if (parser.results.length > 1) {
      console.warn(`Ambiguous parse of '${dsl}'`);
    }
    if (parser.results.length === 0) {
      console.warn(`No parsed results for '${dsl}'`);
    }
    _DslParser.cache[dsl] = [...parser.results[0]];
    return parser.results[0];
  }
};
_DslParser.cache = {};
var DslParser = _DslParser;

// src/EncodingParser.ts
var EncodingParser = class _EncodingParser {
  static parseOptions(optionsStanza) {
    const optionsAST = {
      simpleOptions: {},
      expressions: {},
      context: optionsStanza.context
    };
    const { options } = optionsStanza;
    Object.keys(options).forEach((k) => {
      const v = options[k];
      if (_EncodingParser.isDslString(v)) {
        optionsAST.expressions[k] = DslParser.parse(_EncodingParser.withoutArrow(v));
      } else {
        optionsAST.simpleOptions[k] = v;
      }
    });
    return optionsAST;
  }
  static isDslString(s) {
    return s ? s.toString().trim().startsWith(">") : false;
  }
  static withoutArrow(s) {
    return s.toString().match(/\s*>\s*(.+$)/)[1].trim();
  }
  static parse(encoding) {
    const { dimensions: dslFields, context } = encoding;
    const ast = { dimensions: {}, context };
    Object.keys(dslFields).forEach((f) => {
      const astDimension = { value: [] };
      let value = null;
      if (typeof dslFields[f] === "string") {
        value = dslFields[f];
      } else {
        const dim = dslFields[f];
        value = dim.value;
      }
      astDimension.value = DslParser.parse(value);
      ast.dimensions[f] = astDimension;
    });
    return ast;
  }
};
//# sourceMappingURL=EncodingParser.js.map
