cryptol-2.4.0: Cryptol: The Language of Cryptography

Copyright | (c) 2013-2016 Galois Inc.
License | BSD3
Maintainer | cryptol@galois.com
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell98

Cryptol.Parser.Lexer

Description

At present Alex generates code with too many warnings.

Synopsis

- primLexer :: Config -> Text -> ([Located Token], Position)
- lexer :: Config -> Text -> ([Located Token], Position)
- data Layout
  - = Layout
  - | NoLayout
- data Token = Token {
  - tokenType :: TokenT
  - tokenText :: Text
  }
- data TokenT
  - = Num Integer Int Int
  - | ChrLit Char
  - | Ident [Text] Text
  - | StrLit String
  - | KW TokenKW
  - | Op TokenOp
  - | Sym TokenSym
  - | Virt TokenV
  - | White TokenW
  - | Err TokenErr
  - | EOF
- data TokenV
  - = VCurlyL
  - | VCurlyR
  - | VSemi
- data TokenKW
  - = KW_Arith
  - | KW_Bit
  - | KW_Cmp
  - | KW_else
  - | KW_Eq
  - | KW_extern
  - | KW_fin
  - | KW_if
  - | KW_private
  - | KW_include
  - | KW_inf
  - | KW_lg2
  - | KW_lengthFromThen
  - | KW_lengthFromThenTo
  - | KW_max
  - | KW_min
  - | KW_module
  - | KW_newtype
  - | KW_pragma
  - | KW_property
  - | KW_then
  - | KW_type
  - | KW_where
  - | KW_let
  - | KW_x
  - | KW_import
  - | KW_as
  - | KW_hiding
  - | KW_infixl
  - | KW_infixr
  - | KW_infix
  - | KW_primitive
- data TokenErr
  - = UnterminatedComment
  - | UnterminatedString
  - | UnterminatedChar
  - | InvalidString
  - | InvalidChar
  - | LexicalError
- data TokenSym
  - = Bar
  - | ArrL
  - | ArrR
  - | FatArrR
  - | Lambda
  - | EqDef
  - | Comma
  - | Semi
  - | Dot
  - | DotDot
  - | DotDotDot
  - | Colon
  - | BackTick
  - | ParenL
  - | ParenR
  - | BracketL
  - | BracketR
  - | CurlyL
  - | CurlyR
  - | TriL
  - | TriR
  - | Underscore
- data TokenW
  - = BlockComment
  - | LineComment
  - | Space
  - | DocStr
- data Located a = Located {
  - srcRange :: !Range
  - thing :: a
  }
- data Config = Config {
  - cfgSource :: !FilePath
  - cfgLayout :: !Layout
  - cfgPreProc :: PreProc
  - cfgAutoInclude :: [FilePath]
  - cfgModuleScope :: Bool
  }
- defaultConfig :: Config

# Documentation

primLexer :: Config -> Text -> ([Located Token], Position) Source #

Returns the tokens and the last position of the input that we processed. The tokens include whte space tokens.

lexer :: Config -> Text -> ([Located Token], Position) Source #

Returns the tokens in the last position of the input that we processed. White space is removed, and layout processing is done as requested. This stream is fed to the parser.

data Layout Source #

Constructors

Layout |
NoLayout |

data Token Source #

Constructors

Token |

Fields

- tokenType :: TokenT
- tokenText :: Text

Instances

