From 4ec7d8096853b1b478da3588206eb2a29559efa9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 29 Jul 2020 10:04:05 -0700 Subject: [PATCH] Mention rule order as the fallback criteria in docs Fixes #702 --- docs/section-3-creating-parsers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/section-3-creating-parsers.md b/docs/section-3-creating-parsers.md index b075e488..694f8dae 100644 --- a/docs/section-3-creating-parsers.md +++ b/docs/section-3-creating-parsers.md @@ -505,6 +505,8 @@ Grammars often contain multiple tokens that can match the same characters. For e 4. **Match Specificity** - If there are two valid tokens with the same precedence and which both match the same number of characters, Tree-sitter will prefer a token that is specified in the grammar as a `String` over a token specified as a `RegExp`. +5. **Rule Order** - If none of the above criteria can be used to select one token over another, Tree-sitter will prefer the token that appears earlier in the grammar. + ### Keywords Many languages have a set of *keyword* tokens (e.g. `if`, `for`, `return`), as well as a more general token (e.g. `identifier`) that matches any word, including many of the keyword strings. For example, JavaScript has a keyword `instanceof`, which is used as a binary operator, like this: