diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-02-11 15:48:57 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2022-04-18 20:59:09 +0200 |
| commit | c7de1a16f89b9aa3205f50c9cf2b9f6792ac6e4b (patch) | |
| tree | ff2eec2b1abd1ecff49db3484260e9367d915845 /src/librustdoc/html/static | |
| parent | 49297337b46eabef906a41f2c438bdd569b9227d (diff) | |
| download | rust-c7de1a16f89b9aa3205f50c9cf2b9f6792ac6e4b.tar.gz rust-c7de1a16f89b9aa3205f50c9cf2b9f6792ac6e4b.zip | |
Improve documentation and add some explanations in the code
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 65a1dfe269e..43a59ed85e0 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -309,45 +309,57 @@ window.initSearch = function(rawSearchIndex) { } /** + * This function parses the next query element until it finds `endChar`, calling `getNextElem` + * to collect each element. + * + * If there is no `endChar`, this function will implicitly stop at the end without raising an + * error. + * * @param {ParsedQuery} query * @param {ParserState} parserState * @param {Array<QueryElement>} elems - This is where the new {QueryElement} will be added. - * @param {string} limit - This function will stop when it'll encounter this + * @param {string} endChar - This function will stop when it'll encounter this * character. */ - function getItemsBefore(query, parserState, elems, limit) { + function getItemsBefore(query, parserState, elems, endChar) { var turns = 0; while (parserState.pos < parserState.length) { var c = parserState.userQuery[parserState.pos]; - if (c === limit) { + if (c === endChar) { break; - } else if (c === "," && limit !== "" && turns > 0) { + } else if (c === "," && endChar !== "" && turns > 0) { parserState.pos += 1; continue; } else if (c === ":" && isPathStart(parserState)) { throw new Error("Unexpected `::`: paths cannot start with `::`"); } else if (c === ":" || isEndCharacter(c)) { var extra = ""; - if (limit === ">") { + if (endChar === ">") { extra = "`<`"; - } else if (limit === "") { + } else if (endChar === "") { extra = "`->`"; } throw new Error("Unexpected `" + c + "` after " + extra); } var posBefore = parserState.pos; - getNextElem(query, parserState, elems, limit === ">"); + getNextElem(query, parserState, elems, endChar === ">"); turns += 1; + // This case can be encountered if `getNextElem` encounted a "stop character" right from + // the start. For example if you have `,,`. In this case, we simply move up the current + // position to continue the parsing. if (posBefore === parserState.pos) { parserState.pos += 1; } } - // We are either at the end of the string or on the "limit" character, let's move forward + // We are either at the end of the string or on the `endChar`` character, let's move forward // in any case. parserState.pos += 1; } /** + * Parses the provided `query` input to fill `parserState`. If it encounters an error while + * parsing `query`, it'll throw an error. + * * @param {ParsedQuery} query * @param {ParserState} parserState */ @@ -1194,7 +1206,9 @@ window.initSearch = function(rawSearchIndex) { } /** - * This function is called in case the query has more than one element. + * This function is called in case the query has more than one element. In this case, it'll + * try to match the items which validates all the elements. For `aa -> bb` will look for + * functions which have a parameter `aa` and has `bb` in its returned values. * * @param {Row} row * @param {integer} pos - Position in the `searchIndex`. |
