Hi,<div><br></div><div>I am trying to use the lexer from the parser-tools collection.</div><div>I have written a minimal example that exhibits a behavior that seems odd to me (code is at the end of the email).</div><div><br>
</div><div>The first two tests behave as expected but I would have expected the third to fail. I understand that it does not, given the way the lexer is implemented, but I cannot figure out how to change this behavior.</div>
<div><br></div><div>Could someone please give me directions to fix this ?</div><div><br></div><div>Thanks in advance.</div><div><br></div><div>Regards,</div><div>Philippe Mechaï</div><div><br></div><div><br></div><div>Sample code:</div>
<div>--------------------</div><div><div><font face="courier new, monospace">#lang racket/base</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(require racket/port</font></div>
<div><font face="courier new, monospace"> parser-tools/lex</font></div><div><font face="courier new, monospace"> (prefix-in : parser-tools/lex-sre))</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">(define-tokens data (ID NUM))</font></div><div><font face="courier new, monospace">(define-empty-tokens delim (EOF))</font></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="courier new, monospace">(define sample-lexer</font></div><div><font face="courier new, monospace"> (lexer</font></div><div><font face="courier new, monospace"> [(eof) 'EOF]</font></div>
<div><font face="courier new, monospace"> [whitespace (sample-lexer input-port)]</font></div><div><font face="courier new, monospace"> [(:+ alphabetic) (token-ID (string->symbol lexeme))]</font></div><div><font face="courier new, monospace"> [(:+ numeric) (token-NUM (string->number lexeme))]))</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">(define (test-lexer instr)</font></div><div><font face="courier new, monospace"> (printf "~%Test [~a]:~%" instr)</font></div>
<div><font face="courier new, monospace"> (with-handlers ([exn:fail? (λ (e) </font></div><div><font face="courier new, monospace"> (eprintf "ERROR: ~a~%" (exn-message e)))])</font></div>
<div><font face="courier new, monospace"> (with-input-from-string instr</font></div><div><font face="courier new, monospace"> (λ ()</font></div><div><font face="courier new, monospace"> (printf "token: ~a~%" (sample-lexer (current-input-port)))))))</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">;; TEST 1</font></div><div><font face="courier new, monospace">(test-lexer "*")</font></div><div><font face="courier new, monospace">;; TEST 2</font></div>
<div><font face="courier new, monospace">(test-lexer "4 a")</font></div><div><font face="courier new, monospace">;; TEST 3</font></div><div><font face="courier new, monospace">(test-lexer "4a")</font></div>
</div><div><br></div><div><br></div>