e9cb7ce
" IFM syntax file
e9cb7ce
" Language: Interactive Fiction Mapper
e9cb7ce
" Maintainer: Dave Chapeskie <dchapes@ddm.wox.org>
e9cb7ce
" $Id: ifm.vim,v 1.1 2005/10/04 21:17:50 cgrau Exp $
e9cb7ce
"
e9cb7ce
" Note:  This is my first attempt at doing vim syntax highlighting,
e9cb7ce
"        if there is a better way of doing any of this please e-mail me.
e9cb7ce
" Note:  This is for version 5.0 of IFM.
e9cb7ce
" TODO: handle using "$variable_name" where strings or numbers are expected
e9cb7ce
" TODO: handle "$variable_name" and "${variable_name}" within strings
e9cb7ce
" TODO: handle expressions
e9cb7ce
e9cb7ce
" Remove any old syntax stuff hanging around
e9cb7ce
syntax clear
e9cb7ce
e9cb7ce
" Catch keywords in the wrong spot
e9cb7ce
syntax keyword ifmError contained title map require room item task link join
e9cb7ce
e9cb7ce
" IFM statements
e9cb7ce
" TODO: doesn't complain when there is something betweem the keyword and the
e9cb7ce
"       string
e9cb7ce
" TODO: IFM2.0 and above supports changing existing objects by leaving out
e9cb7ce
"	the string and using the tag, the tag doesn't get hightlighted using
e9cb7ce
"       ifmId yet.
e9cb7ce
syntax region ifmTitleStatement	end=";" matchgroup=ifmStatement start="\<title\>" contains=ifmError,ifmComment,ifmString
e9cb7ce
syntax region ifmMapStatement	end=";" matchgroup=ifmStatement start="\<map\>" contains=ifmError,ifmComment,ifmString
e9cb7ce
syntax region ifmRequireStatement end=";" matchgroup=ifmStatement start="\<require\>" contains=ifmError,ifmComment,ifmReal
e9cb7ce
syntax region ifmRoomStatement	end=";" matchgroup=ifmStatement start="\<room\>" contains=ifmError,ifmComment,ifmString,ifmRoomOpt,ifmTagOpt,ifmDirFromOpt,ifmExitOpt,ifmScoreOpt,ifmGoOpt,ifmLengthOpt
e9cb7ce
syntax region ifmItemStatement	end=";" matchgroup=ifmStatement start="\<item\>" contains=ifmError,ifmComment,ifmString,ifmItemOpt,ifmTagOpt,ifmInOpt,ifmScoreOpt
e9cb7ce
syntax region ifmTaskStatement	end=";" matchgroup=ifmStatement start="\<task\>" contains=ifmError,ifmComment,ifmString,ifmTaskOpt,ifmTagOpt,ifmInOpt,ifmScoreOpt
e9cb7ce
syntax region ifmLinkStatement	end=";" matchgroup=ifmStatement start="\<link\>" contains=ifmError,ifmComment,ifmString,ifmLinkOpt,ifmTagOpt,ifmDirOpt,ifmGoOpt,ifmLengthOpt
e9cb7ce
syntax region ifmJoinStatement	end=";" matchgroup=ifmStatement start="\<join\>" contains=ifmError,ifmComment,ifmString,ifmJoinOpt,ifmTagOpt,ifmDirOpt,ifmGoOpt,ifmLengthOpt
e9cb7ce
syntax region ifmStyleStatement	end=";" matchgroup=ifmStatement start="\<style\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmEndStyleStatement	end=";" matchgroup=ifmStatement start="\<endstyle\>" contains=ifmId,ifmComment
e9cb7ce
e9cb7ce
" GPP preprocessor statements
e9cb7ce
syntax region ifmIncludeStatement	end="$" matchgroup=ifmStatement start="^%include\>" contains=ifmString,ifmComment
e9cb7ce
syntax region ifmDefineStatement	end="$" matchgroup=ifmStatement start="^%define\>" contains=ifmId,ifmString,ifmComment
e9cb7ce
syntax region ifmDefevalStatement	end="$" matchgroup=ifmStatement start="^%defeval\>" contains=ifmId,ifmString,ifmComment
e9cb7ce
syntax region ifmUndefStatement		end="$" matchgroup=ifmStatement start="^%undef\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmIfStatement		end="$" matchgroup=ifmStatement start="^%if\>" contains=ifmString,ifmComment
e9cb7ce
syntax region ifmIfdefStatement		end="$" matchgroup=ifmStatement start="^%ifdef\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmIfndefStatement	end="$" matchgroup=ifmStatement start="^%ifndef\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmIfeqStatement		end="$" matchgroup=ifmStatement start="^%ifeq\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmIfneqStatement		end="$" matchgroup=ifmStatement start="^%ifneq\>" contains=ifmId,ifmComment
e9cb7ce
syntax region ifmElseStatement		end="$" matchgroup=ifmStatement start="^%else\>" contains=ifmComment
e9cb7ce
syntax region ifmEndifStatement		end="$" matchgroup=ifmStatement start="^%endif\>" contains=ifmComment
e9cb7ce
syntax region ifmExecStatement		end="$" matchgroup=ifmStatement start="^%exec\>" contains=ifmString,ifmComment
e9cb7ce
syntax region ifmEvalStatement		end="$" matchgroup=ifmStatement start="^%eval\>" contains=ifmString,ifmComment
e9cb7ce
syntax region ifmModeStatement		end="$" matchgroup=ifmStatement start="^%mode\>" contains=ifmGPPMode,ifmString,ifmComment
e9cb7ce
" TODO: highlight these pre-defined preprocessor macros
e9cb7ce
syntax keyword ifmMacro IFM_VERSION IFM_FORMAT
e9cb7ce
e9cb7ce
syntax keyword ifmGPPMode contained push pop save restore standard user meta
e9cb7ce
syntax keyword ifmGPPMode contained quote comment nocomment string nostring
e9cb7ce
syntax keyword ifmGPPMode contained preservelf charset
e9cb7ce
e9cb7ce
" Comments
e9cb7ce
syntax match ifmComment "#.*" contains=ifmTodo
e9cb7ce
syntax keyword ifmTodo	contained TODO XXX
e9cb7ce
e9cb7ce
" Arguments of options which we want highlighted
e9cb7ce
syntax keyword ifmGoDir contained out in up down
e9cb7ce
" TODO: ifmString doesn't handle "testStr\\" correctly...
e9cb7ce
syntax region ifmString	contained start=+"+ skip=+\\"+ end=+"+
e9cb7ce
syntax match ifmId	contained "[a-zA-Z][a-zA-Z0-9_]*"
e9cb7ce
" TODO: IFM5.0 now accepts expressions whenever a number is expected
e9cb7ce
syntax match ifmInteger	contained "[0-9]\+"
e9cb7ce
syntax match ifmReal	contained "[0-9]\+\.[0-9]\+"
e9cb7ce
e9cb7ce
" The options which the above arguments are part of
e9cb7ce
syntax region ifmTagOpt	contained end="\<\S*\>" matchgroup=ifmKeyword start="\<tag\>" contains=ifmId keepend
e9cb7ce
syntax region ifmScoreOpt contained end="\<[0-9]*\>" matchgroup=ifmKeyword start="\<score\>" contains=ifmInteger keepend
e9cb7ce
syntax region ifmLengthOpt contained end="\<[0-9]*\>" matchgroup=ifmKeyword start="\<length\>" contains=ifmInteger keepend
e9cb7ce
syntax region ifmGoOpt	contained end="\<\S*\>" matchgroup=ifmKeyword start="\<go\>" contains=ifmGoDir keepend
e9cb7ce
syntax region ifmFromOpt contained end="\<\S*\>" matchgroup=ifmKeyword start="\<from\>" contains=ifmId keepend
e9cb7ce
syntax region ifmInOpt contained end="\<\S*\>" matchgroup=ifmKeyword start="\<in\>" contains=ifmId keepend
e9cb7ce
e9cb7ce
syntax keyword ifmExitOpt	contained exit			skipwhite skipempty nextgroup=ifmExitDir
e9cb7ce
syntax keyword ifmExitDir	contained nw n ne w e sw s se	skipwhite skipempty nextgroup=ifmExitDir
e9cb7ce
syntax keyword ifmExitDir contained northwest north northeast west east southwest south southeast skipwhite skipempty nextgroup=ifmExitDir
e9cb7ce
e9cb7ce
syntax keyword ifmDirFromOpt	contained dir			skipwhite skipempty nextgroup=ifmDirFrom
e9cb7ce
syntax keyword ifmDirFrom	contained nw n ne w e sw s se	skipwhite skipempty nextgroup=ifmDirFrom,ifmDirFromInt,ifmFromOpt
e9cb7ce
syntax keyword ifmDirFrom contained northwest north northeast west east southwest south southeast skipwhite skipempty nextgroup=ifmExitDir
e9cb7ce
syntax match ifmDirFromInt	contained "[0-9]\+"		skipwhite skipempty nextgroup=ifmDirFrom,ifmFromOpt
e9cb7ce
e9cb7ce
e9cb7ce
" Other options:
e9cb7ce
"    These options take arguments but we don't hightlight them
e9cb7ce
"    TODO: "in/after last" should have the word 'last' highlighted as a
e9cb7ce
"    constant, similarily for tasks "in any" should have 'any' highlighted
e9cb7ce
"    TODO: 'it' should be highlighted (e.g. task "xx" need xx drop it)
e9cb7ce
"    TODO: IFM2.0 added things like "leave all except ID" which should be
e9cb7ce
"    highlighted.
e9cb7ce
"    TODO: 'cmd from' and 'cmd to' should be hightlighted instead of just 'cmd'
e9cb7ce
"    TODO: IFM5.0 added "keep with/until ID [ID...]" for items; 'with'/'until'
e9cb7ce
"    should be highlighted.
e9cb7ce
syntax keyword ifmRoomOpt contained link join note need after before leave cmd
e9cb7ce
syntax keyword ifmRoomOpt contained style
e9cb7ce
syntax keyword ifmItemOpt contained note need after before style
e9cb7ce
syntax keyword ifmTaskOpt contained cmd note need after follow do get give lose
e9cb7ce
syntax keyword ifmTaskOpt contained drop goto style
e9cb7ce
syntax keyword ifmLinkOpt contained to cmd need after before leave style
e9cb7ce
syntax keyword ifmJoinOpt contained to cmd need after before leave style
e9cb7ce
"    These options don't have arguments
e9cb7ce
syntax keyword ifmRoomOpt contained start oneway finish nodrop nolink nopath
e9cb7ce
syntax keyword ifmItemOpt contained hidden keep ignore lost finish "given [obsolete]
e9cb7ce
syntax keyword ifmTaskOpt contained safe ignore finish
e9cb7ce
syntax keyword ifmLinkOpt contained oneway hidden nopath
e9cb7ce
syntax keyword ifmJoinOpt contained oneway hidden nopath
e9cb7ce
e9cb7ce
e9cb7ce
" IFM variable assignment
e9cb7ce
" [Format.]Ident = Integer|Real|String|"undef" ["in style" Id] ;
e9cb7ce
" TODO: handle "undef" keyword and "in style" clause
e9cb7ce
syntax region ifmEqInt contained end=";" matchgroup=ifmStatement start="=" contains=ifmInteger
e9cb7ce
syntax region ifmEqReal contained end=";" matchgroup=ifmStatement start="=" contains=ifmInteger,ifmReal
e9cb7ce
syntax region ifmEqString contained end=";" matchgroup=ifmStatement start="=" contains=ifmString
e9cb7ce
e9cb7ce
syntax keyword ifmIntIdent item_text_fontsize link_dashed link_line_width link_spline link_text_fontsize map_text_fontsize page_rotate room_border_dashed room_border_width room_exit_width room_text_fontsize show_border show_page_border show_items show_tags show_title show_page_title title_fontsize page_title_fontsize map_title_fontsize fit_page show_map_title map_section_spacing show_map_border show_joins keep_unused_items all_tasks_safe solver_messages task_graph_rooms task_graph_orphans skipwhite skipempty nextgroup=ifmEqInt
e9cb7ce
syntax keyword ifmRealIdent canvas_height canvas_width font_scale link_arrow_size page_height page_margin page_width room_height room_shadow_xoff room_shadow_yoff room_size room_width map_canvas_width map_canvas_height skipwhite skipempty nextgroup=ifmEqReal
e9cb7ce
syntax keyword ifmStringIdent canvas_background_colour colour_file item_text_colour item_text_font item_text_fontdef link_colour link_inout_string link_text_colour link_text_font link_text_fontdef link_updown_string map_text_colour map_text_font page_background_colour page_border_colour page_size prolog_file room_border_colour room_colour room_exit_colour room_shadow_colour room_text_colour room_text_font room_text_fontdef title_colour page_title_colour map_title_colour title_font page_title_font map_title_font map_border_colour map_background_colour join_format task_graph_attr task_graph_node task_graph_link skipwhite skipempty nextgroup=ifmEqString
e9cb7ce
e9cb7ce
syntax keyword ifmFormat ps tk text raw rec skipwhite skipempty nextgroup=ifmIntIdent,ifmRealIdent,ifmStringIdent
e9cb7ce
e9cb7ce
e9cb7ce
" Synchronization.
e9cb7ce
" Look backwards for a ';' but ignore any that occur in comments or
e9cb7ce
" strings.  Stop after going back 250 lines without finding a ';'
e9cb7ce
syntax sync match ifmSyncRoutine grouphere NONE ";"
e9cb7ce
syntax sync match ifmNoSyncComment "#.*"
e9cb7ce
syntax sync region ifmNoSyncString start=+"+ skip=+\\"+ end=+"+
e9cb7ce
syntax sync maxlines=250
e9cb7ce
e9cb7ce
e9cb7ce
if !exists("did_ifm_syntax_inits")
e9cb7ce
  let did_ifm_syntax_inits = 1
