(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))))
--- /dev/null
+(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) '())
+