Quick test to show how character spans match original BEL String

    Mostly for debugging purposes
770163
def print_spans(spans, max_idx: int) -> None:
    

    bel_spans = [" "] * (max_idx + 3)
    for val, span in spans:
        if val in ["Nested", "NSArg"]:
            continue
        for i in range(span[0], span[1] + 1):
            bel_spans[i] = val[0]

    # print(''.join(bel_spans))

    # Add second layer for Nested Objects if available
    bel_spans = [" "] * (max_idx + 3)
    for val, span in spans:
        if val not in ["Nested"]:
            continue
        for i in range(span[0], span[1] + 1):
            bel_spans[i] = val[0]
932269
static String jsRegExpToJavaRegExp(String re) {
		re = re.replaceAll("\\[\\^\\\\\\d\\]", ".");
		re = re.replaceAll("\\[([^\\]]*)\\\\b([^\\]]*)\\]", "[$1\\\\cH$2]"); // [...\b...]
																				// ->
																				// [...\cH...]
		re = re.replaceAll("(?<!\\\\)\\[([^((?<!\\\\)\\[)\\]]*)\\[", "[$1\\\\["); // [...[...]
																					// ->
																					// [...\[...]

		// back reference in character classes are simply ignored by browsers
		re = re.replaceAll("(?<!\\\\)\\[([^\\]]*)(?<!\\\\)\\\\\\d", "[$1"); // [...ab\5cd...]
																			// ->
																			// [...abcd...]

		// characters escaped without need should be "un-escaped"
		re = re.replaceAll("(?<!\\\\)\\\\([ACE-RT-VX-Zaeg-mpqyz])", "$1");

		re = escapeJSCurly(re);
		return re;
	}
1361412
boolean checkPrefix(char[] chars, int[] cursor) {
    if (chars.length > cursor[0] && chars[cursor[0]] == MatchSpace.NONWILD_MARKER)
      return false;
    if (prefix == null)
      return true;
    if (cursor[1] - cursor[0] < prefix.minlen)
      // a conservative test, but if we can't pass it, we'll certainly fail later
      return false;
    for (int i = 0; i < prefix.items.length; i++) {
      Object item = prefix.items[i];
      if (item == Pattern.matchOne)
        if (!topicSkipForward(chars, cursor))
          return false;
        else
          ; // topic skip succeeded so continue
      else if (!matchForward(chars, (char[]) item, cursor))
        return false;
      // else this phase succeeded so continue
    }
    // The prefix matches exactly.  But, unless we are at the end of the string,
    // the next character MUST be a separator.
    return cursor[0] == cursor[1] || 
      chars[cursor[0]] == MatchSpace.SUBTOPIC_SEPARATOR_CHAR;
  }
134585
function base32DecodeLastCharacter(chunk, characterIndex, buffer, index) {
    const byteIndex = Math.floor(index + (characterIndex * 5) / 8);
    const offset = characterIndex % 8;
    switch (offset) {
        case 1:
            buffer[byteIndex] |= chunk >>> 2;
            break;
        case 3:
            buffer[byteIndex] |= chunk >>> 4;
            break;
        case 4:
            buffer[byteIndex] |= chunk >>> 1;
            break;
        case 6:
            buffer[byteIndex] |= chunk >>> 3;
            break;
        case 7:
            buffer[byteIndex] |= chunk;
            break;
    }
}
227646
def _matching_string(matched, string):
        
        if string is None:
            return string
        if IS_PY2:
            # pylint: disable=undefined-variable
            if isinstance(matched, text_type):
                return text_type(string)
        else:
            if isinstance(matched, bytes) and isinstance(string, str):
                return string.encode(locale.getpreferredencoding(False))
        return string
73072
function isEqualRegexp(a, b) {
  if (typeOf(a) !== 'regexp') return false;
  if (typeOf(b) !== 'regexp') return false;
  if (a.source !== b.source) return false;
  if (a.global !== b.global) return false;
  if (a.multiline !== b.multiline) return false;
  if (a.ignoreCase !== b.ignoreCase) return false;
  return true;
}
787422
def is_print(value, space = True, tab = False, crlf = False):
    
    if not isinstance(value, basestring):
        return False

    regex = r'\x00-\x08\x0B\x0C\x0E-\x1F\x7F'

    if not space:
        regex += r'\x20'

    if tab:
        regex += r'\x09'

    if crlf:
        regex += r'\x0A\x0D'

    return re.match(r'[' + regex + ']', value, re.U) is None
