Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c7de1a1

Browse files
Improve documentation and add some explanations in the code
1 parent 4929733 commit c7de1a1

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/librustdoc/html/static/js/search.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,45 +309,57 @@ window.initSearch = function(rawSearchIndex) {
309309
}
310310

311311
/**
312+
* This function parses the next query element until it finds `endChar`, calling `getNextElem`
313+
* to collect each element.
314+
*
315+
* If there is no `endChar`, this function will implicitly stop at the end without raising an
316+
* error.
317+
*
312318
* @param {ParsedQuery} query
313319
* @param {ParserState} parserState
314320
* @param {Array<QueryElement>} elems - This is where the new {QueryElement} will be added.
315-
* @param {string} limit - This function will stop when it'll encounter this
321+
* @param {string} endChar - This function will stop when it'll encounter this
316322
* character.
317323
*/
318-
function getItemsBefore(query, parserState, elems, limit) {
324+
function getItemsBefore(query, parserState, elems, endChar) {
319325
var turns = 0;
320326
while (parserState.pos < parserState.length) {
321327
var c = parserState.userQuery[parserState.pos];
322-
if (c === limit) {
328+
if (c === endChar) {
323329
break;
324-
} else if (c === "," && limit !== "" && turns > 0) {
330+
} else if (c === "," && endChar !== "" && turns > 0) {
325331
parserState.pos += 1;
326332
continue;
327333
} else if (c === ":" && isPathStart(parserState)) {
328334
throw new Error("Unexpected `::`: paths cannot start with `::`");
329335
} else if (c === ":" || isEndCharacter(c)) {
330336
var extra = "";
331-
if (limit === ">") {
337+
if (endChar === ">") {
332338
extra = "`<`";
333-
} else if (limit === "") {
339+
} else if (endChar === "") {
334340
extra = "`->`";
335341
}
336342
throw new Error("Unexpected `" + c + "` after " + extra);
337343
}
338344
var posBefore = parserState.pos;
339-
getNextElem(query, parserState, elems, limit === ">");
345+
getNextElem(query, parserState, elems, endChar === ">");
340346
turns += 1;
347+
// This case can be encountered if `getNextElem` encounted a "stop character" right from
348+
// the start. For example if you have `,,`. In this case, we simply move up the current
349+
// position to continue the parsing.
341350
if (posBefore === parserState.pos) {
342351
parserState.pos += 1;
343352
}
344353
}
345-
// We are either at the end of the string or on the "limit" character, let's move forward
354+
// We are either at the end of the string or on the `endChar`` character, let's move forward
346355
// in any case.
347356
parserState.pos += 1;
348357
}
349358

350359
/**
360+
* Parses the provided `query` input to fill `parserState`. If it encounters an error while
361+
* parsing `query`, it'll throw an error.
362+
*
351363
* @param {ParsedQuery} query
352364
* @param {ParserState} parserState
353365
*/
@@ -1194,7 +1206,9 @@ window.initSearch = function(rawSearchIndex) {
11941206
}
11951207

11961208
/**
1197-
* This function is called in case the query has more than one element.
1209+
* This function is called in case the query has more than one element. In this case, it'll
1210+
* try to match the items which validates all the elements. For `aa -> bb` will look for
1211+
* functions which have a parameter `aa` and has `bb` in its returned values.
11981212
*
11991213
* @param {Row} row
12001214
* @param {integer} pos - Position in the `searchIndex`.

src/test/rustdoc-js-std/parser-errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const QUERY = [
44
'P "P"',
55
'"p" p',
66
'"const": p',
7-
"<:a>", "<::a>",
7+
"<:a>",
8+
"<::a>",
89
"((a))",
910
"->,a",
1011
"(p -> p",

src/test/rustdoc-js/generics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const QUERY = [
1212

1313
const EXPECTED = [
1414
{
15-
// "R"<P>
15+
// R<P>
1616
'returned': [
1717
{ 'path': 'generics', 'name': 'alef' },
1818
],

0 commit comments

Comments
 (0)