Created
          July 15, 2011 11:21 
        
      - 
      
- 
        Save palladin/1084511 to your computer and use it in GitHub Desktop. 
    Functional style Regex engine
  
        
  
    
      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 char c (s : string) = seq { if s.Length > 0 && s.[0] = c then yield s.Substring(1) } | |
| let (=>) l r s = seq { for sl in l s do for sr in r sl -> sr } | |
| let (<|>) l r s = seq { yield! l s; yield! r s } | |
| let rec (<*>) e s = seq { yield s; yield! (e => (<*>) e) s } | |
| let (<+>) e = e => (<*>) e | |
| // example c(a|d)+r | |
| let pattern = char 'c' => (<+>) (char 'a' <|> char 'd') => char 'r' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment