Created
September 21, 2013 20:36
-
-
Save funrep/6653937 to your computer and use it in GitHub Desktop.
Simple IRC parser, tries to replicate https://github.com/Tehnix/HsIRCParser/blob/master/HsIRCParser.hs made by @Tehnix
This file contains hidden or 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 | |
(provide split-message | |
get-nick | |
get-host | |
get-chan | |
get-action) | |
(define (split-message s) | |
(let ([ss (regexp-split #rx":" s)]) | |
(match ss | |
[(list " " _ ...) (cdr ss)] | |
[_ ss]))) | |
(define (split-bang s) | |
(regexp-split #rx"!" s)) | |
(define (split-at s) | |
(regexp-split #rx"@" s)) | |
(define (get-nick ss) | |
(regexp-replace #rx"[@~!&]" (car (split-bang (car ss))) "")) | |
(define (get-host ss) | |
(car (string-split | |
(cadr (split-at | |
(cadr (split-bang (car ss)))))))) | |
(define (get-chan ss) | |
(if (null? ss) | |
"" ; FIXME | |
(if (chan? (car ss)) | |
(car ss) | |
(get-chan (cdr ss))))) | |
(define (chan? s) | |
(match s | |
[(regexp #rx"^#.") #t] | |
[_ #f])) | |
(define (get-action ss) | |
(cadr (string-split (car ss)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment