In this tutorial we're going to build a set of parser combinators.
We'll answer the above question in 2 steps.
- What is a parser?
- and, what is a parser combinator?
So first question: What is parser?
| type Json = | |
| | Null | |
| | Bool of bool | |
| | Number of float | |
| | String of string | |
| | Array of Json list | |
| | Object of (string * Json) list | |
| type Bracket = Open | Close |
| > let alpha = set['a'..'z'] + set['A'..'Z'];; | |
| > let num = set['0'..'9'];; | |
| > let alphanum = alpha + num;; | |
| > let (|Char|_|) alphabet = function | |
| | c::cs when Set.contains c alphabet -> Some(c, cs) | |
| | _ -> None;; |
| { | |
| open Parse | |
| open Lexing | |
| let ident = function | |
| | "let" -> LET | |
| | "rec" -> REC | |
| | "in" -> IN | |
| | "fun" -> FUN | |
| | "if" -> IF | |
| | "then" -> THEN |
| > let pInt : Parser<_, unit> = puint32 |>> int .>> spaces;; | |
| > let str s = pstring s >>. spaces;; | |
| > let keywords = | |
| "if then else let rec in fun".Split ' ' | |
| |> set;; | |
| > let pIdent : Parser<_, unit> = |
| git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*\((.*?)\s*[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n |