Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yaml-mode #1090

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments can also appear after some other tokens, like:

# Comment on a line
"symfony 1.0": { PHP: 5.0, Propel: 1.2 } # Comment at the end of a line
"symfony 1.2": { PHP: 5.2, Propel: 1.3 }

Taken from: https://symfony.com/doc/current/components/yaml/yaml_format.html#comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed a comment-pattern.

^$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