Show Token Source # |
Methods showsPrec :: Int -> Token -> ShowS # show :: Token -> String # showList :: [Token] -> ShowS #
Generic Token Source # |
Associated Types type Rep Token :: * -> * # Methods from :: Token -> Rep Token x # to :: Rep Token x -> Token #
NFData Token Source # |
Methods rnf :: Token -> () #
PP Token Source # |
Methods ppPrec :: Int -> Token -> Doc Source #
type Rep Token Source # |
type Rep Token = D1 (MetaData "Token" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) (C1 (MetaCons "Token" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "tokenType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 TokenT)) (S1 (MetaSel (Just Symbol "tokenText") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))))

data TokenT Source #

Constructors

Num Integer Int Int | value, base, number of digits
ChrLit Char | character literal
Ident [Text] Text | (qualified) identifier
StrLit String | string literal
KW TokenKW | keyword
Op TokenOp | operator
Sym TokenSym | symbol
Virt TokenV | virtual token (for layout)
White TokenW | white space token
Err TokenErr | error token
EOF |

Instances

Eq TokenT Source # |
Methods (==) :: TokenT -> TokenT -> Bool # (/=) :: TokenT -> TokenT -> Bool #
Show TokenT Source # |
Methods showsPrec :: Int -> TokenT -> ShowS # show :: TokenT -> String # showList :: [TokenT] -> ShowS #
Generic TokenT Source # |
Associated Types type Rep TokenT :: * -> * # Methods from :: TokenT -> Rep TokenT x # to :: Rep TokenT x -> TokenT #
NFData TokenT Source # |
Methods rnf :: TokenT -> () #
type Rep TokenT Source # |
type Rep TokenT

data TokenV Source #

Virtual tokens, inserted by layout processing.

Constructors

VCurlyL |
VCurlyR |
VSemi |

Instances

Eq TokenV Source # |
Methods (==) :: TokenV -> TokenV -> Bool # (/=) :: TokenV -> TokenV -> Bool #
Show TokenV Source # |
Methods showsPrec :: Int -> TokenV -> ShowS # show :: TokenV -> String # showList :: [TokenV] -> ShowS #
Generic TokenV Source # |
Associated Types type Rep TokenV :: * -> * # Methods from :: TokenV -> Rep TokenV x # to :: Rep TokenV x -> TokenV #
NFData TokenV Source # |
Methods rnf :: TokenV -> () #
type Rep TokenV Source # |
type Rep TokenV = D1 (MetaData "TokenV" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) ((:+:) (C1 (MetaCons "VCurlyL" PrefixI False) U1) ((:+:) (C1 (MetaCons "VCurlyR" PrefixI False) U1) (C1 (MetaCons "VSemi" PrefixI False) U1)))

data TokenKW Source #

Constructors

KW_Arith |
KW_Bit |
KW_Cmp |
KW_else |
KW_Eq |
KW_extern |
KW_fin |
KW_if |
KW_private |
KW_include |
KW_inf |
KW_lg2 |
KW_lengthFromThen |
KW_lengthFromThenTo |
KW_max |
KW_min |
KW_module |
KW_newtype |
KW_pragma |
KW_property |
KW_then |
KW_type |
KW_where |
KW_let |
KW_x |
KW_import |
KW_as |
KW_hiding |
KW_infixl |
KW_infixr |
KW_infix |
KW_primitive |

Instances

Eq TokenKW Source # |
Methods (==) :: TokenKW -> TokenKW -> Bool # (/=) :: TokenKW -> TokenKW -> Bool #
Show TokenKW Source # |
Methods showsPrec :: Int -> TokenKW -> ShowS # show :: TokenKW -> String # showList :: [TokenKW] -> ShowS #
Generic TokenKW Source # |
Associated Types type Rep TokenKW :: * -> * # Methods from :: TokenKW -> Rep TokenKW x # to :: Rep TokenKW x -> TokenKW #
NFData TokenKW Source # |
Methods rnf :: TokenKW -> () #
type Rep TokenKW Source # |

type Rep TokenKW = D1 (MetaData "TokenKW" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) ((:+:) ((:+:) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "KW_Arith" PrefixI False) U1) (C1 (MetaCons "KW_Bit" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_Cmp" PrefixI False) U1) (C1 (MetaCons "KW_else" PrefixI False) U1))) ((:+:) ((:+:) (C1 (MetaCons "KW_Eq" PrefixI False) U1) (C1 (MetaCons "KW_extern" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_fin" PrefixI False) U1) (C1 (MetaCons "KW_if" PrefixI False) U1)))) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "KW_private" PrefixI False) U1) (C1 (MetaCons "KW_include" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_inf" PrefixI False) U1) (C1 (MetaCons "KW_lg2" PrefixI False) U1))) ((:+:) ((:+:) (C1 (MetaCons "KW_lengthFromThen" PrefixI False) U1) (C1 (MetaCons "KW_lengthFromThenTo" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_max" PrefixI False) U1) (C1 (MetaCons "KW_min" PrefixI False) U1))))) ((:+:) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "KW_module" PrefixI False) U1) (C1 (MetaCons "KW_newtype" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_pragma" PrefixI False) U1) (C1 (MetaCons "KW_property" PrefixI False) U1))) ((:+:) ((:+:) (C1 (MetaCons "KW_then" PrefixI False) U1) (C1 (MetaCons "KW_type" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_where" PrefixI False) U1) (C1 (MetaCons "KW_let" PrefixI False) U1)))) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "KW_x" PrefixI False) U1) (C1 (MetaCons "KW_import" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_as" PrefixI False) U1) (C1 (MetaCons "KW_hiding" PrefixI False) U1))) ((:+:) ((:+:) (C1 (MetaCons "KW_infixl" PrefixI False) U1) (C1 (MetaCons "KW_infixr" PrefixI False) U1)) ((:+:) (C1 (MetaCons "KW_infix" PrefixI False) U1) (C1 (MetaCons "KW_primitive" PrefixI False) U1))))))

data TokenErr Source #

Constructors

UnterminatedComment |
UnterminatedString |
UnterminatedChar |
InvalidString |
InvalidChar |
LexicalError |

Instances

Eq TokenErr Source # |
Methods (==) :: TokenErr -> TokenErr -> Bool # (/=) :: TokenErr -> TokenErr -> Bool #
Show TokenErr Source # |
Methods showsPrec :: Int -> TokenErr -> ShowS # show :: TokenErr -> String # showList :: [TokenErr] -> ShowS #
Generic TokenErr Source # |
Associated Types type Rep TokenErr :: * -> * # Methods from :: TokenErr -> Rep TokenErr x # to :: Rep TokenErr x -> TokenErr #
NFData TokenErr Source # |
Methods rnf :: TokenErr -> () #
type Rep TokenErr Source # |

type Rep TokenErr = D1 (MetaData "TokenErr" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) ((:+:) ((:+:) (C1 (MetaCons "UnterminatedComment" PrefixI False) U1) ((:+:) (C1 (MetaCons "UnterminatedString" PrefixI False) U1) (C1 (MetaCons "UnterminatedChar" PrefixI False) U1))) ((:+:) (C1 (MetaCons "InvalidString" PrefixI False) U1) ((:+:) (C1 (MetaCons "InvalidChar" PrefixI False) U1) (C1 (MetaCons "LexicalError" PrefixI False) U1))))

data TokenSym Source #

Constructors

Bar |
ArrL |
ArrR |
FatArrR |
Lambda |
EqDef |
Comma |
Semi |
Dot |
DotDot |
DotDotDot |
Colon |
BackTick |
ParenL |
ParenR |
BracketL |
BracketR |
CurlyL |
CurlyR |
TriL |
TriR |
Underscore |

Instances

Eq TokenSym Source # |
Methods (==) :: TokenSym -> TokenSym -> Bool # (/=) :: TokenSym -> TokenSym -> Bool #
Show TokenSym Source # |
Methods showsPrec :: Int -> TokenSym -> ShowS # show :: TokenSym -> String # showList :: [TokenSym] -> ShowS #
Generic TokenSym Source # |
Associated Types type Rep TokenSym :: * -> * # Methods from :: TokenSym -> Rep TokenSym x # to :: Rep TokenSym x -> TokenSym #
NFData TokenSym Source # |
Methods rnf :: TokenSym -> () #
type Rep TokenSym Source # |

type Rep TokenSym = D1 (MetaData "TokenSym" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) ((:+:) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "Bar" PrefixI False) U1) (C1 (MetaCons "ArrL" PrefixI False) U1)) ((:+:) (C1 (MetaCons "ArrR" PrefixI False) U1) ((:+:) (C1 (MetaCons "FatArrR" PrefixI False) U1) (C1 (MetaCons "Lambda" PrefixI False) U1)))) ((:+:) ((:+:) (C1 (MetaCons "EqDef" PrefixI False) U1) ((:+:) (C1 (MetaCons "Comma" PrefixI False) U1) (C1 (MetaCons "Semi" PrefixI False) U1))) ((:+:) (C1 (MetaCons "Dot" PrefixI False) U1) ((:+:) (C1 (MetaCons "DotDot" PrefixI False) U1) (C1 (MetaCons "DotDotDot" PrefixI False) U1))))) ((:+:) ((:+:) ((:+:) (C1 (MetaCons "Colon" PrefixI False) U1) (C1 (MetaCons "BackTick" PrefixI False) U1)) ((:+:) (C1 (MetaCons "ParenL" PrefixI False) U1) ((:+:) (C1 (MetaCons "ParenR" PrefixI False) U1) (C1 (MetaCons "BracketL" PrefixI False) U1)))) ((:+:) ((:+:) (C1 (MetaCons "BracketR" PrefixI False) U1) ((:+:) (C1 (MetaCons "CurlyL" PrefixI False) U1) (C1 (MetaCons "CurlyR" PrefixI False) U1))) ((:+:) (C1 (MetaCons "TriL" PrefixI False) U1) ((:+:) (C1 (MetaCons "TriR" PrefixI False) U1) (C1 (MetaCons "Underscore" PrefixI False) U1))))))

