1
1
mirror of https://github.com/github/semantic.git synced 2024-11-30 14:47:30 +03:00
semantic/Doubt/Lambda.swift
2015-07-18 15:43:49 -04:00

10 lines
444 B
Swift

let word = ^("abcdefghijklmnopqrstuvwxyz".characters.map { String($0) })
let ws = ^" "
let term: String -> State<Fix>? = fix { term in
let variable = Syntax<Fix>.Variable <^> word
let application = Syntax.Apply <^> (^"(" *> ws* *> term <*> (ws *> term)* <* ws* <* ^")")
let abstraction = Syntax.Abstract <^> (^"λ" *> ws* *> interpolate(term, ws) <*> (ws* *> ^"." *> term))
return Fix.init <^> (abstraction <|> application <|> variable)
}