yi-language-0.19.2: Collection of language-related Yi libraries.

License | GPL-2
Maintainer | yi-devel@googlegroups.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Extensions

- TemplateHaskell
- TemplateHaskellQuotes
- DisambiguateRecordFields
- RecordWildCards
- DeriveFunctor

Yi.Lexer.Alex

Description

Utilities to turn a lexer generated by Alex into a `Scanner` that can be used by Yi. Most lexers will use the types defined here. Some things are exported for use by lexers themselves through the use of `YiLexerscommon.hsinc`.

Synopsis

- step :: forall l s t i f. Functor f => (TokenLexer l s t i -> f (TokenLexer l s t i)) -> Lexer l s t i -> f (Lexer l s t i)
- type Action hlState token = IndexedStr -> hlState -> (hlState, token)
- utf8Encode :: Char -> [Word8]
- tokenToStyle :: forall (l :: Type -> Type) s t i f. Functor f => ((t -> StyleName) -> f (t -> StyleName)) -> StyleLexer l s t i -> f (StyleLexer l s t i)
- type Byte = Word8
- type IndexedStr = [(Point, Char)]
- type AlexInput = (Char, [Byte], IndexedStr)
- data AlexState lexerState = AlexState {
  - stLexer :: lexerState
  - lookedOffset :: !Point
  - stPosn :: !Posn
  }
- data Posn = Posn {
  - posnOfs :: !Point
  - posnLine :: !Int
  - posnCol :: !Int
  }
- data Tok t = Tok {
  - tokT :: t
  - tokLen :: Size
  - tokPosn :: Posn
  }
- tokToSpan :: Tok t -> Span t
- tokFromT :: t -> Tok t
- startPosn :: Posn
- tokBegin :: Tok t -> Point
- tokEnd :: Tok t -> Point
- moveStr :: Posn -> IndexedStr -> Posn
- moveCh :: Posn -> Char -> Posn
- alexGetChar :: AlexInput -> Maybe (Char, AlexInput)
- alexGetByte :: AlexInput -> Maybe (Word8, AlexInput)
- alexCollectChar :: AlexInput -> [Char]
- alexInputPrevChar :: AlexInput -> Char
- actionConst :: token -> Action lexState token
- actionAndModify :: (lexState -> lexState) -> token -> Action lexState token
- actionStringAndModify :: (s -> s) -> (String -> token) -> Action s token
- actionStringConst :: (String -> token) -> Action lexState token
- type ASI s = (AlexState s, AlexInput)
- type TokenLexer (l :: Type -> Type) s t i = (l s, i) -> Maybe (t, (l s, i))
- type CharScanner = Scanner Point Char
- data Lexer (l :: Type -> Type) s t i = Lexer {
  - _step :: TokenLexer l s t i
  - _starting :: s -> Point -> Posn -> l s
  - _withChars :: Char -> [(Point, Char)] -> i
  - _looked :: l s -> Point
  - _statePosn :: l s -> Posn
  - _lexEmpty :: t
  - _startingState :: s
  }
- data StyleLexer (l :: Type -> Type) s t i = StyleLexer {
  - _tokenToStyle :: t -> StyleName
  - _styleLexer :: Lexer l s (Tok t) i
  }
