[racket] matching eof in a parser-tools lex-abbrev

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Mar 5 16:57:49 EST 2012

In a "define-lex-abbrev", how do I match an EOF?

For example:

---- BEGIN ----
#lang racket/base

(require parser-tools/lex
          parser-tools/lex-sre)

(define-lex-abbrev my-newline-or-eof-abbrev
   (: (? #\return)
      (or #\newline #;eos)))
;; TODO: Need to match EOF where "#;eos" is above.

(define my-lexer
   (lexer (my-newline-or-eof-abbrev 'newline-or-eof)))

(require (planet neil/overeasy))
(test (my-lexer (open-input-string "\r\n")) 'newline-or-eof)
(test (my-lexer (open-input-string "\r"))   'newline-or-eof)
---- END ----

-- 
http://www.neilvandyke.org/


Posted on the users mailing list.