]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Started work on dlang parser and finished number lexing functions for the lexer
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Jul 2012 04:17:14 +0000 (00:17 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Jul 2012 04:17:14 +0000 (00:17 -0400)
source/lexer.scm
source/parser.scm [new file with mode: 0644]
tools/unit.scm [deleted file]

index a9ff5c89d336176e3ded37d68e9a88eba06d539a..4b80c49b9f7152ad0755fd2055eee681c4ae2c3b 100644 (file)
   (while (not (char=? (buf-lookahead! in) #\newline))
     (buf-consume! in)))
 
-(define (dlang/number in str) 'number)
+(define (dlang/number in)
+  (lex/token 'number
+    (string-append
+      (if (char=? #\- (buf-lookahead! in 1)) (buf-consume! in) "")
+      (dlang/integer in)
+      (if (char=? (buf-lookahead! in 1) #\.)
+        (dlang/decimal in) "")
+      (if (or (char=? (buf-lookahead! in 1) #\e)
+              (char=? (buf-lookahead! in 1) #\E))
+        (dlang/exponent in) ""))))
+
+(define (dlang/integer in)
+  (define text "")
+  (if (char-numeric? (buf-lookahead! in 1))
+    (while (char-numeric? (buf-lookahead! in 1))
+      (set! text (string-append text (string (buf-consume! in)))))
+    (error "Expected a number."))
+  text)
+
+(define (dlang/decimal in)
+  (string-append
+    (match in #\.)
+    (dlang/digits in "")))
+
+(define (dlang/exponent in)
+  (string-append
+    (if (char=? (buf-lookahead! in 1) #\e)
+      (match in #\e) (match in #\E))
+    (dlang/integer in "")))
+
 (define (dlang/character in str)
   (token 'character
     (string-append
     (if
       (and (not (char-whitespace? ch))
            (not (eof-object? ch)))
-      (loop (string-append acc (buf-consume! in)) (buf-lookahead! in 1)))
-    acc))
-
+      (loop (string-append acc (buf-consume! in)) (buf-lookahead! in 1))
+      (token 'id acc))))
 
diff --git a/source/parser.scm b/source/parser.scm
new file mode 100644 (file)
index 0000000..7af96ee
--- /dev/null
@@ -0,0 +1,30 @@
+(declare (unit parser)
+         (uses buf))
+
+(define (dlang/program in)
+  (define result '())
+  (while (not (eof-object? (buf-lookahead! in 1)))
+    (append result (list (dlang/expression in)))))
+
+(define (dlang/expression in)
+  (if (core-form? in)
+    (core-from in)
+    (let ((result (basic-expr in))
+          (ret    '()))
+      (if (equal? 'lpar (buf-lookahead! in 1))
+        (begin
+          (match in 'lpar)
+          (set! ret (expr-list in))
+          (match in 'rpar)))
+      ret)))
+
+(define (dlang/core-form in) '())
+
+(define (dlang/basic-expr in) '())
+
+(define (dlang/literal in) '())
+
+(define (dlang/expr-list in) '())
+
+(define (dlang/id-list in) '())
+
diff --git a/tools/unit.scm b/tools/unit.scm
deleted file mode 100644 (file)
index 4bc6809..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-(declare (unit unit))
-
-(define tests-suites '())
-