[racket] lexer-src-pos reports position as #f #f

From: Johnny Morrice (spoon at killersmurf.com)
Date: Tue May 24 18:50:02 EDT 2011

Hi list,

I'm trying to build a lexer with lexer-src-pos from parser-tools/lex.

I've written some unit tests which use pipes to provide an input port
to the lexer.

My problem is that the lexer does not seem to report the correct
line numbers.  Apparently, the line number is #f.

I don't understand what I'm doing wrong.

If I run this through racket v5.1.1:

#lang racket

(require parser-tools/lex)

(define no-pos-lexer
  (lexer-src-pos
    [any-char lexeme]))

(let-values ([(i o) (make-pipe)])
            (display "$" o)
            (let* ([no-pos-token (no-pos-lexer i)]
                   [no-pos (position-token-start-pos no-pos-token)])
              (printf "Token ~a at line ~a, column ~a\n"
                      (position-token-token no-pos-token)
                      (position-line no-pos)
                      (position-col no-pos))))

It outputs:
Token $ at line #f, column #f

But I would like it to output:
Token $ at line 1, column 1

Where am I going wrong?

Thanks
Johnny


Posted on the users mailing list.