Skip to content

Commit 3bbfad7

Browse files
committed
[parser] Add handling of block arguments.
1 parent dd6484e commit 3bbfad7

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

smalltalk-parser/parse/block.rkt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
racket/function
55
racket/unit
66
smalltalk/reader
7+
(submod smalltalk/reader for-pipes)
78
"interface.rkt"
89
"util.rkt")
910

@@ -14,7 +15,12 @@
1415
(export st:block^)
1516

1617
(define st:block-args/p
17-
(return/p null))
18+
(or/p (do/p [args <- (many1/p st:block-argument/p)]
19+
(or/p st:pipe/p
20+
(do/p [p <- st:double-pipe/p]
21+
(push/p (binary-selector (token-srcloc p) '\|))))
22+
(return/p args))
23+
(return/p null)))
1824

1925
(define (make-block-stx lb rb args temps body)
2026
(quasisyntax/loc (build-source-location lb rb args temps body)

smalltalk-parser/parse/util.rkt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@
2323
(define st:binary-selector/p
2424
(token->syntax/p (satisfy/p binary-selector?)))
2525

26+
(define st:block-argument/p
27+
(token->syntax/p (satisfy/p block-argument?)))
28+
2629
(define (st:delimiter/p type)
2730
(~> (conjoin
2831
delimiter?
2932
(lambda~> token-value (eq? type)))
3033
satisfy/p
3134
token->syntax/p))
3235

33-
(define st:pipe/p
36+
(define/p st:pipe/p
3437
(satisfy/p (conjoin
35-
binary-selector?
36-
(lambda (tok)
37-
(eq? '\| (token-value tok))))))
38+
binary-selector?
39+
(lambda (tok)
40+
(eq? '\| (token-value tok))))))
3841

39-
(define st:double-pipe/p
42+
(define/p st:double-pipe/p
4043
(satisfy/p (conjoin
41-
binary-selector?
42-
(lambda (tok)
43-
(eq? '\|\| (token-value tok))))))
44+
binary-selector?
45+
(lambda (tok)
46+
(eq? '\|\| (token-value tok))))))
4447

4548
(define (st:opener/p s)
4649
(~> (conjoin

smalltalk-reader/reader.rkt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
opener?
2020
closer?)
2121

22+
;; The pipe (vertical bar) character is part of the structural syntax and also
23+
;; an binary message selector. Ideally the constructor should be private to the
24+
;; tokenizer, but it is provided here from a submodule because it is needed so the
25+
;; parser can synthesize and inject a token when handling the parsing of blocks.
26+
;; This is not part of the public interface, and could disappear if a better
27+
;; solution is found.
28+
(module* for-pipes #f (provide binary-selector))
29+
2230
(require racket/match
2331
(prefix-in - syntax/readerr)
2432
syntax/srcloc

0 commit comments

Comments
 (0)