]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Refactored lexer to cleanup the character matching
authorMike D. Lowis <mike@mdlowis.com>
Fri, 28 Sep 2012 20:52:44 +0000 (16:52 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 28 Sep 2012 20:52:44 +0000 (16:52 -0400)
source/lexer.scm
source/parse-utils.scm

index b9b5709928cc6e016e4c08bacd2cb60d7dc8c8b4..da5cbdc2a18d2fb9580a87d6b30b51358b5eec41 100644 (file)
          (dlang/whitespace in))
 
         ; Comment
-        ((char=? (chobj-char ch) #\#)
+        ((chobj-char=? ch #\#)
          (dlang/comment in))
 
         ; Number
-        ((or
-           (and (char=? (chobj-char ch) #\-) (dlang/integer? (buf-lookahead! in 2)))
-           (char-numeric? (chobj-char ch)))
+        ((or (and (chobj-char=? ch #\-) (dlang/integer? (buf-lookahead! in 2)))
+             (char-numeric? (chobj-char ch)))
          (dlang/number in))
 
         ; Character
-        ((char=? (chobj-char ch) #\') (dlang/character in))
+        ((chobj-char=? ch #\') (dlang/character in))
 
         ; String
-        ((char=? (chobj-char ch) #\") (dlang/string in))
+        ((chobj-char=? ch #\") (dlang/string in))
 
         ; Symbol
-        ((char=? (chobj-char ch) #\$) (dlang/symbol in))
+        ((chobj-char=? ch #\$) (dlang/symbol in))
 
         ; Punctuation and Parens
-        ((char=? (chobj-char ch) #\()
+        ((chobj-char=? ch #\()
          (token 'lpar (string (chobj-char (buf-consume! in))) location))
-        ((char=? (chobj-char ch) #\))
+        ((chobj-char=? ch #\))
          (token 'rpar (string (chobj-char (buf-consume! in))) location))
-        ((char=? (chobj-char ch) #\,)
+        ((chobj-char=? ch #\,)
          (token 'comma (string (chobj-char (buf-consume! in))) location))
-        ((char=? (chobj-char ch) #\;)
+        ((chobj-char=? ch #\;)
          (token 'term (string (chobj-char (buf-consume! in))) location))
 
         ; Id
@@ -52,7 +51,7 @@
           (dlang/id in))))
     (if (and (not (eof-object? tok))
              (equal? "end" (token-text tok)))
-      (token-type-set! tok 'term))
+        (token-type-set! tok 'term))
     tok))
 
 (define (dlang/whitespace in)
 
 (define (dlang/comment? in)
   (and (not (eof-object? (buf-lookahead! in 1)))
-       (not (char=? (chobj-char (buf-lookahead! in 1)) #\newline))))
+       (not (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=? #\- (chobj-char (buf-lookahead! in 1))))
-        (string (chobj-char (buf-consume! in))) "")
+      (if (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=? (chobj-char (buf-lookahead! in 1)) #\.))
-        (dlang/decimal in) "")
-      (if (and (not (eof-object? (buf-lookahead! in 1)))
-               (or (char=? (chobj-char (buf-lookahead! in 1)) #\e)
-                   (char=? (chobj-char (buf-lookahead! in 1)) #\E)))
-        (dlang/exponent in) ""))
+      (if (chobj-char=? (buf-lookahead! in 1) #\.)
+          (dlang/decimal in) "")
+      (if (or (chobj-char=? (buf-lookahead! in 1) #\e)
+              (chobj-char=? (buf-lookahead! in 1) #\E))
+          (dlang/exponent in) ""))
     location))
 
 (define (dlang/integer in)
index b9c6ed583a1a75a95e4f9ede76415f29eb6812af..320823ca7333847a9cac4c914d7485ce65f15642 100644 (file)
   (and (char=?    (chobj-char cho1) (chobj-char cho2))
        (posdata=? (chobj-pos cho1)  (chobj-pos cho2))))
 
+(define (chobj-char=? obj ch)
+  (and (not (eof-object? obj))
+       (char=? (chobj-char obj) ch)))
+
 (define (charport-read chprt)
   (define ch (read-char (charport-port chprt)))
   (cond