-
-
Save kurinoku/89fce7fcbf5da1f3baecf67beb3e90c6 to your computer and use it in GitHub Desktop.
Trying to parse a file of links with titles, but some unexpected behavior happened.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require br-parser-tools/lex | |
(prefix-in : br-parser-tools/lex-sre)) | |
(module+ test | |
(require rackunit)) | |
(define (read-links in) | |
(define l | |
(lexer | |
[(:or blank whitespace) (l in)] | |
[(:: "http" (:+ (:~ blank whitespace))) `(url ,lexeme)] | |
[(:: (:~ blank whitespace) (:* (:~ #\newline))) `(title ,lexeme)] | |
[(eof) (void)])) | |
(define (next-token) (l in)) | |
(let loop () | |
(let ([a (next-token)]) | |
(if (void? a) | |
'() | |
(list* a (loop)))))) | |
(module+ test | |
(define a | |
" | |
https://abc.com e | |
our world | |
on fire | |
https://www.example.com | |
") | |
(check-equal? (read-links (open-input-string a)) | |
'((url "https://abc.com") | |
(title "e") | |
(title "our world") | |
(title "on fire") | |
(url "https://www.example.com")))) | |
#| | |
-------------------- | |
. FAILURE | |
name: check-equal? | |
location: link-reader.rkt:35:2 | |
actual: | |
'((title "https://abc.com e") | |
(title "our world") | |
(title "on fire") | |
(url "https://www.example.com")) | |
expected: | |
'((url "https://abc.com") | |
(title "e") | |
(title "our world") | |
(title "on fire") | |
(url "https://www.example.com")) | |
-------------------- | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment