Created
October 8, 2012 15:27
-
-
Save davidgrenier/3853115 to your computer and use it in GitHub Desktop.
Recursive descent parser using F# Active Patterns compiled to JavaScript with WebSharper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open IntelliFactory.WebSharper | |
open IntelliFactory.WebSharper.Html | |
open Server.Tonys | |
[<JavaScript>] | |
let string chars = System.String (chars |> List.rev |> List.toArray) | |
[<JavaScript>] | |
let rec (|Eval|) = function | |
| Normal (c :: rest) -> | |
let rec aux acc = function | |
| Normal (c :: rest) -> aux (c :: acc) rest | |
| Quote rest | rest -> | |
let (Eval result) = rest | |
P [string acc |> Text] :: result | |
aux [c] rest | |
| Quote (_ :: rest) -> | |
let rec aux acc = function | |
| Normal (c :: rest) -> aux (c :: acc) rest | |
| Quote (_ :: rest) | rest -> | |
let (Eval result) = rest | |
BlockQuote [string acc |> Text] :: result | |
aux [] rest | |
| _ -> [] | |
and [<JavaScript>] (|Normal|Quote|) = function | |
| '"' :: _ as rest -> Quote rest | |
| rest -> Normal rest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment