Thank you for your comment

Beau­tiful Racket / racket school 2019

  1. (require brag/support) ; imports `lexer`

    (define (apply-port-proc proc str)
      (define ip (open-input-string str))
      (for/list ([tok (in-port proc ip)])
        tok))

    (define lex (lexer
                 ["fo" lexeme]
                 [(:: "f" (:+ "o")) 42]
                 [any-char (lex input-port)]))

    (apply-port-proc read "foobar")
    (apply-port-proc read-char "foobar")
    (apply-port-proc lex "foobar")
    (apply-port-proc lex "fobar")
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    (require brag/support) ; imports `lexer`
    
    (define (apply-port-proc proc str)
      (define ip (open-input-string str))
      (for/list ([tok (in-port proc ip)])
        tok))
    
    (define lex (lexer
                 ["fo" lexeme]
                 [(:: "f" (:+ "o")) 42]
                 [any-char (lex input-port)]))
    
    (apply-port-proc read "foobar")
    (apply-port-proc read-char "foobar")
    (apply-port-proc lex "foobar")
    (apply-port-proc lex "fobar")
    
    copy to clipboard
tacopocalypse/test.rkt
#lang tacopocalypse
##$%#$%#$#$#$$##$%#$%#$#$#$$##$%#$#$#$%#$$##$#$#$%#$%%$#%#$%#$#$%%$##$#$%%#$%%$##$#$%%#$%%$#%%%%#$%%$##$#$#$#$#$%#$$#%%%#$%%%$#%%%%#$%%$##$%#$#$%%%$##$#$%%#$%%$##$#$%#$#$%%$##$%#$#$#$%#$$##$%#$%#$#$#$$##$#$#$%#$%#$$#%%#$%#$%#$$##$#$#$#$#$%#$$#%#$#$#$%%#$$##$#$#$#$#$%#$$##$#$#$%#$%#$$##$%#$%#$%#$$##$#$#$#$#$%#$$##$%#$#$%%#$$##$#$#$#$#$%#$$##$#$#$%#$%#$$#%#$%%#$%#$$##$#$#$#$#$%#$$##$#$#$%%%%$#%#$#$%#$%#$$#%#$#$%#$%#$$#%#$#$%#$%#$$
1
2
#lang tacopocalypse
##$%#$%#$#$#$$##$%#$%#$#$#$$##$%#$#$#$%#$$##$#$#$%#$%%$#%#$%#$#$%%$##$#$%%#$%%$##$#$%%#$%%$#%%%%#$%%$##$#$#$#$#$%#$$#%%%#$%%%$#%%%%#$%%$##$%#$#$%%%$##$#$%%#$%%$##$#$%#$#$%%$##$%#$#$#$%#$$##$%#$%#$#$#$$##$#$#$%#$%#$$#%%#$%#$%#$$##$#$#$#$#$%#$$#%#$#$#$%%#$$##$#$#$#$#$%#$$##$#$#$%#$%#$$##$%#$%#$%#$$##$#$#$#$#$%#$$##$%#$#$%%#$$##$#$#$#$#$%#$$##$#$#$%#$%#$$#%#$%%#$%#$$##$#$#$#$#$%#$$##$#$#$%%%%$#%#$#$%#$%#$$#%#$#$%#$%#$$#%#$#$%#$%#$$
copy to clipboard
tacopocalypse/main.rkt
#lang br/quicklang
(require brag/support) ; imports `lexer`

(module+ reader
  (provide read-syntax))

(define lex
  (lexer
   ;; ···
   ))

(define (tokenize ip)
  (for/list ([tok (in-port lex ip)])
    tok))

(define (parse src toks)
  ;; ···
  )

(define (read-syntax src ip)
  (define toks (tokenize ip))
  (define parse-tree (parse src toks))
  (strip-bindings
   (with-syntax ([PT parse-tree])
     #'(module taco-mod tacopocalypse
         PT))))

(define-macro (my-module-begin PT)
  #'(#%module-begin
     (display (list->string 'PT))))
(provide (rename-out [my-module-begin #%module-begin]))
 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
#lang br/quicklang
(require brag/support) ; imports `lexer`

(module+ reader
  (provide read-syntax))

(define lex
  (lexer
   ;; ···
   ))

(define (tokenize ip)
  (for/list ([tok (in-port lex ip)])
    tok))

(define (parse src toks)
  ;; ···
  )

(define (read-syntax src ip)
  (define toks (tokenize ip))
  (define parse-tree (parse src toks))
  (strip-bindings
   (with-syntax ([PT parse-tree])
     #'(module taco-mod tacopocalypse
         PT))))

(define-macro (my-module-begin PT)
  #'(#%module-begin
     (display (list->string 'PT))))
(provide (rename-out [my-module-begin #%module-begin]))
copy to clipboard
← prev next →