'use strict';

// Lookahead keys are 32Bit integers in the form
// TTTTTTTT-ZZZZZZZZZZZZ-YYYY-XXXXXXXX
// XXXX -> Occurrence Index bitmap.
// YYYY -> DSL Method Type bitmap.
// ZZZZZZZZZZZZZZZ -> Rule short Index bitmap.
// TTTTTTTTT -> alternation alternative index bitmap
const BITS_FOR_METHOD_TYPE = 4;
const BITS_FOR_OCCURRENCE_IDX = 8;
// short string used as part of mapping keys.
// being short improves the performance when composing KEYS for maps out of these
// The 5 - 8 bits (16 possible values, are reserved for the DSL method indices)
const OR_IDX = 1 << BITS_FOR_OCCURRENCE_IDX;
const OPTION_IDX = 2 << BITS_FOR_OCCURRENCE_IDX;
const MANY_IDX = 3 << BITS_FOR_OCCURRENCE_IDX;
const AT_LEAST_ONE_IDX = 4 << BITS_FOR_OCCURRENCE_IDX;
const MANY_SEP_IDX = 5 << BITS_FOR_OCCURRENCE_IDX;
const AT_LEAST_ONE_SEP_IDX = 6 << BITS_FOR_OCCURRENCE_IDX;
// this actually returns a number, but it is always used as a string (object prop key)
function getKeyForAutomaticLookahead(ruleIdx, dslMethodIdx, occurrence) {
    return occurrence | dslMethodIdx | ruleIdx;
}

exports.AT_LEAST_ONE_IDX = AT_LEAST_ONE_IDX;
exports.AT_LEAST_ONE_SEP_IDX = AT_LEAST_ONE_SEP_IDX;
exports.BITS_FOR_METHOD_TYPE = BITS_FOR_METHOD_TYPE;
exports.BITS_FOR_OCCURRENCE_IDX = BITS_FOR_OCCURRENCE_IDX;
exports.MANY_IDX = MANY_IDX;
exports.MANY_SEP_IDX = MANY_SEP_IDX;
exports.OPTION_IDX = OPTION_IDX;
exports.OR_IDX = OR_IDX;
exports.getKeyForAutomaticLookahead = getKeyForAutomaticLookahead;