- type StyleLexerASI s t = StyleLexer AlexState s t AlexInput
- commonLexer :: (ASI s -> Maybe (Tok t, ASI s)) -> s -> Lexer AlexState s (Tok t) AlexInput
- lexScanner :: Lexer l s t i -> CharScanner -> Scanner (l s) t
- unfoldLexer :: ((state, input) -> Maybe (token, (state, input))) -> (state, input) -> [(state, token)]
- posnColA :: Lens' Posn Int
- posnLineA :: Lens' Posn Int
- posnOfsA :: Lens' Posn Point
- tokLenA :: forall t f. Functor f => (Size -> f Size) -> Tok t -> f (Tok t)
- tokPosnA :: forall t f. Functor f => (Posn -> f Posn) -> Tok t -> f (Tok t)
- tokTA :: forall t1 t2 f. Functor f => (t1 -> f t2) -> Tok t1 -> f (Tok t2)
- lexEmpty :: forall (l :: Type -> Type) s t i f. Functor f => (t -> f t) -> Lexer l s t i -> f (Lexer l s t i)
- looked :: forall l s t i f. Functor f => ((l s -> Point) -> f (l s -> Point)) -> Lexer l s t i -> f (Lexer l s t i)
- starting :: forall l s t i f. Functor f => ((s -> Point -> Posn -> l s) -> f (s -> Point -> Posn -> l s)) -> Lexer l s t i -> f (Lexer l s t i)
- startingState :: forall (l :: Type -> Type) s t i f. Functor f => (s -> f s) -> Lexer l s t i -> f (Lexer l s t i)
- statePosn :: forall l s t i f. Functor f => ((l s -> Posn) -> f (l s -> Posn)) -> Lexer l s t i -> f (Lexer l s t i)
- withChars :: forall (l :: Type -> Type) s t i f. Functor f => ((Char -> [(Point, Char)] -> i) -> f (Char -> [(Point, Char)] -> i)) -> Lexer l s t i -> f (Lexer l s t i)
- styleLexer :: forall (l1 :: Type -> Type) s1 t i1 (l2 :: Type -> Type) s2 i2 f. Functor f => (Lexer l1 s1 (Tok t) i1 -> f (Lexer l2 s2 (Tok t) i2)) -> StyleLexer l1 s1 t i1 -> f (StyleLexer l2 s2 t i2)
- (+~) :: SemiNum absolute relative => absolute -> relative -> absolute
- (~-) :: SemiNum absolute relative => absolute -> absolute -> relative
- newtype Size = Size {
  - fromSize :: Int
  }
- type Stroke = Span StyleName

# Documentation

step :: forall l s t i f. Functor f => (TokenLexer l s t i -> f (TokenLexer l s t i)) -> Lexer l s t i -> f (Lexer l s t i) Source #

type Action hlState token = IndexedStr -> hlState -> (hlState, token) Source #

utf8Encode :: Char -> [Word8] Source #

Encode a Haskell String to a list of Word8 values, in UTF8 format.

tokenToStyle :: forall (l :: Type -> Type) s t i f. Functor f => ((t -> StyleName) -> f (t -> StyleName)) -> StyleLexer l s t i -> f (StyleLexer l s t i) Source #

type Byte = Word8 Source #

type IndexedStr = [(Point, Char)] Source #

type AlexInput = (Char, [Byte], IndexedStr) Source #

data AlexState lexerState Source #

Lexer state

Constructors

AlexState |

Fields

- stLexer :: lexerState
- lookedOffset :: !Point
- stPosn :: !Posn

#### Instances

Instances details

Show lexerState => Show (AlexState lexerState) Source # |
Instance details Defined in Yi.Lexer.Alex Methods showsPrec :: Int -> AlexState lexerState -> ShowS Source # show :: AlexState lexerState -> String Source # showList :: [AlexState lexerState] -> ShowS Source #

data Posn Source #

Constructors

Posn |

Fields

- posnOfs :: !Point
- posnLine :: !Int
- posnCol :: !Int

#### Instances

Instances details

Ix Posn Source # |
Instance details Defined in Yi.Lexer.Alex Methods range :: (Posn, Posn) -> [Posn] Source # index :: (Posn, Posn) -> Posn -> Int Source # unsafeIndex :: (Posn, Posn) -> Posn -> Int Source # inRange :: (Posn, Posn) -> Posn -> Bool Source # rangeSize :: (Posn, Posn) -> Int Source # unsafeRangeSize :: (Posn, Posn) -> Int Source #
Show Posn Source # |
Instance details Defined in Yi.Lexer.Alex Methods showsPrec :: Int -> Posn -> ShowS Source # show :: Posn -> String Source # showList :: [Posn] -> ShowS Source #
Eq Posn Source # |
Instance details Defined in Yi.Lexer.Alex Methods (==) :: Posn -> Posn -> Bool Source # (/=) :: Posn -> Posn -> Bool Source #
Ord Posn Source # |
Instance details Defined in Yi.Lexer.Alex Methods compare :: Posn -> Posn -> Ordering Source # (<) :: Posn -> Posn -> Bool Source # (<=) :: Posn -> Posn -> Bool Source # (>) :: Posn -> Posn -> Bool Source # (>=) :: Posn -> Posn -> Bool Source # max :: Posn -> Posn -> Posn Source # min :: Posn -> Posn -> Posn Source #

