-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '7dc4fb60390218b09bc351062eeede7dcdbb4d9f'
- Loading branch information
Showing
19 changed files
with
15,740 additions
and
14,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
vendored_parsers/tree-sitter-racket/corpus/here_string/.gitattributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
win_* text eol=crlf | ||
win_* eol=crlf | ||
* eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# fuzz test | ||
|
||
The directory contains the scripts that test the implementation to avoid the problem that a symbol is parsed as a number or vice versa. | ||
|
||
## Resource | ||
|
||
* ~6 minutes to run | ||
* ~300M generated files | ||
|
||
## Run | ||
|
||
```shell | ||
$ cd fuzztest | ||
# 30s | ||
$ racket gen_cases.rkt | ||
cpu time: 26531 real time: 26835 gc time: 1069 | ||
5114173 cases generated | ||
$ cd .. | ||
$ tree-sitter generate | ||
# 3 minutes | ||
$ tree-sitter parse fuzztest/case.txt > fuzztest/res1.txt | ||
# 2 minutes | ||
$ cd fuzztest && racket postprocess.rkt | ||
# should show nothing | ||
$ sdiff -s <(cat -n expect.txt) <(cat -n res.txt) | ||
|
||
# If there is some error, run | ||
$ sdiff -s <(cat -n expect.txt) <(cat -n res.txt) | less | ||
# then get the first error case at `N`-th line | ||
$ cat case.txt | sed -n 'Np' | ||
``` | ||
|
||
You can edit `gen_cases.rkt` to generate less cases during development. | ||
|
57 changes: 57 additions & 0 deletions
57
vendored_parsers/tree-sitter-racket/fuzztest/gen_cases.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#lang racket | ||
|
||
(require racket/extflonum) | ||
|
||
;; all characters that can appear in a valid number/exflonum | ||
;; remove some insignificant parts to improve performance | ||
;; (define alphabet-char "abdefilnost") | ||
(define alphabet-char "abdefilnostx") | ||
(define special-char "#./@+-") | ||
;; (define numeric-char "0123456789") | ||
(define numeric-char "0179") | ||
(define all-char | ||
(string-append alphabet-char | ||
special-char | ||
numeric-char)) | ||
|
||
(define cnt 0) | ||
(define max-len 5) | ||
|
||
(define case-port (open-output-file "case.txt" #:exists 'replace)) | ||
(define expect-port (open-output-file "expect.txt" #:exists 'replace)) | ||
|
||
(define (gen i case) | ||
(with-handlers ([exn:fail? (lambda _ (void))]) | ||
(when (> i 0) | ||
(define case-str (list->string case)) | ||
;; "[email protected]" should be a number according the document, | ||
;; but it's actually a symbol. | ||
;; It's a bug of Racket reader, and will fix in new Racket release. | ||
;; we skip these cases. | ||
(when (not (string-contains? case-str "@.")) | ||
(with-handlers ([exn:fail? void]) | ||
(with-input-from-string case-str | ||
(lambda () | ||
(define fst (read)) | ||
(define snd (read)) | ||
(when (eof-object? snd) | ||
(cond [(symbol? fst) | ||
(set! cnt (add1 cnt)) | ||
(displayln case-str case-port) | ||
(displayln "symbol" expect-port)] | ||
[(number? fst) | ||
(set! cnt (add1 cnt)) | ||
(displayln case-str case-port) | ||
(displayln "number" expect-port)] | ||
;; it's here for possible future change that | ||
;; split extflonum from number | ||
[(extflonum? fst) | ||
(set! cnt (add1 cnt)) | ||
(displayln case-str case-port) | ||
(displayln "number" expect-port)])))))))) | ||
(when (< i max-len) | ||
(for ([c all-char]) | ||
(gen (add1 i) (cons c case))))) | ||
|
||
(time (gen 0 '())) | ||
(displayln (format "~a cases generated" cnt)) |
26 changes: 26 additions & 0 deletions
26
vendored_parsers/tree-sitter-racket/fuzztest/postprocess.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#lang racket | ||
|
||
(define port (open-input-file "res1.txt")) | ||
(define all-result (drop (read port) 4)) | ||
(define all-result-line | ||
(for/list ([r all-result]) | ||
(cons (car r) (caadr r)))) | ||
(with-output-to-file "res.txt" | ||
#:exists 'replace | ||
(lambda () | ||
(let loop ([line 0] | ||
[firstline? #t] | ||
[lst all-result-line]) | ||
(match lst | ||
['() (void)] | ||
[(cons fst rem) | ||
#:when (= (cdr fst) line) | ||
(when (not firstline?) | ||
(display " ")) | ||
(display (car fst)) | ||
(loop line (if firstline? #t #f) rem)] | ||
[(cons fst rem) | ||
(newline) | ||
(display (car fst)) | ||
(loop (add1 line) #f rem)])) | ||
(newline))) |
Oops, something went wrong.