Skip to content

Instantly share code, notes, and snippets.

@davidgrenier
Created October 8, 2012 15:27
Show Gist options
  • Save davidgrenier/3853115 to your computer and use it in GitHub Desktop.
Save davidgrenier/3853115 to your computer and use it in GitHub Desktop.
Recursive descent parser using F# Active Patterns compiled to JavaScript with WebSharper
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