data Tok t Source #

Constructors

Tok |

Fields

- tokT :: t
- tokLen :: Size
- tokPosn :: Posn

#### Instances

Instances details

Functor Tok Source # |
Instance details Defined in Yi.Lexer.Alex Methods fmap :: (a -> b) -> Tok a -> Tok b Source # (<$) :: a -> Tok b -> Tok a Source #
Show t => Show (Tok t) Source # |
Instance details Defined in Yi.Lexer.Alex Methods showsPrec :: Int -> Tok t -> ShowS Source # show :: Tok t -> String Source # showList :: [Tok t] -> ShowS Source #
Eq (Tok a) Source # |
Instance details Defined in Yi.Lexer.Alex Methods (==) :: Tok a -> Tok a -> Bool Source # (/=) :: Tok a -> Tok a -> Bool Source #

tokToSpan :: Tok t -> Span t Source #

tokFromT :: t -> Tok t Source #

startPosn :: Posn Source #

tokBegin :: Tok t -> Point Source #

tokEnd :: Tok t -> Point Source #

moveStr :: Posn -> IndexedStr -> Posn Source #

moveCh :: Posn -> Char -> Posn Source #

alexGetChar :: AlexInput -> Maybe (Char, AlexInput) Source #

alexGetByte :: AlexInput -> Maybe (Word8, AlexInput) Source #

alexCollectChar :: AlexInput -> [Char] Source #

alexInputPrevChar :: AlexInput -> Char Source #

actionConst :: token -> Action lexState token Source #

Return a constant token

actionAndModify :: (lexState -> lexState) -> token -> Action lexState token Source #

Return a constant token, and modify the lexer state

actionStringAndModify :: (s -> s) -> (String -> token) -> Action s token Source #

Convert the parsed string into a token, and also modify the lexer state

actionStringConst :: (String -> token) -> Action lexState token Source #

Convert the parsed string into a token

type ASI s = (AlexState s, AlexInput) Source #

type TokenLexer (l :: Type -> Type) s t i = (l s, i) -> Maybe (t, (l s, i)) Source #

Function to (possibly) lex a single token and give us the remaining input.

type CharScanner = Scanner Point Char Source #

Handy alias

data Lexer (l :: Type -> Type) s t i Source #

Generalises lexers. This allows us to easily use lexers which don't want to be cornered into the types we have predefined here and use in `common.hsinc`.

Constructors

Lexer |

Fields

- _step :: TokenLexer l s t i
- _starting :: s -> Point -> Posn -> l s
- _withChars :: Char -> [(Point, Char)] -> i
- _looked :: l s -> Point
- _statePosn :: l s -> Posn
- _lexEmpty :: t
- _startingState :: s

data StyleLexer (l :: Type -> Type) s t i Source #

Just like `Lexer` but also knows how to turn its tokens into `StyleName`s.

Constructors

StyleLexer |

Fields

- _tokenToStyle :: t -> StyleName
- _styleLexer :: Lexer l s (Tok t) i

type StyleLexerASI s t = StyleLexer AlexState s t AlexInput Source #

`StyleLexer` over `ASI`.

commonLexer :: (ASI s -> Maybe (Tok t, ASI s)) -> s -> Lexer AlexState s (Tok t) AlexInput Source #

Defines a `Lexer` for `ASI`. This exists to make using the new `lexScanner` easier if you're using `ASI` as all our lexers do today, 23-08-2014.

lexScanner :: Lexer l s t i -> CharScanner -> Scanner (l s) t Source #

Combine a character scanner with a lexer to produce a token scanner. May be used together with `mkHighlighter` to produce a `Highlighter`, or with `linearSyntaxMode` to produce a `Mode`.

unfoldLexer :: ((state, input) -> Maybe (token, (state, input))) -> (state, input) -> [(state, token)] Source #

unfold lexer into a function that returns a stream of (state, token)

posnColA :: Lens' Posn Int Source #

posnLineA :: Lens' Posn Int Source #

posnOfsA :: Lens' Posn Point Source #

