ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.22k stars 141 forks source link

`(chibi parse)`: Inaccurate line number information in parse-failure #876

Open nmeum opened 1 year ago

nmeum commented 1 year ago

Consider the following chibi program:

(import (scheme base)
        (scheme write)
        (srfi 14)
        (chibi parse))

(define parse-line
  (parse-seq
    (parse-repeat+ (parse-char char-set:digit))
    (parse-char char-set:blank)
    (parse-repeat+ (parse-char char-set:letter))
    parse-end-of-line))

(let ((s (string->parse-stream "42foobar")))
  (call-with-parse
    parse-line
    s
    0
    (lambda (r s i fk)
      (display "success: ")
      (display r)
      (newline))
    parse-failure))

This outputs the following error:

ERROR: incomplete parse at: (0 2 "42f" "failed char pred")
  called from <anonymous> on line 1292 of file /usr/share/chibi/init-7.scm
  called from <anonymous> on line 821 of file /usr/share/chibi/init-7.scm

Since the car of the list in the error message is the line number, I would have expected the output to be:

ERROR: incomplete parse at: (1 2 "42f" "failed char pred")

Since the error occurs on the first line of input. However, it seems that chibi-scheme starts counting line numbers at zero (which I would argue is at the very least unconventional). Is it intentional that line numbers start at zero?