Image Unit Processing Interface. INFO: This is a mirror from GitHub. github.com/sona-tau/iupi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Removed file artifacts created by drracket

+1 -148
+1
.gitignore
··· 1 + *.rkt~
-71
src/combinators.rkt~
··· 1 - #lang plait 2 - (require "utilities.rkt") 3 - (require "types.rkt") 4 - 5 - ;----- Parser 'a applicative -----; 6 - ; The following applicative implementations for (Parser 'a) were taken 7 - ; from the prelude implementation of haskell at: 8 - ; https://hackage.haskell.org/package/base-4.19.1.0/docs/src/GHC.Base.html 9 - ; Creates a parser that parses (x) regardless of input 10 - (define (pure [x : 'a]) : (Parser 'a) 11 - (λ (input) 12 - (ok (pair input x)))) 13 - 14 - ; Creates a parser out of two parsers that will sequence the application of the 15 - ; first parser with the second parser. First it parses the same input with both 16 - ; parsers then applies the function contained within the first parser to the 17 - ; parsed result of the second parser. This is usually referred to as <*> in 18 - ; Haskell. 19 - (define (seq-ap [p1 : (Parser ('a -> 'b))] [p2 : (Parser 'a)]) : (Parser 'b) 20 - (λ (input) 21 - (type-case (ParseResult ('a -> 'b)) (p1 input) 22 - [(ok f) (do (p2 input) 23 - (λ (y) (p-result (fst y) ((snd f) (snd y)))))] 24 - [(err) (err)]))) 25 - 26 - ;----- Parser Combinators -----; 27 - ; Creates a parser that runs the entire list of parsers through an input and 28 - ; returns an (ok) variant if any of them succeed 29 - (define (or/p [ps : (Listof (Parser 'a))]) : (Parser 'a) 30 - (λ (input) 31 - (let ([res1 ((first ps) input)]) 32 - (foldr alt res1 (map (λ (p) (p input)) (rest ps)))))) 33 - 34 - ; Creates a parser out of two parsers that will sequence them. 35 - (define (seq/p [p1 : (Parser 'a)] [p2 : (Parser 'b)]) : (Parser ('a * 'b)) 36 - (λ (input) (do (p1 input) 37 - (λ (res1) (do (p2 (fst res1)) 38 - (λ (res2) (p-result (fst res2) (pair (snd res1) (snd res2))))))))) 39 - 40 - ; Creates a parser that parses either (p1) or (p2) 41 - (define (alt/p [p1 : (Parser 'a)] [p2 : (Parser 'a)]) : (Parser 'a) 42 - (λ (input) (alt (p1 input) (p2 input)))) 43 - 44 - ; Creates a parser that will parse the input 0 or more times. Like using "*" in 45 - ; a RegEx. 46 - (define (many/p [p : (Parser 'a)]) : (Parser (Listof 'a)) 47 - (alt/p (many1/p p) (pure '()))) 48 - 49 - ; Creates a parser that parses the input 1 or more times. Like using "+" in a 50 - ; RegEx. 51 - (define (many1/p [p : (Parser 'a)]) : (Parser (Listof 'a)) 52 - (λ (input) (type-case (ParseResult 'a) (p input) 53 - [(ok first) (type-case (ParseResult (Listof 'a)) ((many/p p) (fst first)) 54 - [(ok rest) (ok (pair (fst rest) (append (list (snd first)) (snd rest))))] 55 - [(err) (err)])] 56 - [(err) (err)]))) 57 - 58 - ; Creates a parser out of two parsers that sequentially applies them. But will 59 - ; only return the result of the first parser with the rest of the input from the 60 - ; second parser. 61 - (define (left/p [l : (Parser 'a)] [r : (Parser 'b)]) : (Parser 'a) 62 - (λ (input) (do (l input) 63 - (λ (result1) (do (r (fst result1)) 64 - (λ (result2) (p-result (fst result2) (snd result1)))))))) 65 - 66 - ; Creates a parser out of two parsers that sequentially applies them. But will 67 - ; only return the result of the second parser. 68 - (define (right/p [l : (Parser 'a)] [r : (Parser 'b)]) : (Parser 'b) 69 - (λ (input) (do (l input) 70 - (λ (result1) (do (r (fst result1)) 71 - (λ (result2) (ok result2)))))))
-45
src/main.rkt~
··· 1 - #lang plait 2 - 3 - (define (id x) x) 4 - 5 - (define-type U8 6 - [num (n : Number)] 7 - ) 8 - 9 - (define-type ImgOps 10 - [interpolate (f : Number)] 11 - [rotate-left] 12 - [rotate-right] 13 - [mirror] 14 - [transpose] 15 - [set (c : Color)] 16 - ) 17 - 18 - (define-type Color 19 - [hex-color (n : Number)] ;; TODO: Hex should turn a string of #FFA123 into a Number 20 - [int-color (n : Number)] 21 - ) 22 - 23 - (define-type NumOps 24 - [addR (n : Number)] 25 - [addL (n : Number)] 26 - ) 27 - 28 - (define-type Expr 29 - [img-op (op : ImgOps)] 30 - [num-op (op : NumOps)] 31 - ) 32 - 33 - (define (get-SetNum s) (map s-exp->number (s-exp->list s))) 34 - 35 - 36 - (define (parse e) 37 - [cond 38 - [(s-exp-match? `& e) (rotate-left)] 39 - [(s-exp-match? `(Number) e) (set (get-SetNum e))] 40 - [else (rotate-left)] 41 - ] 42 - ) 43 - 44 - (parse `&) 45 - (parse `(255))
src/parser.rkt~

This is a binary file and will not be displayed.

-32
src/types.rkt~
··· 1 - #lang plait 2 - ;----- Language Types -----; 3 - ; General Expression type 4 - (define-type Expr 5 - [operation (op : Operation)] 6 - [color (c : Color)]) 7 - 8 - ; Operation type 9 - (define-type Operation 10 - [add (color : Color) (e : Expr)] 11 - [subtract (color : Color) (e : Expr)] 12 - [multiply (color : Color) (e : Expr)] 13 - [divide (color : Color) (e : Expr)] 14 - [value-invert (e : Expr)] 15 - [linear-invert (e : Expr)] 16 - [interpolate (color : Color) (e : Expr) (percent : Number)] 17 - [hue-shift (e : Expr) (shift : Number)] 18 - [max (color : Color) (e : Expr)] 19 - [min (color : Color) (e : Expr)]) 20 - 21 - ; Color type 22 - (define-type Color 23 - [rgb-color (red : Number) (green : Number) (blue : Number)] 24 - [grayscale-color (n : Number)]) 25 - 26 - ;----- Parser Types -----; 27 - (define-type (ParseResult 'a) 28 - [ok (r : (String * 'a))] 29 - [err]) 30 - 31 - (define-type-alias (Parser 'a) 32 - (String -> (ParseResult 'a)))
src/utilities.rkt~

This is a binary file and will not be displayed.