Created
May 1, 2019 20:48
-
-
Save beckyconning/815290b3ad740f20e726c69dbb0dfc3c 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
module Main where | |
import Prelude | |
import Control.Alt ((<|>)) | |
import Control.Apply (lift2) | |
import Data.Array (catMaybes, fromFoldable) | |
import Data.List (List(..), many) | |
import Data.List as List | |
import Data.String.CodeUnits (fromCharArray) | |
import Effect (Effect) | |
import Effect.Console (log) | |
import Text.Parsing.Parser (ParserT, runParserT) | |
import Text.Parsing.Parser.Combinators (try, lookAhead, manyTill, optionMaybe) | |
import Text.Parsing.Parser.Combinators as PC | |
import Text.Parsing.Parser.String (anyChar, string) | |
data MoustacheToken = Open | Close | Character Char | |
instance showMoustacheToken :: Show MoustacheToken where | |
show Open = "Open" | |
show Close = "Close" | |
show (Character s) = "(Character " <> show s <> ")" | |
open :: forall m. Monad m => ParserT String m MoustacheToken | |
open = string "{{" $> Open | |
close :: forall m. Monad m => ParserT String m MoustacheToken | |
close = string "}}" $> Close | |
moustacheTokens :: forall m. Monad m => ParserT String m (List MoustacheToken) | |
moustacheTokens = many $ open <|> close <|> (Character <$> anyChar) | |
main :: Effect Unit | |
main = log <<< show =<< runParserT example1 moustacheTokens | |
example1 :: String | |
example1 = "{{hey}}yeah {{lets go}}" |
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
(Right (Open : (Character 'h') : (Character 'e') : (Character 'y') : Close : (Character 'y') : (Character 'e') : (Character 'a') : (Character 'h') : (Character ' ') : Open : (Character 'l') : (Character 'e') : (Character 't') : (Character 's') : (Character ' ') : (Character 'g') : (Character 'o') : Close : Nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment