-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse-test.rkt
45 lines (39 loc) · 1.23 KB
/
parse-test.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#lang racket/base
(require microparsec
racket/unit
(only-in racket/stream stream->list)
threading
smalltalk/reader
smalltalk/parse/block
smalltalk/parse/expr
smalltalk/parse/interface
smalltalk/parse/message
smalltalk/parse/method
smalltalk/parse/primary
smalltalk/parse/statement
smalltalk/parse/top-decl)
(define-values/invoke-unit/infer
(export st:statement^
st:method^
st:top-decl^)
(link default-st:block@
default-st:primary@
default-st:message@
default-st:expr@
default-st:statement@
default-st:method@
default-st:top-decl@))
(define (string->tokens s)
(~> (open-input-string s)
(in-port smalltalk-read _)
sequence->stream))
(define (p f s)
(define-values (parsed rest) (parse f (string->tokens s)))
(values parsed (stream->list rest)))
(module* parse-file #f
(call-with-input-file (vector-ref (current-command-line-arguments) 0)
(lambda (inp)
(port-count-lines! inp)
(parse st:top-decl/p (sequence->stream (in-port smalltalk-read inp))))))
(module* parse-string #f
(p st:code-body/p (vector-ref (current-command-line-arguments) 0)))