Advertisement
Guest User

Untitled

a guest
May 10th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.45 KB | None | 0 0
  1. #lang racket
  2.  
  3. (provide add-active-token def-active-token process-string)
  4.  
  5. (struct activeToken(tokenString function))
  6. (define activeTokenList '())
  7.  
  8. (define (string-after-newline str)
  9.   (println "STRING AFTER NEWLINE")
  10. (match (regexp-match-positions "\n" str)
  11. ((list (cons start end)) (substring str end))
  12. (else "")))
  13.  
  14. (define (add-active-token token func)
  15.   (let* ([a (activeToken token func)])
  16.     (set! activeTokenList (cons a activeTokenList)))
  17.   )
  18.  
  19.  
  20. (add-active-token ";;" string-after-newline)
  21. (add-active-token "//" string-after-newline)
  22.  
  23.  
  24. (define-syntax-rule (def-active-token string (args) body)
  25.   (println "bb"))
  26.  
  27. (def-active-token ";;" (str)
  28. (or (for/or ((c (in-string str))
  29. (i (in-naturals)))
  30. (and (char=? c #\newline)
  31. (substring str (+ i 1))))
  32. ""))
  33.  
  34. (define (process-string string)
  35.   ;(println "PROCESS")
  36.   ;(println string)
  37.   (for ([token activeTokenList])
  38.     (match (regexp-match-positions (activeToken-tokenString token) string)
  39.       ((list (cons start end))
  40.       ; (set! string (string-append (substring string 0 start) ((activeToken-function token) (substring string end)))))
  41.         (set! string (string-append (substring string 0 start) ((activeToken-function token) (substring string end))))
  42.         (process-string string))
  43.       ;(println ((activeToken-function token) string)))
  44.       (else ""))
  45.     )
  46.  (string-append "" string)
  47. )
  48.  
  49. (process-string "jal\n//l\n//kk")
  50.  
  51.  
  52. (for ([i activeTokenList]) (print i))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement