Support for #: keywords in the syntax colorer.

svn: r1314
This commit is contained in:
Scott Owens 2005-11-14 21:53:37 +00:00
parent 4ebb06b25c
commit 73d12ea244
2 changed files with 103 additions and 15 deletions

View File

@ -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)]))

View File

@ -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 #<<end-string
#:\ \8\ \a\\
end-string
"cccccccccccc")
(test "#:||" "cccc")
(test "#:|a|" "ccccc")
(test "#:|8|" "ccccc")
(test "#:|\\|" "ccccc")
(test "#:a| |a" "ccccccc")
(test "#:a|\t|a" "ccccccc")
(test "#:a|\n|a" "ccccccc")
(test "#:a|\"|a" "ccccccc")
(test "#:a|,|a" "ccccccc")
(test "#:a|'|a" "ccccccc")
(test "#:a|`|a" "ccccccc")
(test "#:a|;|a" "ccccccc")
(test "#:a|(|a" "ccccccc")
(test "#:a|)|a" "ccccccc")
(test "#:a|[|a" "ccccccc")
(test "#:a|]|a" "ccccccc")
(test "#:a|{|a" "ccccccc")
(test "#:a|}|a" "ccccccc")
(test "#:a|,|\\ |||\\|| se \\|\\\\|\\\\|" "cccccccccccccccccccccccccc")
(test "#:\\ ,#:a" "ccccoccc")
(test "#:| |a,#:a" "ccccccoccc")
(test "#:a#||#" "ccccccc")
(test "#:a#;1 2" "cccc;;;;")
(test "#:a#<<a" "ccccccc")
(test "#:1#!1" "cccccc")
(test "#:1+nan.0" "ccccccccc")
(test "#:-inf.0+1" "cccccccccc")
(test "#:\\#:a" "cccccc")
(test "#:#\\:a" "cccccc")
(test "#:1.1" "ccccc")
(test "#:a|" "xxxx")
(test "#:a#|" "xxxxx")
(test "#:a||a|, a\n\"" "xxxxxxxxxxxx")