Skip to content

Commit e4ee329

Browse files
Fix eBNF and handling of whitespace characters when not in a path
1 parent 4f0a912 commit e4ee329

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,13 @@ function initSearch(rawSearchIndex) {
838838
throw ["Unexpected ", c];
839839
} else if (c === ":" && !isPathStart(parserState)) {
840840
if (parserState.typeFilter !== null) {
841-
throw ["Unexpected ", ":"];
841+
throw [
842+
"Unexpected ",
843+
":",
844+
" (expected path after type filter ",
845+
parserState.typeFilter + ":",
846+
")",
847+
];
842848
} else if (query.elems.length === 0) {
843849
throw ["Expected type filter before ", ":"];
844850
} else if (query.literalSearch) {
@@ -853,6 +859,9 @@ function initSearch(rawSearchIndex) {
853859
query.literalSearch = false;
854860
foundStopChar = true;
855861
continue;
862+
} else if (isWhitespace(c)) {
863+
skipWhitespace(parserState);
864+
continue;
856865
}
857866
if (!foundStopChar) {
858867
let extra = "";
@@ -983,7 +992,7 @@ function initSearch(rawSearchIndex) {
983992
* path = ident *(DOUBLE-COLON/{WS} ident) [!]
984993
* slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
985994
* arg = [type-filter *WS COLON *WS] (path [generics] / slice)
986-
* type-sep = COMMA *(COMMA)
995+
* type-sep = *WS COMMA *(COMMA)
987996
* nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
988997
* generics = OPEN-ANGLE-BRACKET [ nonempty-arg-list ] *(type-sep)
989998
* CLOSE-ANGLE-BRACKET

tests/rustdoc-js-std/parser-errors.js

+105-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ const PARSED = [
366366
original: "a<> :",
367367
returned: [],
368368
userQuery: "a<> :",
369-
error: 'Expected `,`, `:` or `->` after `>`, found ` `',
369+
error: 'Unexpected `<` in type filter (before `:`)',
370370
},
371371
{
372372
query: "mod : :",
@@ -440,4 +440,108 @@ const PARSED = [
440440
userQuery: "a<",
441441
error: "Unclosed `<`",
442442
},
443+
{
444+
query: "p<x> , y",
445+
elems: [
446+
{
447+
name: "p",
448+
fullPath: ["p"],
449+
pathWithoutLast: [],
450+
pathLast: "p",
451+
generics: [
452+
{
453+
name: "x",
454+
fullPath: ["x"],
455+
pathWithoutLast: [],
456+
pathLast: "x",
457+
generics: [],
458+
typeFilter: -1,
459+
},
460+
],
461+
typeFilter: -1,
462+
},
463+
{
464+
name: "y",
465+
fullPath: ["y"],
466+
pathWithoutLast: [],
467+
pathLast: "y",
468+
generics: [],
469+
typeFilter: -1,
470+
},
471+
],
472+
foundElems: 2,
473+
original: "p<x> , y",
474+
returned: [],
475+
userQuery: "p<x> , y",
476+
error: null,
477+
},
478+
{
479+
query: "p<x , y>",
480+
elems: [
481+
{
482+
name: "p",
483+
fullPath: ["p"],
484+
pathWithoutLast: [],
485+
pathLast: "p",
486+
generics: [
487+
{
488+
name: "x",
489+
fullPath: ["x"],
490+
pathWithoutLast: [],
491+
pathLast: "x",
492+
generics: [],
493+
typeFilter: -1,
494+
},
495+
{
496+
name: "y",
497+
fullPath: ["y"],
498+
pathWithoutLast: [],
499+
pathLast: "y",
500+
generics: [],
501+
typeFilter: -1,
502+
},
503+
],
504+
typeFilter: -1,
505+
},
506+
],
507+
foundElems: 1,
508+
original: "p<x , y>",
509+
returned: [],
510+
userQuery: "p<x , y>",
511+
error: null,
512+
},
513+
{
514+
query: "p ,x , y",
515+
elems: [
516+
{
517+
name: "p",
518+
fullPath: ["p"],
519+
pathWithoutLast: [],
520+
pathLast: "p",
521+
generics: [],
522+
typeFilter: -1,
523+
},
524+
{
525+
name: "x",
526+
fullPath: ["x"],
527+
pathWithoutLast: [],
528+
pathLast: "x",
529+
generics: [],
530+
typeFilter: -1,
531+
},
532+
{
533+
name: "y",
534+
fullPath: ["y"],
535+
pathWithoutLast: [],
536+
pathLast: "y",
537+
generics: [],
538+
typeFilter: -1,
539+
},
540+
],
541+
foundElems: 3,
542+
original: "p ,x , y",
543+
returned: [],
544+
userQuery: "p ,x , y",
545+
error: null,
546+
},
443547
];

0 commit comments

Comments
 (0)