Based on my experiments, it appears that parser-tools/lex picks the rule with 
the longest match, breaking ties in favor of the rule appearing first. As far 
as I can tell, this fact is not documented in the lexer manual. It says:

"Produces a function that takes an input-port, matches the re’s against the 
buffer, and returns the result of executing the corresponding action-expr."

Here's the text of my proposed commit. Unless I see a comment to the contrary, 
I'll commit this later today or tomorrow.

Thanks!

John


>From eefa87cd51cc579ef4762e6986671797e0473718 Mon Sep 17 00:00:00 2001
From: John Clements <[email protected]>
Date: Wed, 1 May 2013 07:51:40 -0700
Subject: [PATCH] specified match precedence in lexer... hope I'm right

---
collects/parser-tools/parser-tools.scrbl |    6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/collects/parser-tools/parser-tools.scrbl 
b/collects/parser-tools/parser-tools.scrbl
index cb3a84f..9bc5ef5 100644
--- a/collects/parser-tools/parser-tools.scrbl
+++ b/collects/parser-tools/parser-tools.scrbl
@@ -51,8 +51,10 @@ style lexer and parser generators.
                   (id datum ...)])]{

     Produces a function that takes an input-port, matches the
-     @racket[re]'s against the buffer, and returns the result of
-     executing the corresponding @racket[action-expr].
+     @racket[re] patterns against the buffer, and returns the result of
+     executing the corresponding @racket[action-expr]. When multiple
+     patterns match, a lexer will choose the longest match, breaking
+     ties in favor of the rule appearing first.

     @margin-note{The implementation of 
@racketmodname[syntax-color/racket-lexer]
                 contains a lexer for the @racketmodname[racket] language.
-- 
1.7.7.5 (Apple Git-26)



____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to