function constructFactory(onreturn, fields) {
    return hook

    // Handle either an object mapping codes to constructs, a list of
    // constructs, or a single construct.
    function hook(constructs, returnState, bogusState) {
      var listOfConstructs
      var constructIndex
      var currentConstruct
      var info

      return constructs.tokenize || 'length' in constructs
        ? handleListOfConstructs(miniflat(constructs))
        : handleMapOfConstructs

      function handleMapOfConstructs(code) {
        if (code in constructs || codes.eof in constructs) {
          return handleListOfConstructs(
            constructs.null
              ? /* c8 ignore next */
                miniflat(constructs[code]).concat(miniflat(constructs.null))
              : constructs[code]
          )(code)
        }

        return bogusState(code)
      }

      function handleListOfConstructs(list) {
        listOfConstructs = list
        constructIndex = 0
        return handleConstruct(list[constructIndex])
      }

      function handleConstruct(construct) {
        return start

        function start(code) {
          // To do: not nede to store if there is no bogus state, probably?
          // Currently doesn’t work because `inspect` in document does a check
          // w/o a bogus, which doesn’t make sense. But it does seem to help perf
          // by not storing.
          info = store()
          currentConstruct = construct

          if (!construct.partial) {
            context.currentConstruct = construct
          }

          if (
            construct.name &&
            context.parser.constructs.disable.null.indexOf(construct.name) > -1
          ) {
            return nok(code)
          }

          return construct.tokenize.call(
            fields ? assign({}, context, fields) : context,
            effects,
            ok,
            nok
          )(code)
        }
      }

      function ok(code) {
        assert__default['default'].equal(code, expectedCode, 'expected code')
        consumed = true
        onreturn(currentConstruct, info)
        return returnState
      }

      function nok(code) {
        assert__default['default'].equal(code, expectedCode, 'expected code')
        consumed = true
        info.restore()

        if (++constructIndex < listOfConstructs.length) {
          return handleConstruct(listOfConstructs[constructIndex])
        }

        return bogusState
      }
    }
  }
// Factory to attempt/check/interrupt.
Factory to attempt/check/interrupt.
Factory to attempt / check / interrupt .
function constructFactory(onreturn, fields) {
    return hook
    function hook(constructs, returnState, bogusState) {
      var listOfConstructs
      var constructIndex
      var currentConstruct
      var info
      return constructs.tokenize || 'length' in constructs
        ? handleListOfConstructs(miniflat(constructs))
        : handleMapOfConstructs
      function handleMapOfConstructs(code) {
        if (code in constructs || codes.eof in constructs) {
          return handleListOfConstructs(
            constructs.null
              ? 
                miniflat(constructs[code]).concat(miniflat(constructs.null))
              : constructs[code]
          )(code)
        }
        return bogusState(code)
      }
      function handleListOfConstructs(list) {
        listOfConstructs = list
        constructIndex = 0
        return handleConstruct(list[constructIndex])
      }
      function handleConstruct(construct) {
        return start
        function start(code) {
          info = store()
          currentConstruct = construct
          if (!construct.partial) {
            context.currentConstruct = construct
          }
          if (
            construct.name &&
            context.parser.constructs.disable.null.indexOf(construct.name) > -1
          ) {
            return nok(code)
          }
          return construct.tokenize.call(
            fields ? assign({}, context, fields) : context,
            effects,
            ok,
            nok
          )(code)
        }
      }
      function ok(code) {
        assert__default['default'].equal(code, expectedCode, 'expected code')
        consumed = true
        onreturn(currentConstruct, info)
        return returnState
      }
      function nok(code) {
        assert__default['default'].equal(code, expectedCode, 'expected code')
        consumed = true
        info.restore()
        if (++constructIndex < listOfConstructs.length) {
          return handleConstruct(listOfConstructs[constructIndex])
        }
        return bogusState
      }
    }
  }
function constructFactory ( onreturn , fields ) { return hook function hook ( constructs , returnState , bogusState ) { var listOfConstructs var constructIndex var currentConstruct var info return constructs . tokenize || 'length' in constructs ? handleListOfConstructs ( miniflat ( constructs ) ) : handleMapOfConstructs function handleMapOfConstructs ( code ) { if ( code in constructs || codes . eof in constructs ) { return handleListOfConstructs ( constructs . null ? miniflat ( constructs [ code ] ) . concat ( miniflat ( constructs . null ) ) : constructs [ code ] ) ( code ) } return bogusState ( code ) } function handleListOfConstructs ( list ) { listOfConstructs = list constructIndex = 0 return handleConstruct ( list [ constructIndex ] ) } function handleConstruct ( construct ) { return start function start ( code ) { info = store ( ) currentConstruct = construct if ( ! construct . partial ) { context . currentConstruct = construct } if ( construct . name && context . parser . constructs . disable . null . indexOf ( construct . name ) > - 1 ) { return nok ( code ) } return construct . tokenize . call ( fields ? assign ( { } , context , fields ) : context , effects , ok , nok ) ( code ) } } function ok ( code ) { assert__default [ 'default' ] . equal ( code , expectedCode , 'expected code' ) consumed = true onreturn ( currentConstruct , info ) return returnState } function nok ( code ) { assert__default [ 'default' ] . equal ( code , expectedCode , 'expected code' ) consumed = true info . restore ( ) if ( ++ constructIndex < listOfConstructs . length ) { return handleConstruct ( listOfConstructs [ constructIndex ] ) } return bogusState } } }
Factory to attempt/check/interrupt.
Factory to attempt / check / interrupt .
// Handle either an object mapping codes to constructs, a list of // constructs, or a single construct. /* c8 ignore next */ // To do: not nede to store if there is no bogus state, probably? // Currently doesn’t work because `inspect` in document does a check // w/o a bogus, which doesn’t make sense. But it does seem to help perf // by not storing.