Created
February 19, 2021 12:23
-
-
Save algebraic-dev/e1ac7aa4c8696f53dc7333569fe22048 to your computer and use it in GitHub Desktop.
The problem
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 LexerTest | |
import Text.Lexer | |
import Data.List | |
data TokenKind =Sharp | |
Show TokenKind where | |
show Sharp = "#" | |
revertTokens : List TokenKind -> String | |
revertTokens (hd::tl) = | |
(foldl (\acc => \cur => acc ++ (show cur)) (show hd) tl) | |
revertTokens [] = "" | |
token_map : TokenMap TokenKind | |
token_map = [(is '#' ,\n => Sharp)] | |
lexMd : String -> Either (Int, Int) (List (TokenData TokenKind)) | |
lexMd str | |
= case lex token_map str of | |
(tokens, _, _, "") => Right tokens | |
(_, line, column, _) => Left $ (line, column) | |
fixTkns : (List TokenKind -> String) | |
-> Either (Int, Int) (List (TokenData TokenKind)) | |
-> String | |
fixTkns fn res = | |
case res of | |
Left x => "" | |
Right list => fn (map TokenData.tok list) | |
public export | |
simpleMd : String | |
simpleMd = "####" | |
simpleMdRes : String | |
simpleMdRes = (fixTkns revertTokens (lexMd simpleMd)) | |
simpleLex : simpleMdRes = simpleMd | |
simpleLex = Refl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment