Skip to content

Commit 248e4e8

Browse files
authored
Add prefixed code blocks to #lang resyntax/test (#598)
1 parent 9006e96 commit 248e4e8

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

test.rkt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,14 @@
327327

328328
(define-syntax-class multi-line-code-block-tag
329329
(pattern
330-
(~or #:standalone-code-block #:starting-code-block #:middle-code-block #:ending-code-block)))
330+
(~or #:standalone-code-block
331+
#:prefixed-standalone-code-block
332+
#:first-code-block
333+
#:middle-code-block
334+
#:last-code-block
335+
#:prefixed-first-code-block
336+
#:prefixed-middle-code-block
337+
#:prefixed-last-code-block)))
331338

332339

333340
(define (join-multiline-code-blocks stx)

test/private/grammar.rkt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ option: /AT-SIGN IDENTIFIER expression
88

99
@expression: code-line
1010
| standalone-code-block
11+
| prefixed-standalone-code-block
1112
| range-set
1213
| IDENTIFIER
1314
| LITERAL-STRING
@@ -16,12 +17,21 @@ option: /AT-SIGN IDENTIFIER expression
1617

1718
code-line: /SINGLE-DASH CODE-LINE
1819
standalone-code-block: /DASH-LINE CODE-LINE* /DASH-LINE
20+
prefixed-standalone-code-block: /PIPE-DASH-LINE (/PIPE-SPACE CODE-LINE)* /PIPE-DASH-LINE
1921

2022

21-
@code-block-sequence: starting-code-block middle-code-block* ending-code-block+
22-
starting-code-block: /DASH-LINE CODE-LINE* /EQUALS-LINE
23+
@code-block-sequence: first-code-block middle-code-block* last-code-block+
24+
| prefixed-first-code-block prefixed-middle-code-block* prefixed-last-code-block+
25+
26+
27+
first-code-block: /DASH-LINE CODE-LINE* /EQUALS-LINE
2328
middle-code-block: CODE-LINE* /EQUALS-LINE
24-
ending-code-block: CODE-LINE* /DASH-LINE
29+
last-code-block: CODE-LINE* /DASH-LINE
30+
31+
32+
prefixed-first-code-block: /PIPE-DASH-LINE (/PIPE-SPACE CODE-LINE)* /PIPE-EQUALS-LINE
33+
prefixed-middle-code-block: (/PIPE-SPACE CODE-LINE)* /PIPE-EQUALS-LINE
34+
prefixed-last-code-block: (/PIPE-SPACE CODE-LINE)* /PIPE-DASH-LINE
2535

2636

2737
range-set: line-range (/COMMA line-range)*

test/private/tokenizer.rkt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
(define-lex-abbrev dash-line (concatenation (repetition 3 +inf.0 #\-) #\newline))
3131
(define-lex-abbrev equals-line (concatenation (repetition 3 +inf.0 #\=) #\newline))
32+
(define-lex-abbrev pipe-dash-line (concatenation "|" dash-line))
33+
(define-lex-abbrev pipe-equals-line (concatenation "|" equals-line))
3234

3335

3436
(define-lex-abbrev refactoring-test-code-block
@@ -55,12 +57,20 @@
5557
(repetition 0 +inf.0 (union alphabetic numeric (char-set "-/")))))
5658

5759

58-
(define-tokens refactoring-test-tokens
59-
(IDENTIFIER LITERAL-STRING LITERAL-INTEGER CODE-LINE))
60+
(define-tokens refactoring-test-tokens (IDENTIFIER LITERAL-STRING LITERAL-INTEGER CODE-LINE))
6061

6162

6263
(define-empty-tokens empty-refactoring-test-tokens
63-
(COLON AT-SIGN DOUBLE-DOT COMMA SINGLE-DASH DASH-LINE EQUALS-LINE))
64+
(COLON
65+
AT-SIGN
66+
DOUBLE-DOT
67+
COMMA
68+
SINGLE-DASH
69+
DASH-LINE
70+
EQUALS-LINE
71+
PIPE-DASH-LINE
72+
PIPE-EQUALS-LINE
73+
PIPE-SPACE))
6474

6575

6676
(define (string-lines str)
@@ -85,6 +95,10 @@
8595
(let ()
8696
(set! active-lexer multi-code-line-lexer)
8797
(token-DASH-LINE))]
98+
[pipe-dash-line
99+
(let ()
100+
(set! active-lexer pipe-prefix-lexer)
101+
(token-PIPE-DASH-LINE))]
88102
[refactoring-test-literal-string
89103
(token-LITERAL-STRING
90104
(string->immutable-string (substring lexeme 1 (sub1 (string-length lexeme)))))]
@@ -108,6 +122,25 @@
108122
(token-DASH-LINE))]
109123
[equals-line (token-EQUALS-LINE)]))
110124

125+
(define pipe-prefix-lexer
126+
(lexer-src-pos
127+
["| "
128+
(let ()
129+
(set! active-lexer pipe-code-line-lexer)
130+
(token-PIPE-SPACE))]
131+
[pipe-dash-line
132+
(let ()
133+
(set! active-lexer initial-lexer)
134+
(token-PIPE-DASH-LINE))]
135+
[pipe-equals-line (token-PIPE-EQUALS-LINE)]))
136+
137+
(define pipe-code-line-lexer
138+
(lexer-src-pos
139+
[rest-of-line
140+
(let ()
141+
(set! active-lexer pipe-prefix-lexer)
142+
(token-CODE-LINE lexeme))]))
143+
111144
(define active-lexer initial-lexer)
112145

113146
(λ () (active-lexer port)))

test/testing-lang-test.rkt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#lang resyntax/test
2+
3+
4+
header: - #lang resyntax/test
5+
6+
7+
test: "unnecessary multi-line code blocks in tests refactorable to single-line code blocks"
8+
|-------------------
9+
| test: "foo"
10+
| ------------------
11+
| (and a (and b c))
12+
| ==================
13+
| (and a b c)
14+
| ------------------
15+
|===================
16+
| test: "foo"
17+
| ------------------
18+
| (and a (and b c))
19+
| ------------------
20+
| ------------------
21+
| (and a b c)
22+
| ------------------
23+
|===================
24+
| test: "foo"
25+
| - (and a (and b c))
26+
| - (and a b c)
27+
|-------------------

0 commit comments

Comments
 (0)