mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-26 13:11:30 +03:00
24 lines
578 B
Idris
24 lines
578 B
Idris
import Text.Lexer
|
|
|
|
data Kind = Ignore | Ident | Oper | Number
|
|
|
|
ignore : WithBounds (Token Kind) -> Bool
|
|
ignore (MkBounded (Tok Ignore _) _ _) = True
|
|
ignore _ = False
|
|
|
|
tmap : TokenMap (Token Kind)
|
|
tmap = [
|
|
(alpha <+> many alphaNum, Tok Ident),
|
|
(some digit, Tok Number),
|
|
(some symbol, Tok Oper),
|
|
(spaces, Tok Ignore)
|
|
]
|
|
|
|
show : WithBounds (Token Kind) -> String
|
|
show t@(MkBounded (Tok _ v) _ _) = "\{show $ start t} \{show v}"
|
|
|
|
main : IO ()
|
|
main = do
|
|
let toks = filter (not . ignore) $ fst $ lex tmap "let x = 1\n y = 2\n in x + y"
|
|
traverse_ (putStrLn . show) toks
|