citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

happy.vim (3636B)


      1 " Vim syntax file
      2 " Language:     Happy file language
      3 " Maintainer:   Nickolay Kudasov
      4 " Last Change:  18 March, 2010
      5 "
      6 " Version:      0.2
      7 " Changes:      ' is now part of non-terminals
      8 "               highlighting todos and fixmes in haskell comments
      9 "               highlighting haskell directives
     10 
     11 if exists("b:current_syntax")
     12     finish
     13 endif
     14 
     15 " Keywords (e.g. %name) start with %, so we add it to keyword characters
     16 set iskeyword+=%
     17 
     18 " ' is allowed in non-terminals
     19 set isident+='
     20 
     21 " Haskell code in happy file
     22 syn match haskell_comment  /--.*$/ contained contains=happy_todo,happy_fixme
     23 syn match haskell_char /'[^\\]'\|'\\.'/ contained
     24 
     25 syn region haskell_string           start=/"/ skip=/\\"/ end=/"/        contained
     26 syn region haskell_block_comment    start=/{-/ end=/-}/                 fold contained contains=haskell_block_comment,happy_todo,happy_fixme
     27 syn region haskell_directive        start=/{-#/ end=/#-}/               contained
     28 syn region haskell_code             start=/{/ skip=/'\\\?}'/ end=/}/    fold contains=haskell_comment,haskell_block_comment,haskell_string,haskell_char,haskell_code,haskell_directive
     29 
     30 " Comments in happy file
     31 syn match happy_comment  /--.*$/ contains=happy_todo,happy_fixme
     32 syn region happy_block_comment  start=/{-/ end=/-}/ fold contains=happy_block_comment,happy_todo,happy_fixme
     33 syn match happy_todo     /[tT][oO][dD][oO]/ contained
     34 syn match happy_fixme    /[fF][iI][xX][mM][eE]/ contained
     35 
     36 " Module header directives
     37 syn keyword happy_directives    %tokentype %partial
     38 syn keyword happy_directives    %monad %lexer
     39 syn keyword happy_directives    %expect %error
     40 syn keyword happy_directives    %attributetype %attribute
     41 
     42 " %name directive
     43 syn match parser_name   /[a-zA-Z_][a-zA-Z_\d]*/ contained
     44 syn region happy_names  matchgroup=happy_directives start=/%name/       end=/%/me=e-1,he=e-1 contains=happy_name,parser_name,happy_comment
     45 
     46 " %token and association directives
     47 syn match token_name    /[a-zA-Z_][a-zA-Z_\d]*/         contained
     48 syn region token_name   start=/"/ skip=/\\"/ end=/"/    contained
     49 syn region token_name   start=/'/ skip=/\\'/ end=/'/    contained
     50 
     51 syn region happy_tokens matchgroup=happy_directives start=/%token/      end=/%/me=e-1,he=e-1 contains=token_name,haskell_code,happy_comment
     52 syn region happy_assoc  matchgroup=happy_directives start=/%left/       end=/%/me=e-1,he=e-1 contains=token_name,haskell_code,happy_comment
     53 syn region happy_assoc  matchgroup=happy_directives start=/%right/      end=/%/me=e-1,he=e-1 contains=token_name,haskell_code,happy_comment
     54 syn region happy_assoc  matchgroup=happy_directives start=/%nonassoc/   end=/%/me=e-1,he=e-1 contains=token_name,haskell_code,happy_comment
     55 
     56 syn match happy_separator   /%%/
     57 
     58 " Happy grammar
     59 syn match non_terminal  /[a-zA-Z_][a-zA-Z_\d\']*/         
     60 syn region terminal     start=/"/ skip=/\\"/ end=/"/    
     61 syn region terminal     start=/'/ skip=/\\'/ end=/'/    
     62 
     63 hi def link haskell_comment         Comment
     64 hi def link haskell_block_comment   Comment
     65 hi def link haskell_directive       Special
     66 hi def link haskell_char            Character
     67 hi def link haskell_string          String
     68 
     69 hi def link happy_comment           Comment
     70 hi def link happy_block_comment     Comment
     71 hi def link happy_todo              Todo
     72 hi def link happy_fixme             Todo
     73 hi def link parser_name             Function
     74 hi def link token_name              Identifier
     75 hi def link happy_directives        Keyword
     76 hi def link happy_separator         Special
     77 hi def link non_terminal            Identifier
     78 hi def link terminal                String
     79 
     80 " Syntax configuration name
     81 let b:current_syntax = "happy"