Skip to content

Commit

Permalink
Fix eBNF and handling of whitespace characters when not in a path
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 14, 2023
1 parent 4f0a912 commit e4ee329
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,13 @@ function initSearch(rawSearchIndex) {
throw ["Unexpected ", c];
} else if (c === ":" && !isPathStart(parserState)) {
if (parserState.typeFilter !== null) {
throw ["Unexpected ", ":"];
throw [
"Unexpected ",
":",
" (expected path after type filter ",
parserState.typeFilter + ":",
")",
];
} else if (query.elems.length === 0) {
throw ["Expected type filter before ", ":"];
} else if (query.literalSearch) {
Expand All @@ -853,6 +859,9 @@ function initSearch(rawSearchIndex) {
query.literalSearch = false;
foundStopChar = true;
continue;
} else if (isWhitespace(c)) {
skipWhitespace(parserState);
continue;
}
if (!foundStopChar) {
let extra = "";
Expand Down Expand Up @@ -983,7 +992,7 @@ function initSearch(rawSearchIndex) {
* path = ident *(DOUBLE-COLON/{WS} ident) [!]
* slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
* arg = [type-filter *WS COLON *WS] (path [generics] / slice)
* type-sep = COMMA *(COMMA)
* type-sep = *WS COMMA *(COMMA)
* nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
* generics = OPEN-ANGLE-BRACKET [ nonempty-arg-list ] *(type-sep)
* CLOSE-ANGLE-BRACKET
Expand Down
106 changes: 105 additions & 1 deletion tests/rustdoc-js-std/parser-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const PARSED = [
original: "a<> :",
returned: [],
userQuery: "a<> :",
error: 'Expected `,`, `:` or `->` after `>`, found ` `',
error: 'Unexpected `<` in type filter (before `:`)',
},
{
query: "mod : :",
Expand Down Expand Up @@ -440,4 +440,108 @@ const PARSED = [
userQuery: "a<",
error: "Unclosed `<`",
},
{
query: "p<x> , y",
elems: [
{
name: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
generics: [
{
name: "x",
fullPath: ["x"],
pathWithoutLast: [],
pathLast: "x",
generics: [],
typeFilter: -1,
},
],
typeFilter: -1,
},
{
name: "y",
fullPath: ["y"],
pathWithoutLast: [],
pathLast: "y",
generics: [],
typeFilter: -1,
},
],
foundElems: 2,
original: "p<x> , y",
returned: [],
userQuery: "p<x> , y",
error: null,
},
{
query: "p<x , y>",
elems: [
{
name: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
generics: [
{
name: "x",
fullPath: ["x"],
pathWithoutLast: [],
pathLast: "x",
generics: [],
typeFilter: -1,
},
{
name: "y",
fullPath: ["y"],
pathWithoutLast: [],
pathLast: "y",
generics: [],
typeFilter: -1,
},
],
typeFilter: -1,
},
],
foundElems: 1,
original: "p<x , y>",
returned: [],
userQuery: "p<x , y>",
error: null,
},
{
query: "p ,x , y",
elems: [
{
name: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
generics: [],
typeFilter: -1,
},
{
name: "x",
fullPath: ["x"],
pathWithoutLast: [],
pathLast: "x",
generics: [],
typeFilter: -1,
},
{
name: "y",
fullPath: ["y"],
pathWithoutLast: [],
pathLast: "y",
generics: [],
typeFilter: -1,
},
],
foundElems: 3,
original: "p ,x , y",
returned: [],
userQuery: "p ,x , y",
error: null,
},
];

0 comments on commit e4ee329

Please sign in to comment.