From 287adc0bee741ee5b0ec5eed78a59316bab199ea Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 9 Jul 2012 00:17:14 -0400 Subject: [PATCH] Started work on dlang parser and finished number lexing functions for the lexer --- source/lexer.scm | 36 ++++++++++++++++++++++++++++++++---- source/parser.scm | 30 ++++++++++++++++++++++++++++++ tools/unit.scm | 4 ---- 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 source/parser.scm delete mode 100644 tools/unit.scm diff --git a/source/lexer.scm b/source/lexer.scm index a9ff5c8..4b80c49 100644 --- a/source/lexer.scm +++ b/source/lexer.scm @@ -49,7 +49,36 @@ (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 @@ -76,7 +105,6 @@ (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 index 0000000..7af96ee --- /dev/null +++ b/source/parser.scm @@ -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 index 4bc6809..0000000 --- a/tools/unit.scm +++ /dev/null @@ -1,4 +0,0 @@ -(declare (unit unit)) - -(define tests-suites '()) - -- 2.52.0