diff --git a/collects/syntax-color/scheme-lexer.ss b/collects/syntax-color/scheme-lexer.ss index bf9e736a30..3b7a3430fb 100644 --- a/collects/syntax-color/scheme-lexer.ss +++ b/collects/syntax-color/scheme-lexer.ss @@ -126,8 +126,9 @@ (:? "\\" bad-id-escapes)) "\\" bad-id-escapes)] - - + + [keyword (:: "#:" (:* identifier-escapes identifier-chars))] + [reader-command (:or (:: "#" c s) (:: "#" c i))] [sharing (:or (:: "#" (make-uinteger digit10) "=") (:: "#" (make-uinteger digit10) "#"))]) @@ -258,8 +259,9 @@ (define scheme-lexer (lexer - [(:+ scheme-whitespace) (ret lexeme 'white-space #f start-pos end-pos)] - [(:or "#t" "#f" "#T" "#F" character + [(:+ scheme-whitespace) + (ret lexeme 'white-space #f start-pos end-pos)] + [(:or "#t" "#f" "#T" "#F" character keyword (make-num digit2 radix2) (make-num digit8 radix8) (make-num digit10 (:? radix10)) @@ -270,19 +272,21 @@ (ret lexeme 'comment #f start-pos end-pos)] ["#|" (read-nested-comment 1 start-pos input-port)] [(:: (:or "" "#hash" "#hasheq" (:: "#" (:* digit10))) "(") - (values lexeme 'parenthesis '|(| (position-offset start-pos) (position-offset end-pos))] + (ret lexeme 'parenthesis '|(| start-pos end-pos)] [(:: (:or "" "#hash" "#hasheq" (:: "#" (:* digit10))) "[") - (values lexeme 'parenthesis '|[| (position-offset start-pos) (position-offset end-pos))] + (ret lexeme 'parenthesis '|[| start-pos end-pos)] [(:: (:or "" "#hash" "#hasheq" (:: "#" (:* digit10))) "{") - (values lexeme 'parenthesis '|{| (position-offset start-pos) (position-offset end-pos))] + (ret lexeme 'parenthesis '|{| start-pos end-pos)] [(:or ")" "]" "}") - (values lexeme 'parenthesis (string->symbol lexeme) (position-offset start-pos) (position-offset end-pos))] + (ret lexeme 'parenthesis (string->symbol lexeme) start-pos end-pos)] [(:or "'" "`" "#'" "#`" "#&") - (values lexeme 'constant #f (position-offset start-pos) (position-offset end-pos))] + (ret lexeme 'constant #f start-pos end-pos)] [(:or script sharing reader-command "." "," ",@" "#," "#,@") - (values lexeme 'other #f (position-offset start-pos) (position-offset end-pos))] - [identifier (values lexeme 'symbol #f (position-offset start-pos) (position-offset end-pos))] - ["#<<" (get-here-string (position-offset start-pos) input-port)] + (ret lexeme 'other #f start-pos end-pos)] + [identifier + (ret lexeme 'symbol #f start-pos end-pos)] + ["#<<" + (get-here-string (position-offset start-pos) input-port)] [(special) (ret "" 'no-color #f start-pos end-pos)] [(special-comment) @@ -290,7 +294,8 @@ [(eof) (values lexeme 'eof #f #f #f)] [(:or bad-char bad-str (:& bad-id - (complement (:: (:or (:: "#" (:or f t)) reader-command sharing "#<<" "#\\" "#|" "#;" "#&" script) any-string)))) + (complement (:: (:or (:: "#" (:or f t)) reader-command sharing "#<<" "#\\" "#|" "#;" "#&" script) + any-string)))) (ret lexeme 'error #f start-pos end-pos)] [any-char (extend-error lexeme start-pos end-pos input-port)])) diff --git a/collects/tests/syntax-color/scheme-lexer.ss b/collects/tests/syntax-color/scheme-lexer.ss index 908eb845ad..ee232aaea4 100644 --- a/collects/tests/syntax-color/scheme-lexer.ss +++ b/collects/tests/syntax-color/scheme-lexer.ss @@ -3,7 +3,6 @@ ;; The R5RS part of numbers ;; ;; Not supported -;; Keywords ;; Honu (#hx, #sx, #honu) ;; #reader @@ -214,7 +213,8 @@ end-string (test "1#!1" "iiii") (test "1+nan.0" "iiiiiii") (test "-inf.0+1" "iiiiiiii") - +(test "\\#:a" "iiii") +(test "#\\:a" "ccci") ;; Bad identifiers (test "#a" "xx") @@ -444,3 +444,86 @@ end-string (test "#x1E+2" "xxxxxx") (test "#x1d+2" "xxxxxx") +;; Keywords +(test "#:" "cc") +(test "#:a#:a" "cccccc") +(test "#:a #:a" "ccc ccc") +(test "#:a\t#:a" "ccc ccc") +(test "#:a\n#:a" "ccc ccc") +(test "#:a\"#:a" "cccxxxx") +(test "#:a,#:a" "cccoccc") +(test "#:a'#:a" "ccccccc" 3) +(test "#:a`#:a" "ccccccc" 3) +(test "#:a;#:a" "ccc;;;;") +(test "#:a(#:a" "cccpccc") +(test "#:a)#:a" "cccpccc") +(test "#:a[#:a" "cccpccc") +(test "#:a]#:a" "cccpccc") +(test "#:a{#:a" "cccpccc") +(test "#:a}#:a" "cccpccc") +(test "#:a##:a" "ccccccc") +(test "#:a.#:a" "ccccccc") +(test "#:a@#:a" "ccccccc") +(test "#:a/#:a" "ccccccc") +(test "#:a\"#:a\"#:a" "cccsssssccc") +(test "#:a1#:a" "ccccccc") +(test "#:a%#:a" "ccccccc") + +(test "#:1a" "cccc") +(test "#:\\8" "cccc") +(test "#:\\a" "cccc") +(test "#:\\\\" "cccc") +(test "#:a\\ a" "cccccc") +(test "#:a\\\ta" "cccccc") +(test "#:a\\\na" "cccccc") +(test "#:a\\\"a" "cccccc") +(test "#:a\\,a" "cccccc") +(test "#:a\\'a" "cccccc") +(test "#:a\\`a" "cccccc") +(test "#:a\\;a" "cccccc") +(test "#:a\\(a" "cccccc") +(test "#:a\\)a" "cccccc") +(test "#:a\\[a" "cccccc") +(test "#:a\\]a" "cccccc") +(test "#:a\\{a" "cccccc") +(test "#:a\\}a" "cccccc") +(test "#:\\|" "cccc") +(test "#:a\\|a" "cccccc") +(test #<