tokLenA :: forall t f. Functor f => (Size -> f Size) -> Tok t -> f (Tok t) Source #

tokPosnA :: forall t f. Functor f => (Posn -> f Posn) -> Tok t -> f (Tok t) Source #

tokTA :: forall t1 t2 f. Functor f => (t1 -> f t2) -> Tok t1 -> f (Tok t2) Source #

lexEmpty :: forall (l :: Type -> Type) s t i f. Functor f => (t -> f t) -> Lexer l s t i -> f (Lexer l s t i) Source #

looked :: forall l s t i f. Functor f => ((l s -> Point) -> f (l s -> Point)) -> Lexer l s t i -> f (Lexer l s t i) Source #

starting :: forall l s t i f. Functor f => ((s -> Point -> Posn -> l s) -> f (s -> Point -> Posn -> l s)) -> Lexer l s t i -> f (Lexer l s t i) Source #

startingState :: forall (l :: Type -> Type) s t i f. Functor f => (s -> f s) -> Lexer l s t i -> f (Lexer l s t i) Source #

statePosn :: forall l s t i f. Functor f => ((l s -> Posn) -> f (l s -> Posn)) -> Lexer l s t i -> f (Lexer l s t i) Source #

withChars :: forall (l :: Type -> Type) s t i f. Functor f => ((Char -> [(Point, Char)] -> i) -> f (Char -> [(Point, Char)] -> i)) -> Lexer l s t i -> f (Lexer l s t i) Source #

styleLexer :: forall (l1 :: Type -> Type) s1 t i1 (l2 :: Type -> Type) s2 i2 f. Functor f => (Lexer l1 s1 (Tok t) i1 -> f (Lexer l2 s2 (Tok t) i2)) -> StyleLexer l1 s1 t i1 -> f (StyleLexer l2 s2 t i2) Source #

(+~) :: SemiNum absolute relative => absolute -> relative -> absolute Source #

(~-) :: SemiNum absolute relative => absolute -> absolute -> relative Source #

newtype Size Source #

Size of a buffer region

Constructors

Size |

Fields

- fromSize :: Int

#### Instances

Instances details

Binary Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods put :: Size -> Put Source # get :: Get Size Source # putList :: [Size] -> Put Source #
Enum Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods succ :: Size -> Size Source # pred :: Size -> Size Source # toEnum :: Int -> Size Source # fromEnum :: Size -> Int Source # enumFrom :: Size -> [Size] Source # enumFromThen :: Size -> Size -> [Size] Source # enumFromTo :: Size -> Size -> [Size] Source # enumFromThenTo :: Size -> Size -> Size -> [Size] Source #
Num Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods (+) :: Size -> Size -> Size Source # (-) :: Size -> Size -> Size Source # (*) :: Size -> Size -> Size Source # negate :: Size -> Size Source # abs :: Size -> Size Source # signum :: Size -> Size Source # fromInteger :: Integer -> Size Source #
Integral Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods quot :: Size -> Size -> Size Source # rem :: Size -> Size -> Size Source # div :: Size -> Size -> Size Source # mod :: Size -> Size -> Size Source # quotRem :: Size -> Size -> (Size, Size) Source # divMod :: Size -> Size -> (Size, Size) Source # toInteger :: Size -> Integer Source #
Real Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods toRational :: Size -> Rational Source #
Show Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods showsPrec :: Int -> Size -> ShowS Source # show :: Size -> String Source # showList :: [Size] -> ShowS Source #
Eq Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods (==) :: Size -> Size -> Bool Source # (/=) :: Size -> Size -> Bool Source #
Ord Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods compare :: Size -> Size -> Ordering Source # (<) :: Size -> Size -> Bool Source # (<=) :: Size -> Size -> Bool Source # (>) :: Size -> Size -> Bool Source # (>=) :: Size -> Size -> Bool Source # max :: Size -> Size -> Size Source # min :: Size -> Size -> Size Source #
SemiNum Point Size Source # |
Instance details Defined in Yi.Buffer.Basic Methods (+~) :: Point -> Size -> Point Source # (-~) :: Point -> Size -> Point Source # (~-) :: Point -> Point -> Size Source #

type Stroke = Span StyleName Source #