PR 10344
svn: r15545
This commit is contained in:
parent
afe7e75f1e
commit
0c73b84692
|
@ -216,8 +216,10 @@ are a few examples, using @scheme[:] prefixed SRE syntax:
|
||||||
no @scheme[(special)] rule is present, the lexer returns
|
no @scheme[(special)] rule is present, the lexer returns
|
||||||
@scheme[(void)].}]
|
@scheme[(void)].}]
|
||||||
|
|
||||||
End-of-files, specials, special-comments and special-errors can
|
End-of-files, specials, special-comments and special-errors cannot
|
||||||
never be part of a lexeme with surrounding characters.
|
be parsed via a rule using an ordinary regular expression
|
||||||
|
(but dropping down and manipulating the port to handle them
|
||||||
|
is possible in some situations).
|
||||||
|
|
||||||
Since the lexer gets its source information from the port, use
|
Since the lexer gets its source information from the port, use
|
||||||
@scheme[port-count-lines!] to enable the tracking of line and
|
@scheme[port-count-lines!] to enable the tracking of line and
|
||||||
|
|
|
@ -235,6 +235,18 @@
|
||||||
(else
|
(else
|
||||||
(read-char i)
|
(read-char i)
|
||||||
(cons next (special-read-line i))))))
|
(cons next (special-read-line i))))))
|
||||||
|
|
||||||
|
(define (read-line/skip-over-specials i)
|
||||||
|
(let loop ()
|
||||||
|
(let ((next (peek-char-or-special i)))
|
||||||
|
(cond
|
||||||
|
((or (eq? next #\newline) (eof-object? next))
|
||||||
|
null)
|
||||||
|
(else
|
||||||
|
(read-char-or-special i)
|
||||||
|
(if (char? next)
|
||||||
|
(cons next (loop))
|
||||||
|
(loop)))))))
|
||||||
|
|
||||||
(define (get-here-string start-pos i)
|
(define (get-here-string start-pos i)
|
||||||
(let* ((ender (list->string (special-read-line i)))
|
(let* ((ender (list->string (special-read-line i)))
|
||||||
|
@ -273,6 +285,11 @@
|
||||||
(ret lexeme 'constant #f start-pos end-pos)]
|
(ret lexeme 'constant #f start-pos end-pos)]
|
||||||
[keyword (ret lexeme 'parenthesis #f start-pos end-pos)]
|
[keyword (ret lexeme 'parenthesis #f start-pos end-pos)]
|
||||||
[str (ret lexeme 'string #f start-pos end-pos)]
|
[str (ret lexeme 'string #f start-pos end-pos)]
|
||||||
|
[";"
|
||||||
|
(values (apply string (read-line/skip-over-specials input-port)) 'comment #f
|
||||||
|
(position-offset start-pos)
|
||||||
|
(get-offset input-port))]
|
||||||
|
#;
|
||||||
[line-comment
|
[line-comment
|
||||||
(ret lexeme 'comment #f start-pos end-pos)]
|
(ret lexeme 'comment #f start-pos end-pos)]
|
||||||
["#;"
|
["#;"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
;; Not tested:
|
#lang scheme
|
||||||
|
|
||||||
|
;; Not well tested:
|
||||||
;; Non-character input data (i.e. specials)
|
;; Non-character input data (i.e. specials)
|
||||||
;; The R5RS part of numbers
|
;; The R5RS part of numbers
|
||||||
;;
|
;;
|
||||||
|
@ -40,22 +42,35 @@
|
||||||
(cons (make-string (- end start) (char kind))
|
(cons (make-string (- end start) (char kind))
|
||||||
(lex f p)))))
|
(lex f p)))))
|
||||||
|
|
||||||
(define (test input expected . num-toks)
|
(define (test input expected [e-n (chunks (string->list expected))])
|
||||||
(let* ((l (lex scheme-lexer (open-input-string input)))
|
(let* ([p (input->port input)]
|
||||||
|
(l (lex scheme-lexer p))
|
||||||
(s (apply string-append l)))
|
(s (apply string-append l)))
|
||||||
|
(close-input-port p)
|
||||||
(unless (string=? s expected)
|
(unless (string=? s expected)
|
||||||
(printf "input : ~a~n" input)
|
(printf "input : ~s~n" input)
|
||||||
(printf "output : ~s~n" s)
|
(printf "output : ~s~n" s)
|
||||||
(printf "expected: ~s~n~n" expected))
|
(printf "expected: ~s~n~n" expected))
|
||||||
(let ((e-n
|
(let ((a-n (length l)))
|
||||||
(cond
|
|
||||||
((not (null? num-toks)) (car num-toks))
|
|
||||||
(else (chunks (string->list expected)))))
|
|
||||||
(a-n (length l)))
|
|
||||||
(unless (= e-n a-n)
|
(unless (= e-n a-n)
|
||||||
(printf "input : ~a~n" input)
|
(printf "input : ~a~n" input)
|
||||||
(printf "expected: ~a tokens~n" e-n)
|
(printf "expected: ~a tokens~n" e-n)
|
||||||
(printf "got : ~a tokens~n~n" a-n)))))
|
(printf "got : ~a tokens~n~n" a-n)))))
|
||||||
|
|
||||||
|
(define (input->port input)
|
||||||
|
(let-values ([(in out) (make-pipe-with-specials)])
|
||||||
|
(thread
|
||||||
|
(λ ()
|
||||||
|
(let loop ([input input])
|
||||||
|
(cond
|
||||||
|
[(list? input)
|
||||||
|
(for-each loop input)]
|
||||||
|
[(string? input)
|
||||||
|
(display input out)]
|
||||||
|
[else
|
||||||
|
(write-special input out)]))
|
||||||
|
(close-output-port out)))
|
||||||
|
in))
|
||||||
|
|
||||||
;; Delimiters
|
;; Delimiters
|
||||||
(test " " " ")
|
(test " " " ")
|
||||||
|
@ -400,11 +415,14 @@ end-string
|
||||||
|
|
||||||
|
|
||||||
;; Comments
|
;; Comments
|
||||||
|
(test ";ab" ";;;")
|
||||||
(test #<<end-string
|
(test #<<end-string
|
||||||
1 a; asd\
|
1 a; asd\
|
||||||
1 ;a
|
1 ;a
|
||||||
end-string
|
end-string
|
||||||
"c i;;;;;; c ;;")
|
"c i;;;;;; c ;;")
|
||||||
|
(test '(";a" 1 "b") ";;;;" 1) ;; a special comment
|
||||||
|
(test '(";a" 1 "b\n1" 1) ";;;; cn" 4)
|
||||||
|
|
||||||
(test "#||#" ";;;;")
|
(test "#||#" ";;;;")
|
||||||
(test "#|#||#|#" ";;;;;;;;")
|
(test "#|#||#|#" ";;;;;;;;")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user