From c1f5e3abb40189405d0068a873e5a25e593855ad Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 28 Jul 2009 21:11:51 +0000 Subject: [PATCH] changed Scribble coloring for better tabbing svn: r15612 --- collects/syntax-color/scribble-lexer.ss | 20 ++++++++++++++----- collects/tests/syntax-color/scribble-lexer.ss | 14 ++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/collects/syntax-color/scribble-lexer.ss b/collects/syntax-color/scribble-lexer.ss index 7838b46495..1804b9d53c 100644 --- a/collects/syntax-color/scribble-lexer.ss +++ b/collects/syntax-color/scribble-lexer.ss @@ -15,7 +15,7 @@ (make-text #rx"^@" #f #f - #rx".*?(?:(?=@)|$)" + #rx".*?(?:(?=[@\r\n])|$)" #f #f)))]) (let-values ([(line col pos) (port-next-location in)] @@ -38,7 +38,7 @@ mode))) ;; Line comment: (begin - (regexp-match #rx"\r\n|\r|\n" in) + (regexp-match? #rx".*?(?=[\r\n])" in) (let-values ([(end-line end-col end-pos) (port-next-location in)]) (comment-k "@;" 'comment @@ -96,8 +96,18 @@ pos end-pos (cons (car mode) mode)))] + [(regexp-try-match #px"^(?:[\r\n])\\s*" in) + ;; Treat a newline and leading whitespace in text mode as whitespace + ;; instead of as a string: + (let-values ([(end-line end-col end-pos) (port-next-location in)]) + (values " " + 'white-space + #f + pos + end-pos + mode))] [else - ;; Read string up to @ or } + ;; Read string up to @, }, or newline (regexp-match? (text-string-rx l) in) (let-values ([(end-line end-col end-pos) (port-next-location in)]) (values 'string @@ -220,7 +230,7 @@ re-opener #"[@{])|(?=" closer - #")|$)")) + #")|(?=[\r\n])|$)")) #f #f) (cdr mode))))))] @@ -234,7 +244,7 @@ (cons (make-text #rx"^@" #rx"^}" #rx"^{" - #rx".*?(?:(?=[@{}])|$)" + #rx".*?(?:(?=[@{}\r\n])|$)" '|{| '|}|) (cdr mode))))] diff --git a/collects/tests/syntax-color/scribble-lexer.ss b/collects/tests/syntax-color/scribble-lexer.ss index 9a8e952017..9aff1bd8f5 100644 --- a/collects/tests/syntax-color/scribble-lexer.ss +++ b/collects/tests/syntax-color/scribble-lexer.ss @@ -187,7 +187,8 @@ (1 other))) (test "@; 1" '((4 comment))) -(test "@; 1\nv" '((5 comment) +(test "@; 1\nv" '((4 comment) + (1 white-space) (1 string))) (test "@;{1}v" '((2 comment) (1 other) @@ -199,3 +200,14 @@ (5 string) (2 other) (1 string))) + +(test "a\n b" '((1 string) + (3 white-space) + (1 string))) +(test "@item{A\nB}" '((1 other) + (4 symbol) + (1 other) + (1 string) + (1 white-space) + (1 string) + (1 other)))