less prototype, less bad code implementation of CCHM type theory
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1020 B

  1. {
  2. module Presyntax.Lexer where
  3. import qualified Data.ByteString.Lazy as Lbs
  4. import qualified Data.Text.Encoding as T
  5. import qualified Data.ByteString as Sbs
  6. import Presyntax.Tokens
  7. }
  8. %wrapper "monad-bytestring"
  9. $alpha = [a-zA-Z]
  10. $digit = [0-9]
  11. tokens :-
  12. $white+ ;
  13. $alpha [$alpha $digit \_ \']* { yield TokVar }
  14. \= { always TokEqual }
  15. \: { always TokColon }
  16. \\ { always TokLambda }
  17. "->" { always TokArrow }
  18. \( { always TokOParen }
  19. \{ { always TokOBrace }
  20. \) { always TokCParen }
  21. \} { always TokCBrace }
  22. {
  23. alexEOF :: Alex Token
  24. alexEOF = do
  25. (AlexPn _ l c, _, _, _) <- alexGetInput
  26. pure $ Token TokEof l c
  27. yield k t@(AlexPn _ l c, _, s, _) i = pure (Token (k $! (T.decodeUtf8 (Lbs.toStrict (Lbs.take i s)))) l c)
  28. always k x i = yield (const k) x i
  29. }