data TokenW Source #

Constructors

BlockComment |
LineComment |
Space |
DocStr |

Instances

Eq TokenW Source # |
Methods (==) :: TokenW -> TokenW -> Bool # (/=) :: TokenW -> TokenW -> Bool #
Show TokenW Source # |
Methods showsPrec :: Int -> TokenW -> ShowS # show :: TokenW -> String # showList :: [TokenW] -> ShowS #
Generic TokenW Source # |
Associated Types type Rep TokenW :: * -> * # Methods from :: TokenW -> Rep TokenW x # to :: Rep TokenW x -> TokenW #
NFData TokenW Source # |
Methods rnf :: TokenW -> () #
type Rep TokenW Source # |
type Rep TokenW = D1 (MetaData "TokenW" "Cryptol.Parser.LexerUtils" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) ((:+:) ((:+:) (C1 (MetaCons "BlockComment" PrefixI False) U1) (C1 (MetaCons "LineComment" PrefixI False) U1)) ((:+:) (C1 (MetaCons "Space" PrefixI False) U1) (C1 (MetaCons "DocStr" PrefixI False) U1)))

data Located a Source #

Constructors

Located |

Fields

- srcRange :: !Range
- thing :: a

Instances

Functor Located Source # |
Methods fmap :: (a -> b) -> Located a -> Located b # (<$) :: a -> Located b -> Located a #
Eq a => Eq (Located a) Source # |
Methods (==) :: Located a -> Located a -> Bool # (/=) :: Located a -> Located a -> Bool #
Show a => Show (Located a) Source # |
Methods showsPrec :: Int -> Located a -> ShowS # show :: Located a -> String # showList :: [Located a] -> ShowS #
Generic (Located a) Source # |
Associated Types type Rep (Located a) :: * -> * # Methods from :: Located a -> Rep (Located a) x # to :: Rep (Located a) x -> Located a #
NFData a => NFData (Located a) Source # |
Methods rnf :: Located a -> () #
PPName a => PPName (Located a) Source # |
Methods ppNameFixity :: Located a -> Maybe (Assoc, Int) Source # ppPrefixName :: Located a -> Doc Source # ppInfixName :: Located a -> Doc Source #
PP a => PP (Located a) Source # |
Methods ppPrec :: Int -> Located a -> Doc Source #
AddLoc (Located a) Source # |
Methods addLoc :: Located a -> Range -> Located a Source # dropLoc :: Located a -> Located a Source #
HasLoc (Located a) Source # |
Methods getLoc :: Located a -> Maybe Range Source #
NoPos (Located t) Source # |
Methods noPos :: Located t -> Located t Source #
type Rep (Located a) Source # |
type Rep (Located a) = D1 (MetaData "Located" "Cryptol.Parser.Position" "cryptol-2.4.0-CN28BMG3PUFD1lr9WvB1U9" False) (C1 (MetaCons "Located" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "srcRange") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Range)) (S1 (MetaSel (Just Symbol "thing") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))

data Config Source #

Constructors

Config |

Fields

- cfgSource :: !FilePath

  File that we are working on

- cfgLayout :: !Layout

  Settings for layout processing

- cfgPreProc :: PreProc

  Preprocessor settings

- cfgAutoInclude :: [FilePath]

  Implicit includes

- cfgModuleScope :: Bool

  When we do layout processing should we add a vCurly (i.e., are we parsing a list of things).

defaultConfig :: Config Source #