From: Mike D. Lowis Date: Fri, 20 Jul 2012 17:44:28 +0000 (-0400) Subject: Refactored lexer rule for string by adding a string character recognition predicate X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6c361edd571c3d8c36d407716585655c9bff561d;p=archive%2Fdlang-scm.git Refactored lexer rule for string by adding a string character recognition predicate --- diff --git a/source/lexer.scm b/source/lexer.scm index c1426c9..c4d1fe8 100644 --- a/source/lexer.scm +++ b/source/lexer.scm @@ -114,13 +114,17 @@ (define (dlang/string in) (define text (string (char-match in #\"))) - (while (and (not (eof-object? (buf-lookahead! in 1))) - (not (char=? #\newline (buf-lookahead! in 1))) - (not (char=? #\" (buf-lookahead! in 1)))) + (while (dlang/string-char? in) (set! text (string-append text (string (buf-consume! in))))) (set! text (string-append text (string (char-match in #\")))) (token 'string text)) +(define (dlang/string-char? in) + (define ch (buf-lookahead! in 1)) + (and (not (eof-object? ch)) + (not (char=? #\newline ch)) + (not (char=? #\" ch)))) + (define (dlang/symbol in) (token 'symbol (string-append