96498
def check_convert_string(obj, name=None,
                             no_leading_trailing_whitespace=True,
                             no_whitespace=False,
                             no_newline=True,
                             whole_word=False,
                             min_len=1,
                             max_len=0):
        """"""
        if not name:
            name = 'Argument'
        obj = ensure_unicode(obj, name=name)
        if no_whitespace:
            if _PATTERN_WHITESPACE.match(obj):
                raise ValueError('%s cannot contain whitespace' % name)
        elif no_leading_trailing_whitespace and _PATTERN_LEAD_TRAIL_WHITESPACE.match(obj):
            raise ValueError('%s contains leading/trailing whitespace' % name)
        if (min_len and len(obj) < min_len) or (max_len and len(obj) > max_len):
            raise ValueError('%s too short/long (%d/%d)' % (name, min_len, max_len))
        if whole_word:
            if not _PATTERN_WORD.match(obj):
                raise ValueError('%s can only contain alphanumeric (unicode) characters, numbers and the underscore'
                                 % name)
        # whole words cannot contain newline so additional check not required
        elif no_newline and '\n' in obj:
            raise ValueError('%s cannot contain line breaks' % name)
        return obj
81336
function rawIgnoreRegex(html, opts) {
    var ignore = opts['raw-ignore-regex'];
    if (!ignore) { return [html, function (issue) { return issue; }]; }

    var origLineCol = knife.getLineColFunc(html),
        l = 1, // Current line in the modified string
        d = 0; // Difference between original and modified line numbers
    var lines = [],
        cols = [];
    var total = html.length;
    html = html.replace(ignore, function (match) {
        var offset = arguments[arguments.length - 2],
            start = origLineCol(offset),
            end = origLineCol(offset + match.length),
            linediff = end[0] - start[0],
            newcol = start[0] - d;
        if (linediff) {
            for (; l < newcol; l++) { lines[l] = l + d; }
            d += linediff;
        }
        if (!cols[newcol]) { cols[newcol] = [[1,0,start[0]]]; }
        var col = cols[newcol],
            st = start[1] - col[col.length - 1][1];
        col.push([st, end[1] - st, end[0]]);
        return '';
    });

    var recoverLineCol;
    function findInCol(col, i) {
        var lo = 0, hi = col.length;
        while (lo < hi - 1) {
            var mid = Math.floor((lo + hi) / 2),
                v = col[mid][0];
            if (v === i) {
                return col[mid];
            } else if (v < i) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        return col[lo];
    }
    if (d === 0) { // No multi-line ignores
        recoverLineCol = function (issue) {
            var col = cols[issue.line];
            if (col) {
                issue.column += findInCol(col, issue.column)[1];
            }
            return issue;
        };
    } else {
        for (; l < total - d; l++) { lines[l] = l + d; }
        recoverLineCol = function (issue) {
            var col = cols[issue.line];
            if (col) {
                var c = findInCol(col, issue.column);
                issue.column += c[1];
                issue.line = c[2];
            } else {
                issue.line = lines[issue.line];
            }
            return issue;
        };
    }
    return [html, recoverLineCol];
}
89372
def parse_nested(
    bels: list, char_locs: CharLocs, parsed: Parsed, errors: Errors
) -> Tuple[Parsed, Errors]:
    

    for sp in char_locs[
        "nested_parens"
    ]:  # sp = start parenthesis, ep = end parenthesis
        ep, level = char_locs["nested_parens"][sp]
        if ep == -1:
            ep = len(bels) + 1
        parsed[(sp, ep)] = {"type": "Nested", "span": (sp, ep)}

    return parsed, errors
797334
def match(self, chars):
        """"""
        start_index = self.next_index
        for char in self:
            if char not in chars:
                self.next_index -= 1
                break
        return self[start_index:self.next_index]
707109
function checkUrange(i) {
  const start = i;
  let l;

  if (i >= tokensLength) return 0;

  // Check for unicode prefix (u+ or U+)
  if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;
  else return 0;

  if (i >= tokensLength) return 0;

  if (tokens[i].value === '+') i += 1;
  else return 0;

  while (i < tokensLength) {
    if (l = checkIdent(i)) i += l;
    else if (l = checkNumber(i)) i += l;
    else if (l = checkUnary(i)) i += l;
    else if (l = _checkUnicodeWildcard(i)) i += l;
    else break;
  }

  tokens[start].urangeEnd = i - 1;

  return i - start;
}
676747
function _buildRegexFromString(regex) {

        if (!regex || (typeof regex !== "string" && !(regex instanceof RegExp))) {
            _regexDebug();
            return false;
        }

        if (typeof regex !== 'string') {
            regex = regex.toString();
        }

        var separator = regex.charAt(0),
            index = regex.length - 1,
            pattern,
            modifier,
            rule;

        while (index > 0) {
            if (/[gimsxeU]/.test(regex.charAt(index))) {
                index--;
            } else {
                break;
            }
        }

        if (regex.charAt(index) !== separator) {
            separator = null;
        }

        if (separator && index !== regex.length - 1) {
            modifier = regex.substr(index + 1, regex.length - 1);
        }

        if (separator) {
            pattern = regex.substr(1, index - 1);
        } else {
            pattern = regex;
        }

        try {
            rule = new RegExp(pattern, modifier);
        } catch (error) {
            _regexDebug();
            return false;
        }

        return rule;

        function _regexDebug() {
            // {debug}
            window.Debug.log({
                'function': '_buildRegexFromString()',
                'arguments': '{pattern: {' + (pattern || '') + '}, modifier: {' + (modifier || '') + '}',
                'message': 'WARNING - Invalid regex given: ' + regex
            });
            window.Debug.print();
            // {/debug}
        }

    }
472438
function RegExpStringIterator(R, S, global, fullUnicode) {
	if (ES.Type(S) !== 'String') {
		throw new TypeError('S must be a string');
	}
	if (ES.Type(global) !== 'Boolean') {
		throw new TypeError('global must be a boolean');
	}
	if (ES.Type(fullUnicode) !== 'Boolean') {
		throw new TypeError('fullUnicode must be a boolean');
	}
	hidden.set(this, '[[IteratingRegExp]]', R);
	hidden.set(this, '[[IteratedString]]', S);
	hidden.set(this, '[[Global]]', global);
	hidden.set(this, '[[Unicode]]', fullUnicode);
	hidden.set(this, '[[Done]]', false);
}
1051227
private boolean checkStringToBeParsed(final String pStringToBeParsed) {

    // Check for nullness
    if (pStringToBeParsed == null) {
      if (mDebugging) {
        out.println(DebugUtil.getPrefixDebugMessage(this) + "string to be parsed is null - rejection!");
      }
      return false;
    }

    // Check if valid character (element in alphabet)
    for (int i = 0; i < pStringToBeParsed.length(); i++) {
      if (!isInAlphabet(pStringToBeParsed.charAt(i))) {
        if (mDebugging) {
          out.println(DebugUtil.getPrefixDebugMessage(this)
                      + "one or more characters in string to be parsed are not legal characters - rejection!");
        }
        return false;
      }
    }
    return true;
  }
985520
function matchTopic(ts,t) {
        if (ts == "#") {
            return true;
        }
        var re = new RegExp("^"+ts.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(\/.*)?")+"$");
        return re.test(t);
    }
1041991
function (chrs, buffer, pos, strict, opts) {
                        var isValid = opts.regex.val1.test(chrs);
                        if (!strict && !isValid) {
                            if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
                                isValid = opts.regex.val1.test("0" + chrs.charAt(0));
                                if (isValid) {
                                    buffer[pos - 1] = "0";
                                    return { "pos": pos, "c": chrs.charAt(0) };
                                }
                            }
                        }
                        return isValid;
                    }