function parseSyntax()

in tools/api-builder/cheatsheet-package/services/cheatsheetItemParser.js [57:93]


    function parseSyntax(text) {
      var index = 0;

      if (text.charAt(index) !== '`') throw new Error('item syntax must start with a backtick');

      var start = index + 1;
      index = text.indexOf('`', start);
      if (index === -1) throw new Error('item syntax must end with a backtick');
      item.syntax = text.substring(start, index);
      start = index + 1;

      // skip to next pipe
      while(index < text.length && text.charAt(index) !== '|') index += 1;

      while(text.charAt(start) === '|') {

        start += 1;

        // skip whitespace
        while(start < text.length && /\s/.test(text.charAt(start))) start++;

        if (text.charAt(start) !== '`') throw new Error('bold matcher must start with a backtick');

        start += 1;
        index = text.indexOf('`', start);
        if (index === -1) throw new Error('bold matcher must end with a backtick');
        item.bold.push(text.substring(start, index));
        start = index + 1;

      }

      if (start !== text.length) {
        throw new Error('syntax field must only contain a syntax code block and zero or more bold ' +
                        'matcher code blocks, delimited by pipes.\n' +
                        'Instead it was "' + text + '"');
      }
    }