Created
February 1, 2013 06:49
-
-
Save PollRobots/4689812 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let parseExpression (grammar:Map<string,GrammarRule<'a>>) start (input:string) = | |
| let rec parse offset = function | |
| | Terminal x -> | |
| let e = offset + x.Length - 1 | |
| if e < input.Length && input.[offset..e] = x then (TerminalSymbol x, e + 1) else (Unmatched, offset) | |
| | TerminalOneOf x -> match currentCharacter input offset with | |
| | Some c -> if x.Contains(c) then (TerminalSymbol c, offset + c.Length) else (Unmatched, offset) | |
| | None -> (Unmatched, offset) | |
| | TerminalWildcard -> match currentCharacter input offset with | |
| | Some c -> (TerminalSymbol c, offset + c.Length) | |
| | None -> (Unmatched, offset) | |
| | TerminalUnicode x -> match currentCharacter input offset with | |
| | Some c -> if Char.GetUnicodeCategory(c, 0) = x then (TerminalSymbol c, offset + c.Length) else (Unmatched, offset) | |
| | None -> (Unmatched, offset) | |
| | NonTerminal x -> | |
| let rule = grammar.[x] | |
| // . | |
| // . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment