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 | |
| parent | 49297337b46eabef906a41f2c438bdd569b9227d (diff) | |
| download | rust-c7de1a16f89b9aa3205f50c9cf2b9f6792ac6e4b.tar.gz rust-c7de1a16f89b9aa3205f50c9cf2b9f6792ac6e4b.zip | |
Improve documentation and add some explanations in the code
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 32 | ||||
| -rw-r--r-- | src/test/rustdoc-js-std/parser-errors.js | 3 | ||||
| -rw-r--r-- | src/test/rustdoc-js/generics.js | 2 |
3 files changed, 26 insertions, 11 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`. diff --git a/src/test/rustdoc-js-std/parser-errors.js b/src/test/rustdoc-js-std/parser-errors.js index 7d00b7fed59..d4cd9facf17 100644 --- a/src/test/rustdoc-js-std/parser-errors.js +++ b/src/test/rustdoc-js-std/parser-errors.js @@ -4,7 +4,8 @@ const QUERY = [ 'P "P"', '"p" p', '"const": p', - "<:a>", "<::a>", + "<:a>", + "<::a>", "((a))", "->,a", "(p -> p", diff --git a/src/test/rustdoc-js/generics.js b/src/test/rustdoc-js/generics.js index 4aa6b355b6d..5e5ba7cd9ac 100644 --- a/src/test/rustdoc-js/generics.js +++ b/src/test/rustdoc-js/generics.js @@ -12,7 +12,7 @@ const QUERY = [ const EXPECTED = [ { - // "R"<P> + // R<P> 'returned': [ { 'path': 'generics', 'name': 'alef' }, ], |
