Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 26, 2015 14:14
Show Gist options
  • Save SteveGilham/fbe5ca8d532dd7ac7e1b to your computer and use it in GitHub Desktop.
Save SteveGilham/fbe5ca8d532dd7ac7e1b to your computer and use it in GitHub Desktop.
Continuation based lexer (partial)
type LispLex = Bra | Ket | Dot | Str of string | Num of int | Symbol of string
let alpha c = ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))
let digit c = (c >= '0') && (c <= '9')
let eqChar c c' = c = c'
let l2s l = String(List.toArray l)
let ( ^| ) p q = fun x -> (p x) || (q x)
// Read a symbol from the input
let readSymbol s char g =
(lexGetChar s, alpha ^| digit ^| eqChar '_') ^*
(fun l ->
fun opt ->
lexPutLexeme s (Symbol (l2s ([char]@l))) (g opt));;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment