mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Handle separators in their own functions and fix missing handling of tabs
This commit is contained in:
parent
da829d8d9d
commit
e03a950747
@ -226,6 +226,17 @@ window.initSearch = function(rawSearchIndex) {
|
||||
(c >= 'A' && c <= 'Z'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the given `c` character is a separator.
|
||||
*
|
||||
* @param {string} c
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isSeparatorCharacter(c) {
|
||||
return ", \t".indexOf(c) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ParsedQuery} query
|
||||
* @param {ParserState} parserState
|
||||
@ -295,7 +306,11 @@ window.initSearch = function(rawSearchIndex) {
|
||||
if (!isIdentCharacter(c)) {
|
||||
if (isErrorCharacter(c)) {
|
||||
throw new Error(`Unexpected \`${c}\``);
|
||||
} else if (isStopCharacter(c) || isSpecialStartCharacter(c)) {
|
||||
} else if (
|
||||
isStopCharacter(c) ||
|
||||
isSpecialStartCharacter(c) ||
|
||||
isSeparatorCharacter(c))
|
||||
{
|
||||
break;
|
||||
}
|
||||
// If we allow paths ("str::string" for example).
|
||||
@ -358,7 +373,7 @@ window.initSearch = function(rawSearchIndex) {
|
||||
var c = parserState.userQuery[parserState.pos];
|
||||
if (c === endChar) {
|
||||
break;
|
||||
} else if (c === "," || c === " ") {
|
||||
} else if (isSeparatorCharacter(c)) {
|
||||
parserState.pos += 1;
|
||||
foundStopChar = true;
|
||||
continue;
|
||||
@ -409,7 +424,7 @@ window.initSearch = function(rawSearchIndex) {
|
||||
c = parserState.userQuery[parserState.pos];
|
||||
if (isStopCharacter(c)) {
|
||||
foundStopChar = true;
|
||||
if (c === "," || c === " ") {
|
||||
if (isSeparatorCharacter(c)) {
|
||||
parserState.pos += 1;
|
||||
continue;
|
||||
} else if (c === "-" || c === ">") {
|
||||
|
@ -27,6 +27,7 @@ const QUERY = [
|
||||
"aaaaa<>b",
|
||||
"fn:aaaaa<>b",
|
||||
"->a<>b",
|
||||
"a<->",
|
||||
];
|
||||
|
||||
const PARSED = [
|
||||
@ -282,4 +283,13 @@ const PARSED = [
|
||||
userQuery: '->a<>b',
|
||||
error: 'Expected `,` or ` `, found `b`',
|
||||
},
|
||||
{
|
||||
elems: [],
|
||||
foundElems: 0,
|
||||
original: 'a<->',
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: 'a<->',
|
||||
error: 'Unexpected `-` after `<`',
|
||||
},
|
||||
];
|
||||
|
206
src/test/rustdoc-js-std/parser-separators.js
Normal file
206
src/test/rustdoc-js-std/parser-separators.js
Normal file
@ -0,0 +1,206 @@
|
||||
// ignore-tidy-tab
|
||||
|
||||
const QUERY = [
|
||||
'aaaaaa b',
|
||||
'a b',
|
||||
'a,b',
|
||||
'a\tb',
|
||||
'a<b c>',
|
||||
'a<b,c>',
|
||||
'a<b\tc>',
|
||||
];
|
||||
|
||||
const PARSED = [
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'aaaaaa',
|
||||
fullPath: ['aaaaaa'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'aaaaaa',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
foundElems: 2,
|
||||
original: "aaaaaa b",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "aaaaaa b",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
foundElems: 2,
|
||||
original: "a b",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a b",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
foundElems: 2,
|
||||
original: "a,b",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a,b",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
foundElems: 2,
|
||||
original: "a\tb",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a\tb",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'c',
|
||||
fullPath: ['c'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'c',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
foundElems: 1,
|
||||
original: "a<b c>",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a<b c>",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'c',
|
||||
fullPath: ['c'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'c',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
foundElems: 1,
|
||||
original: "a<b,c>",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a<b,c>",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
elems: [
|
||||
{
|
||||
name: 'a',
|
||||
fullPath: ['a'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'a',
|
||||
generics: [
|
||||
{
|
||||
name: 'b',
|
||||
fullPath: ['b'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'b',
|
||||
generics: [],
|
||||
},
|
||||
{
|
||||
name: 'c',
|
||||
fullPath: ['c'],
|
||||
pathWithoutLast: [],
|
||||
pathLast: 'c',
|
||||
generics: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
foundElems: 1,
|
||||
original: "a<b\tc>",
|
||||
returned: [],
|
||||
typeFilter: -1,
|
||||
userQuery: "a<b\tc>",
|
||||
error: null,
|
||||
},
|
||||
];
|
@ -275,7 +275,7 @@ function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) {
|
||||
"parseInput", "getItemsBefore", "getNextElem", "createQueryElement",
|
||||
"isReturnArrow", "isPathStart", "getStringElem", "newParsedQuery",
|
||||
"itemTypeFromName", "isEndCharacter", "isErrorCharacter",
|
||||
"isIdentCharacter"];
|
||||
"isIdentCharacter", "isSeparatorCharacter"];
|
||||
|
||||
const functions = ["hasOwnPropertyRustdoc", "onEach"];
|
||||
ALIASES = {};
|
||||
|
Loading…
Reference in New Issue
Block a user