diff --git a/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs b/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs index 07e89abac..eeaed42a7 100644 --- a/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs +++ b/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs @@ -21,3 +21,4 @@ configureMiscModes = do addMode gnuMakeMode addMode ottMode addMode whitespaceMode + addMode yamlMode diff --git a/yi-misc-modes/src/Yi/Lexer/YAML.x b/yi-misc-modes/src/Yi/Lexer/YAML.x new file mode 100644 index 000000000..56abf176d --- /dev/null +++ b/yi-misc-modes/src/Yi/Lexer/YAML.x @@ -0,0 +1,52 @@ +-- -*- haskell -*- +-- Lexer for YAML-file +-- This is based off the syntax as described in the github manual: +-- http://yaml.org/spec/1.2/spec.html +-- Maintainer: Junji Hashimoto +{ +{-# OPTIONS -w #-} +module Yi.Lexer.YAML ( lexer ) where +import Yi.Lexer.Alex hiding (tokenToStyle) +import Yi.Style + ( Style ( .. ) + , StyleName + ) +import qualified Yi.Style as Style +} + +$space = [\ ] + +yaml :- + +<0> +{ + ^\%.* { c Style.importStyle } + ^\-\-\- { c Style.importStyle } + \#.* { c Style.commentStyle } + ^$space*[\-] { c Style.keywordStyle } + ^$space*[^\:]+\: { c Style.keywordStyle } + \n + { c Style.defaultStyle } + . + { c Style.defaultStyle } +} + +{ +data HlState = + TopLevel + deriving Show +stateToInit TopLevel = 0 + +initState :: HlState +initState = TopLevel + +type Token = StyleName + +lexer :: StyleLexerASI HlState Token +lexer = StyleLexer + { _tokenToStyle = id + , _styleLexer = commonLexer alexScanToken initState + } + +#include "common.hsinc" +} diff --git a/yi-misc-modes/src/Yi/Modes.hs b/yi-misc-modes/src/Yi/Modes.hs index d4b1b1be6..d20f207a2 100644 --- a/yi-misc-modes/src/Yi/Modes.hs +++ b/yi-misc-modes/src/Yi/Modes.hs @@ -14,7 +14,7 @@ module Yi.Modes (cMode, objectiveCMode, cppMode, cabalMode, clojureMode, srmcMode, ocamlMode, ottMode, gnuMakeMode, perlMode, pythonMode, javaMode, jsonMode, anyExtension, - svnCommitMode, whitespaceMode, + svnCommitMode, whitespaceMode, yamlMode, gitCommitMode, rubyMode ) where @@ -41,6 +41,7 @@ import qualified Yi.Lexer.Ruby as Ruby (lexer) import qualified Yi.Lexer.Srmc as Srmc (lexer) import qualified Yi.Lexer.SVNCommit as SVNCommit (lexer) import qualified Yi.Lexer.Whitespace as Whitespace (lexer) +import qualified Yi.Lexer.YAML as YAML (lexer) import Yi.Mode.Common import Yi.Style (StyleName) @@ -148,3 +149,9 @@ whitespaceMode = styleMode Whitespace.lexer & modeNameA .~ "whitespace" & modeAppliesA .~ anyExtension [ "ws" ] & modeIndentA .~ (\_ _ -> insertB '\t') + +yamlMode :: TokenBasedMode StyleName +yamlMode = styleMode YAML.lexer + & modeNameA .~ "yaml" + & modeAppliesA .~ anyExtension [ "yaml", "yml" ] + & modeIndentSettingsA %~ (\x -> x { expandTabs = True, shiftWidth = 2 }) diff --git a/yi-misc-modes/yi-misc-modes.cabal b/yi-misc-modes/yi-misc-modes.cabal index 15fac2a75..4ab140c75 100644 --- a/yi-misc-modes/yi-misc-modes.cabal +++ b/yi-misc-modes/yi-misc-modes.cabal @@ -61,6 +61,7 @@ library Yi.Lexer.SVNCommit Yi.Lexer.Srmc Yi.Lexer.Whitespace + Yi.Lexer.YAML Yi.Syntax.Latex other-modules: Yi.Lexer.BasicTemplate