From: Mike D. Lowis Date: Fri, 28 Sep 2012 20:28:34 +0000 (-0400) Subject: Renamed charobj to chobj X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=10ba7569b166aa066e14f9608fc261072647ed19;p=archive%2Fdlang-scm.git Renamed charobj to chobj --- diff --git a/source/lexer.scm b/source/lexer.scm index bcdf7d5..b9b5709 100644 --- a/source/lexer.scm +++ b/source/lexer.scm @@ -19,33 +19,33 @@ (dlang/whitespace in)) ; Comment - ((char=? (charobj-char ch) #\#) + ((char=? (chobj-char ch) #\#) (dlang/comment in)) ; Number ((or - (and (char=? (charobj-char ch) #\-) (dlang/integer? (buf-lookahead! in 2))) - (char-numeric? (charobj-char ch))) + (and (char=? (chobj-char ch) #\-) (dlang/integer? (buf-lookahead! in 2))) + (char-numeric? (chobj-char ch))) (dlang/number in)) ; Character - ((char=? (charobj-char ch) #\') (dlang/character in)) + ((char=? (chobj-char ch) #\') (dlang/character in)) ; String - ((char=? (charobj-char ch) #\") (dlang/string in)) + ((char=? (chobj-char ch) #\") (dlang/string in)) ; Symbol - ((char=? (charobj-char ch) #\$) (dlang/symbol in)) + ((char=? (chobj-char ch) #\$) (dlang/symbol in)) ; Punctuation and Parens - ((char=? (charobj-char ch) #\() - (token 'lpar (string (charobj-char (buf-consume! in))) location)) - ((char=? (charobj-char ch) #\)) - (token 'rpar (string (charobj-char (buf-consume! in))) location)) - ((char=? (charobj-char ch) #\,) - (token 'comma (string (charobj-char (buf-consume! in))) location)) - ((char=? (charobj-char ch) #\;) - (token 'term (string (charobj-char (buf-consume! in))) location)) + ((char=? (chobj-char ch) #\() + (token 'lpar (string (chobj-char (buf-consume! in))) location)) + ((char=? (chobj-char ch) #\)) + (token 'rpar (string (chobj-char (buf-consume! in))) location)) + ((char=? (chobj-char ch) #\,) + (token 'comma (string (chobj-char (buf-consume! in))) location)) + ((char=? (chobj-char ch) #\;) + (token 'term (string (chobj-char (buf-consume! in))) location)) ; Id (else @@ -61,7 +61,7 @@ (define (dlang/whitespace? in) (and (not (eof-object? (buf-lookahead! in 1))) - (char-whitespace? (charobj-char (buf-lookahead! in 1))))) + (char-whitespace? (chobj-char (buf-lookahead! in 1))))) (define (dlang/comment in) (char-match in #\#) @@ -70,22 +70,22 @@ (define (dlang/comment? in) (and (not (eof-object? (buf-lookahead! in 1))) - (not (char=? (charobj-char (buf-lookahead! in 1)) #\newline)))) + (not (char=? (chobj-char (buf-lookahead! in 1)) #\newline)))) (define (dlang/number in) (define location (buf-posdata in)) (token 'number (string-append (if (and (not (eof-object? (buf-lookahead! in 1))) - (char=? #\- (charobj-char (buf-lookahead! in 1)))) - (string (charobj-char (buf-consume! in))) "") + (char=? #\- (chobj-char (buf-lookahead! in 1)))) + (string (chobj-char (buf-consume! in))) "") (dlang/integer in) (if (and (not (eof-object? (buf-lookahead! in 1))) - (char=? (charobj-char (buf-lookahead! in 1)) #\.)) + (char=? (chobj-char (buf-lookahead! in 1)) #\.)) (dlang/decimal in) "") (if (and (not (eof-object? (buf-lookahead! in 1))) - (or (char=? (charobj-char (buf-lookahead! in 1)) #\e) - (char=? (charobj-char (buf-lookahead! in 1)) #\E))) + (or (char=? (chobj-char (buf-lookahead! in 1)) #\e) + (char=? (chobj-char (buf-lookahead! in 1)) #\E))) (dlang/exponent in) "")) location)) @@ -96,7 +96,7 @@ (define (dlang/integer? in) (and (not (eof-object? (buf-lookahead! in 1))) - (char-numeric? (charobj-char (buf-lookahead! in 1))))) + (char-numeric? (chobj-char (buf-lookahead! in 1))))) (define (dlang/decimal in) (string-append @@ -107,12 +107,12 @@ (string-append (string (if (and (not (eof-object? (buf-lookahead! in 1))) - (char=? #\e (charobj-char (buf-lookahead! in 1)))) + (char=? #\e (chobj-char (buf-lookahead! in 1)))) (char-match in #\e) (char-match in #\E))) (if (and (not (eof-object? (buf-lookahead! in 1))) - (char=? #\- (charobj-char (buf-lookahead! in 1)))) - (string (charobj-char (buf-consume! in))) "") + (char=? #\- (chobj-char (buf-lookahead! in 1)))) + (string (chobj-char (buf-consume! in))) "") (dlang/integer in))) (define (dlang/character in) @@ -122,7 +122,7 @@ (string (char-match in #\')) (if (eof-object? (buf-lookahead! in 1)) (abort "Unexpected EOF while parsing character literal") - (string (charobj-char (buf-consume! in)))) + (string (chobj-char (buf-consume! in)))) (string (char-match in #\'))) location)) @@ -138,8 +138,8 @@ (define (dlang/string-char? in) (define ch (buf-lookahead! in 1)) (and (not (eof-object? ch)) - (not (char=? #\newline (charobj-char ch))) - (not (char=? #\" (charobj-char ch))))) + (not (char=? #\newline (chobj-char ch))) + (not (char=? #\" (chobj-char ch))))) (define (dlang/symbol in) (define location (buf-posdata in)) @@ -159,8 +159,8 @@ (define (dlang/id-char? in) (define ch (buf-lookahead! in 1)) (and (not (eof-object? ch)) - (not (char-whitespace? (charobj-char ch))) - (case (charobj-char ch) + (not (char-whitespace? (chobj-char ch))) + (case (chobj-char ch) ((#\( #\) #\; #\, #\' #\" #\$ #\#) #f) (else #t)))) diff --git a/source/parse-utils.scm b/source/parse-utils.scm index 2df1d03..b9c6ed5 100644 --- a/source/parse-utils.scm +++ b/source/parse-utils.scm @@ -28,22 +28,20 @@ (syntree-children=? (syntree-children tr1) (syntree-children tr2)))) (define (syntree-children=? ch1 ch2) - (and - (or - (and (null? ch1) (null? ch2)) - (and (not (null? ch1)) (not (null? ch2)))) - (if (null? ch1) - #t ; If we got here and one is null then BOTH must be, hence equal - (and - (syntree=? (car ch1) (car ch2)) - (syntree-children=? (cdr ch1) (cdr ch2)))))) - -(define-record charobj char pos) -(define charobj make-charobj) - -(define (charobj=? cho1 cho2) - (and (char=? (charobj-char cho1) (charobj-char cho2)) - (posdata=? (charobj-pos cho1) (charobj-pos cho2)))) + (and (or (and (null? ch1) (null? ch2)) + (and (not (null? ch1)) (not (null? ch2)))) + (if (null? ch1) + #t ; If we got here and one is null then BOTH must be, hence equal + (and + (syntree=? (car ch1) (car ch2)) + (syntree-children=? (cdr ch1) (cdr ch2)))))) + +(define-record chobj char pos) +(define chobj make-chobj) + +(define (chobj=? cho1 cho2) + (and (char=? (chobj-char cho1) (chobj-char cho2)) + (posdata=? (chobj-pos cho1) (chobj-pos cho2)))) (define (charport-read chprt) (define ch (read-char (charport-port chprt))) @@ -54,7 +52,7 @@ (charport-column-set! chprt 1)) (else (charport-column-set! chprt (+ 1 (charport-column chprt))))) - (if (eof-object? ch) ch (charobj ch (charport-posdata chprt)))) + (if (eof-object? ch) ch (chobj ch (charport-posdata chprt)))) (define (charport-posdata chprt) (posdata @@ -73,13 +71,13 @@ (if (eof-object? actual) (abort (string-append "Expected '" (string expect) "', received EOF instead")) - (if (equal? expect (charobj-char actual)) + (if (equal? expect (chobj-char actual)) (buf-consume! buf) (abort (string-append "Expected '" (string expect) - "', received '" (string (charobj-char actual)) "' instead")))) - (charobj-char actual)) + "', received '" (string (chobj-char actual)) "' instead")))) + (chobj-char actual)) (define (token-match buf expect) (define actual (buf-lookahead! buf 1)) @@ -129,7 +127,7 @@ (not (null? result))) (define (collect-char in predfn) - (list->string (map charobj-char (collect in predfn buf-consume!)))) + (list->string (map chobj-char (collect in predfn buf-consume!)))) (define (consume-all in predfn) (when (predfn in) diff --git a/tests/test_parse_utils.scm b/tests/test_parse_utils.scm index 4a70eba..2450e09 100644 --- a/tests/test_parse_utils.scm +++ b/tests/test_parse_utils.scm @@ -149,8 +149,8 @@ (call-with-input-string "a" (lambda (input) (define port (charport input)) - (define chobj (charport-read port)) - (and (charobj=? (charobj #\a (posdata "(string)" 1 2)) chobj) + (define result (charport-read port)) + (and (chobj=? (chobj #\a (posdata "(string)" 1 2)) result) (equal? 1 (charport-line port)) (equal? 2 (charport-column port)))))) @@ -158,8 +158,8 @@ (call-with-input-string "\n" (lambda (input) (define port (charport input)) - (define chobj (charport-read port)) - (and (charobj=? (charobj #\newline (posdata "(string)" 2 1)) chobj) + (define result (charport-read port)) + (and (chobj=? (chobj #\newline (posdata "(string)" 2 1)) result) (equal? 2 (charport-line port)) (equal? 1 (charport-column port)))))) @@ -355,7 +355,7 @@ (lambda (input) (define buffer (buf (charport input) charport-read)) (consume-all buffer dlang/integer?) - (charobj=? (charobj #\a (posdata "(string)" 1 2)) + (chobj=? (chobj #\a (posdata "(string)" 1 2)) (buf-lookahead! buffer 1))))) (def-test "should consume an item at a time until predicate returns false" @@ -363,7 +363,7 @@ (lambda (input) (define buffer (buf (charport input) charport-read)) (consume-all buffer dlang/integer?) - (charobj=? (charobj #\a (posdata "(string)" 1 5)) + (chobj=? (chobj #\a (posdata "(string)" 1 5)) (buf-lookahead! buffer 1))))) ; collect @@ -380,5 +380,5 @@ (define buffer (buf (charport input) charport-read)) (define result (collect buffer dlang/integer? buf-consume!)) (equal? '(#\1 #\2 #\3) - (map charobj-char result))))) + (map chobj-char result)))))