@@ -88,80 +88,81 @@ insufficient. See issue #734."
88
88
(< (point-min ) beg))
89
89
(cons (1- beg) end)))
90
90
91
+ (defconst racket--syntax-propertize-rules
92
+ (syntax-propertize-rules
93
+ ; ; here strings: The main responsibility here is to set the "|"
94
+ ; ; char syntax around the "body" so it's treated as a string for
95
+ ; ; indent, nav, font-lock. Think of the \n in #<<ID\n as the open
96
+ ; ; | quote and the \n in ^ID\n as the close | quote.
97
+ ((rx " #<<" (group (+? (not (any ?\n )))) (group ?\n ))
98
+ (2 (racket--syntax-propertize-open-here-string
99
+ (match-beginning 0 )
100
+ (match-string-no-properties 1 )
101
+ (match-beginning 2 ))))
102
+ ((rx (syntax string-delimiter))
103
+ (0 (ignore (racket--syntax-propertize-here-string end))))
104
+ ; ; sexp comments should LOOK like comments but NOT ACT like
105
+ ; ; comments: Give the #; itself the syntax class "prefix" [1], but
106
+ ; ; allow the following sexp to get the usual syntaxes. That way
107
+ ; ; things like indent and sexp nav work within the sexp. Only
108
+ ; ; font-lock handles the sexp specially; see racket-font-lock.el.
109
+ ; ;
110
+ ; ; [1]: Although it's tempting to use punctuation -- so things like
111
+ ; ; `backward-sexp' and `racket-send-last-sexp' ignore the #; --
112
+ ; ; that would mess up indentation of things following the sexp
113
+ ; ; comment. Instead special-case `racket-send-last-sexp' .
114
+ ((rx " #;" )
115
+ (0 " '" ))
116
+ ; ; Character literals. See:
117
+ ; ; <https://docs.racket-lang.org/reference/reader.html#(part._parse-character)>
118
+ ((rx (group " #\\ " (or " nul" " null"
119
+ " backspace"
120
+ " tab" " vtab"
121
+ " newline" " linefeed"
122
+ " page"
123
+ " return"
124
+ " space"
125
+ " rubout"
126
+ (** 3 3 (any (?0 . ?7 )))
127
+ (seq ?u (** 1 4 hex-digit))
128
+ (seq ?U (** 1 6 hex-digit))
129
+ anything))
130
+ (or (not alphabetic) eol))
131
+ (1 " w" ))
132
+ ; ; Treat "complex" reader literals as a single sexp for nav and
133
+ ; ; indent, by also marking as prefix syntax the stuff after the #.
134
+ ; ; Racket predefines reader literals like #"" #rx"" #px"" #hash()
135
+ ; ; #hasheq() #fx3(0 1 2) #s() and so on. I think these -- plus any
136
+ ; ; user defined reader extensions -- can all be covered with the
137
+ ; ; following general rx. Also it seems sufficient to look for just
138
+ ; ; the opening delimiter -- the ( [ { or " -- here.
139
+ ((rx (not (any ?| ))
140
+ (group ?#
141
+ (?? (not (any ?| ; not comment #362
142
+ ?: ; not keyword arg #448
143
+ space ; not space #546
144
+ ?\\ ))
145
+ (*? (or (syntax symbol) (syntax word) (syntax punctuation)))))
146
+ (any ?\" ?\( ?\[ ?\{ ))
147
+ (1 " '" ))
148
+ ; ; Syntax quoting
149
+ ((rx ?# (or ?` ?' ?, ))
150
+ (0 " '" ))
151
+ ; ; Treat '|symbol with spaces| as word syntax
152
+ ((rx ?' ?| (*? (not (any ?\" ?\r ?\n ))) ?| )
153
+ (0 " w" ))
154
+ ; ; Treat |identifier with spaces| -- but not #|comment|# -- as
155
+ ; ; word syntax
156
+ ((rx (not (any ?# ))
157
+ (group ?| (*? (not (any ?\" ?\r ?\n ))) ?| ))
158
+ (1 " w" )))
159
+ " A function value for use by `racket-syntax-propertize' ." )
160
+
91
161
(defun racket-syntax-propertize (start end )
92
162
" Value for variable `syntax-propertize-function' ."
93
163
(goto-char start)
94
164
(racket--syntax-propertize-here-string end)
95
- (funcall
96
- (syntax-propertize-rules
97
- ; ; here strings: The main responsibility here is to set the "|"
98
- ; ; char syntax around the "body" so it's treated as a string for
99
- ; ; indent, nav, font-lock. Think of the \n in #<<ID\n as the open
100
- ; ; | quote and the \n in ^ID\n as the close | quote.
101
- ((rx " #<<" (group (+? (not (any ?\n )))) (group ?\n ))
102
- (2 (racket--syntax-propertize-open-here-string
103
- (match-beginning 0 )
104
- (match-string-no-properties 1 )
105
- (match-beginning 2 ))))
106
- ((rx (syntax string-delimiter))
107
- (0 (ignore (racket--syntax-propertize-here-string end))))
108
- ; ; sexp comments should LOOK like comments but NOT ACT like
109
- ; ; comments: Give the #; itself the syntax class "prefix" [1], but
110
- ; ; allow the following sexp to get the usual syntaxes. That way
111
- ; ; things like indent and sexp nav work within the sexp. Only
112
- ; ; font-lock handles the sexp specially; see racket-font-lock.el.
113
- ; ;
114
- ; ; [1]: Although it's tempting to use punctuation -- so things like
115
- ; ; `backward-sexp' and `racket-send-last-sexp' ignore the #; --
116
- ; ; that would mess up indentation of things following the sexp
117
- ; ; comment. Instead special-case `racket-send-last-sexp' .
118
- ((rx " #;" )
119
- (0 " '" ))
120
- ; ; Character literals. See:
121
- ; ; <https://docs.racket-lang.org/reference/reader.html#(part._parse-character)>
122
- ((rx (group " #\\ " (or " nul" " null"
123
- " backspace"
124
- " tab" " vtab"
125
- " newline" " linefeed"
126
- " page"
127
- " return"
128
- " space"
129
- " rubout"
130
- (** 3 3 (any (?0 . ?7 )))
131
- (seq ?u (** 1 4 hex-digit))
132
- (seq ?U (** 1 6 hex-digit))
133
- anything))
134
- (or (not alphabetic) eol))
135
- (1 " w" ))
136
- ; ; Treat "complex" reader literals as a single sexp for nav and
137
- ; ; indent, by also marking as prefix syntax the stuff after the #.
138
- ; ; Racket predefines reader literals like #"" #rx"" #px"" #hash()
139
- ; ; #hasheq() #fx3(0 1 2) #s() and so on. I think these -- plus any
140
- ; ; user defined reader extensions -- can all be covered with the
141
- ; ; following general rx. Also it seems sufficient to look for just
142
- ; ; the opening delimiter -- the ( [ { or " -- here.
143
- ((rx (not (any ?| ))
144
- (group ?#
145
- (?? (not (any ?| ; not comment #362
146
- ?: ; not keyword arg #448
147
- space ; not space #546
148
- ?\\ ))
149
- (*? (or (syntax symbol) (syntax word) (syntax punctuation)))))
150
- (any ?\" ?\( ?\[ ?\{ ))
151
- (1 " '" ))
152
- ; ; Syntax quoting
153
- ((rx ?# (or ?` ?' ?, ))
154
- (0 " '" ))
155
- ; ; Treat '|symbol with spaces| as word syntax
156
- ((rx ?' ?| (*? (not (any ?\" ?\r ?\n ))) ?| )
157
- (0 " w" ))
158
- ; ; Treat |identifier with spaces| -- but not #|comment|# -- as
159
- ; ; word syntax
160
- ((rx (not (any ?# ))
161
- (group ?| (*? (not (any ?\" ?\r ?\n ))) ?| ))
162
- (1 " w" )))
163
- (point )
164
- end))
165
+ (funcall racket--syntax-propertize-rules (point ) end))
165
166
166
167
(defun racket--syntax-propertize-open-here-string (start string eol )
167
168
" Determine the syntax of the \\ n after a #<<HERE
0 commit comments