e9cb7ce
  " The default methods for highlighting.  Can be overridden later
e9cb7ce
  highlight link ifmStatement	Statement
e9cb7ce
  highlight link ifmRoomOpt	ifmKeyword
e9cb7ce
  highlight link ifmItemOpt	ifmKeyword
e9cb7ce
  highlight link ifmTaskOpt	ifmKeyword
e9cb7ce
  highlight link ifmLinkOpt	ifmKeyword
e9cb7ce
  highlight link ifmJoinOpt	ifmKeyword
e9cb7ce
  highlight link ifmExitOpt	ifmKeyword
e9cb7ce
  highlight link ifmDirFromOpt	ifmKeyword
e9cb7ce
  highlight link ifmFromOpt	ifmKeyword
e9cb7ce
  highlight link ifmGPPMode	ifmKeyword
e9cb7ce
  highlight link ifmKeyword	Type
e9cb7ce
  highlight link ifmGoDir	Constant
e9cb7ce
  highlight link ifmDirFromInt	ifmDirFrom
e9cb7ce
  highlight link ifmDirFrom	Constant
e9cb7ce
  highlight link ifmExitDir	Constant
e9cb7ce
  highlight link ifmInteger	Number
e9cb7ce
  highlight link ifmReal	Number
e9cb7ce
  highlight link ifmError	Error
e9cb7ce
  highlight link ifmString	String
e9cb7ce
  highlight link ifmComment	Comment
e9cb7ce
  highlight link ifmTodo	Todo
e9cb7ce
  highlight	 ifmId		term=bold cterm=bold gui=bold
e9cb7ce
  highlight link ifmFormat	Type
e9cb7ce
  highlight link ifmIntIdent	ifmIdent
e9cb7ce
  highlight link ifmRealIdent	ifmIdent
e9cb7ce
  highlight link ifmStringIdent	ifmIdent
e9cb7ce
  highlight link ifmIdent	Identifier
e9cb7ce
endif
e9cb7ce
e9cb7ce
let current_syntax = "ifm"
e9cb7ce
e9cb7ce
" ifm: ts=8