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

Commit 99c5394

Browse files
Add query syntax for the parser
1 parent 51de26c commit 99c5394

File tree

1 file changed

+71
-12
lines changed

1 file changed

+71
-12
lines changed

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

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,65 @@ window.initSearch = function(rawSearchIndex) {
158158
}
159159

160160
/**
161-
* Executes the query and returns a list of results for each results tab.
161+
* Executes the query and builds an index of results
162+
*
163+
* The supported syntax by this parser is as follow:
164+
*
165+
* ident = *1(ALPHA / DIGIT)
166+
* path = ident *WS *(DOUBLE-COLON *WS ident)
167+
* arg = path *WS [generics]
168+
* nonempty-arg-list = arg *WS *(COMMA *WS arg)
169+
* generics = OPEN-ANGLE-BRACKET *WS nonempty-arg-list *WS CLOSE-ANGLE-BRACKET
170+
* function-args = OPEN-PAREN *WS [nonempty-arg-list] *WS END-PAREN
171+
* return-args = RETURN-ARROW *WS function-args
172+
*
173+
* exact-search = [type-filter *WS COLON] *WS QUOTE ident QUOTE *WS [generics]
174+
* type-search = [type-filter *WS COLON] *WS path *WS generics
175+
* function-search = path *WS function-args *WS [return-args]
176+
*
177+
* query = *WS (exact-search / type-search / function-search / return-args) *WS
178+
*
179+
* type-filter = (
180+
* "mod" /
181+
* "externcrate" /
182+
* "import" /
183+
* "struct" /
184+
* "enum" /
185+
* "fn" /
186+
* "type" /
187+
* "static" /
188+
* "trait" /
189+
* "impl" /
190+
* "tymethod" /
191+
* "method" /
192+
* "structfield" /
193+
* "variant" /
194+
* "macro" /
195+
* "primitive" /
196+
* "associatedtype" /
197+
* "constant" /
198+
* "associatedconstant" /
199+
* "union" /
200+
* "foreigntype" /
201+
* "keyword" /
202+
* "existential" /
203+
* "attr" /
204+
* "derive" /
205+
* "traitalias")
206+
*
207+
* OPEN-ANGLE-BRACKET = "<"
208+
* CLOSE-ANGLE-BRACKET = ">"
209+
* OPEN-PAREN = "("
210+
* END-PAREN = ")"
211+
* COLON = ":"
212+
* DOUBLE-COLON = "::"
213+
* QUOTE = %x22
214+
* COMMA = ","
215+
* RETURN-ARROW = "->"
216+
*
217+
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
218+
* DIGIT = %x30-39
219+
* WS = %x09 / " "
162220
*
163221
* @param {string} val - The user query
164222
* @return {ParsedQuery} - The parsed query
@@ -606,7 +664,8 @@ window.initSearch = function(rawSearchIndex) {
606664
* This function checks if the object (`obj`) generics match the given type (`val`)
607665
* generics. If there are no generics on `obj`, `defaultLev` is returned.
608666
*
609-
* @param {Object} obj - The object to check.
667+
* @param {Row} obj - The object to check.
668+
* @param {QueryElement} val - The element from the parsed query.
610669
* @param {integer} defaultLev - This is the value to return in case there are no generics.
611670
*
612671
* @return {integer} - Returns the best match (if any) or `MAX_LEV_DISTANCE + 1`.
@@ -662,8 +721,8 @@ window.initSearch = function(rawSearchIndex) {
662721
* This function checks if the object (`obj`) matches the given type (`val`) and its
663722
* generics (if any).
664723
*
665-
* @param {Object} obj
666-
* @param {Object} val
724+
* @param {Row} obj
725+
* @param {QueryElement} val - The element from the parsed query.
667726
*
668727
* @return {integer} - Returns a Levenshtein distance to the best match.
669728
*/
@@ -756,8 +815,8 @@ window.initSearch = function(rawSearchIndex) {
756815
/**
757816
* This function checks if the object (`obj`) has an argument with the given type (`val`).
758817
*
759-
* @param {Object} obj
760-
* @param {Object} val
818+
* @param {Row} obj
819+
* @param {QueryElement} val - The element from the parsed query.
761820
* @param {integer} typeFilter
762821
*
763822
* @return {integer} - Returns a Levenshtein distance to the best match. If there is no
@@ -784,8 +843,8 @@ window.initSearch = function(rawSearchIndex) {
784843
}
785844

786845
/**
787-
* @param {Object} obj
788-
* @param {Object} val
846+
* @param {Row} obj
847+
* @param {QueryElement} val - The element from the parsed query.
789848
* @param {integer} typeFilter
790849
*
791850
* @return {integer} - Returns a Levenshtein distance to the best match. If there is no
@@ -978,9 +1037,9 @@ window.initSearch = function(rawSearchIndex) {
9781037
/**
9791038
* This function is called in case the query is only one element (with or without generics).
9801039
*
981-
* @param {Object} ty
982-
* @param {integer} pos - Position in the `searchIndex`.
983-
* @param {Object} elem - The element from the parsed query.
1040+
* @param {Row} ty
1041+
* @param {integer} pos - Position in the `searchIndex`.
1042+
* @param {QueryElement} elem - The element from the parsed query.
9841043
*/
9851044
function handleSingleArg(ty, pos, elem) {
9861045
if (!ty || (filterCrates !== null && ty.crate !== filterCrates)) {
@@ -1477,7 +1536,7 @@ window.initSearch = function(rawSearchIndex) {
14771536
}
14781537

14791538
if (!forced && query.id === currentResults) {
1480-
if (query.val.length > 0) {
1539+
if (query.userQuery.length > 0) {
14811540
putBackSearch();
14821541
}
14831542
return;

0 commit comments

Comments
 (0)