From 20f57b9e40d6e982e39ff475aaa43221955a59df Mon Sep 17 00:00:00 2001 From: Erez Sh Date: Mon, 30 Aug 2021 09:25:49 +0100 Subject: [PATCH] Updated docs, to accord with PR #980 --- docs/grammar.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/grammar.md b/docs/grammar.md index 0d77420..4ac5c77 100644 --- a/docs/grammar.md +++ b/docs/grammar.md @@ -159,14 +159,15 @@ start : (A | B)+ A : "a" | "ab" B : "b" ``` -We get this behavior: +We get only one possible derivation, instead of two: ```bash +>>> p = Lark(g, ambiguity="explicit") >>> p.parse("ab") -Tree(start, [Token(A, 'a'), Token(B, 'b')]) +Tree('start', [Token('A', 'ab')]) ``` -This is happening because Python's regex engine always returns the first matching option. +This is happening because Python's regex engine always returns the best matching option. There is no way to access the alternatives. If you find yourself in this situation, the recommended solution is to use rules instead.