| License | GPL-2 |
|---|---|
| Maintainer | yi-devel@googlegroups.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
| Extensions | OverloadedStrings |
Yi.Mode.Common
Description
Common functions used by modes.
Synopsis
- type TokenBasedMode tok = Mode (Tree (Tok tok))
- fundamentalMode :: Mode syntax
- anyExtension :: [String] -> FilePath -> a -> Bool
- extensionOrContentsMatch :: [String] -> Parser () -> FilePath -> YiString -> Bool
- linearSyntaxMode :: Show s => s -> TokenLexer AlexState s (Tok t) AlexInput -> (t -> StyleName) -> TokenBasedMode t
- hookModes :: (AnyMode -> Bool) -> BufferM () -> [AnyMode] -> [AnyMode]
- applyModeHooks :: [(AnyMode -> Bool, BufferM ())] -> [AnyMode] -> [AnyMode]
- lookupMode :: AnyMode -> YiM AnyMode
- styleMode :: Show (l s) => StyleLexer l s t i -> TokenBasedMode t
- extensionMatches :: [String] -> FilePath -> Bool
- shebangParser :: Parser a -> Parser ()
Documentation
fundamentalMode :: Mode syntax Source #
The only built in mode of yi
Arguments
| :: [String] | List of extensions |
| -> FilePath | Path to compare against |
| -> a | File contents. Currently unused but see
|
| -> Bool |
When applied to an extensions list, creates a modeApplies function.
extensionOrContentsMatch :: [String] -> Parser () -> FilePath -> YiString -> Bool Source #
When applied to an extensions list and regular expression pattern, creates
a modeApplies function.
Arguments
| :: Show s | |
| => s | Starting state |
| -> TokenLexer AlexState s (Tok t) AlexInput | |
| -> (t -> StyleName) | |
| -> TokenBasedMode t |
Specialised version of linearSyntaxMode' for the common case,
wrapping up into a Lexer with commonLexer.
hookModes :: (AnyMode -> Bool) -> BufferM () -> [AnyMode] -> [AnyMode] Source #
Adds a hook to all matching hooks in a list
applyModeHooks :: [(AnyMode -> Bool, BufferM ())] -> [AnyMode] -> [AnyMode] Source #
Apply a list of mode hooks to a list of AnyModes
lookupMode :: AnyMode -> YiM AnyMode Source #
Check whether a mode of the same name is already in modeTable and returns the original mode, if it isn't the case.
styleMode :: Show (l s) => StyleLexer l s t i -> TokenBasedMode t Source #
extensionMatches :: [String] -> FilePath -> Bool Source #
Determines if the file's extension is one of the extensions in the list.
shebangParser :: Parser a -> Parser () Source #
Generate a parser for shebang patterns the generated parser will match only if the shebang is at the start of a line
Examples
shebangParser "runhaskell"
generates a parser that matches "#!/usr/bin/env runhaskell\n" (but also "djsjfaj\n\n\n\r\n#! /usr/bin/env runhaskell \ndkasfkda\n\r\nkasfaj")
Note: You can get ("runhaskell" :: Parser String) by using the OverloadedStrings extension
shebangParser "python"
generates a parser that matches "#!/usr/bin/env python\n"
Note: it doesn't match "#!/usr/bin/env python2\n" (that's why the newline is required)
It is also possible to use more complex parsers:
shebangParser ("python" *> ("2" <|> "3" <|> ""))generates a parser that matches any of:
- "#!/usr/bin/env python\n"
- "#!/usr/bin/env python2\n"
- "#!/usr/bin/env python3\n"