Skip to content

Commit

Permalink
Add yaml-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
junjihashimoto committed Jun 15, 2018
1 parent 70ae278 commit a9dc927
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions yi-misc-modes/src/Yi/Config/Default/MiscModes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ configureMiscModes = do
addMode gnuMakeMode
addMode ottMode
addMode whitespaceMode
addMode yamlMode
52 changes: 52 additions & 0 deletions yi-misc-modes/src/Yi/Lexer/YAML.x
Original file line number Diff line number Diff line change
@@ -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 }
^$space*\#.* { 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"
}
9 changes: 8 additions & 1 deletion yi-misc-modes/src/Yi/Modes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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 })
1 change: 1 addition & 0 deletions yi-misc-modes/yi-misc-modes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9dc927

Please sign in to comment.