Skip to content

Commit 025ae97

Browse files
committed
strengthen the contract on lexer results
thanks to @LiberalArtist for finding this improvement
1 parent 7b0c37a commit 025ae97

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

syntax-color-doc/syntax-color/syntax-color.scrbl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ Parenthesis matching code built on top of @racket[token-tree%].
8787
This function raises an error unless the following boolean
8888
expression is true:
8989
@racketblock[(or (equal? type 'eof)
90-
(and (<= pos-before new-token-start pos-after)
91-
(<= pos-before new-token-end pos-after)))]
90+
(and (= pos-before new-token-start)
91+
(< new-token-start new-token-end)
92+
(= new-token-end pos-after)))]
9293
but it checks the individual parts of the expression to
9394
raise a more meaningful error message when some part is not
9495
true.

syntax-color-lib/syntax-color/lexer-contract.rkt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,16 @@
229229
(define (check-colorer-results-match-port-before-and-after
230230
who type pos-before new-token-start new-token-end pos-after)
231231
(unless (equal? 'eof type)
232-
(unless (<= pos-before new-token-start pos-after)
232+
(unless (= pos-before new-token-start)
233233
(error who
234-
"expected the token start to be between ~s and ~s, got ~s"
235-
pos-before pos-after new-token-start))
236-
(unless (<= pos-before new-token-end pos-after)
234+
"token start expected to match port position before reading\n token-start: ~e\n port-position: ~s"
235+
new-token-start pos-before))
236+
(unless (= pos-after new-token-end)
237237
(error who
238-
"expected the token end to be between ~s and ~s, got ~s"
239-
pos-before pos-after new-token-end))))
238+
"token end expected to match port position afterwards\n token-end: ~e\n port-position: ~s"
239+
"expected the token end to be ~s, got ~s"
240+
new-token-end pos-after))
241+
(unless (< new-token-start new-token-end)
242+
(error who
243+
"expected the token start to be strictly less than the token end\n token-start: ~e\n token-end: ~e"
244+
new-token-start new-token-end))))

syntax-color-test/tests/syntax-color/module-lexer.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
0
2323
mode))
2424
(define-values (_line2 _col2 pos-after) (port-next-location p))
25-
(unless (and (or (not token-start) (<= pos-before token-start pos-after))
26-
(or (not token-end) (<= pos-before token-end pos-after)))
25+
(unless (and (or (not token-start) (= pos-before token-start))
26+
(or (not token-end) (= token-end pos-after))
27+
(or (not token-start) (not token-end) (equal? type 'eof) (< token-start token-end)))
2728
(error 'lex
2829
(string-append
2930
"pos-before, pos-after, token-start, and token-end aren't in the right relationship\n"

0 commit comments

Comments
 (0)