In Files

Parent

Class Index [+]

Quicksearch

TaskJuggler::VimSyntax

This class is a generator for vim (www.vim.org) TaskJuggler syntax highlighting files.

Public Class Methods

new() click to toggle source

Create a generator object.

    # File lib/VimSyntax.rb, line 22
22:     def initialize
23:       @reference = SyntaxReference.new
24: 
25:       @properties = []
26:       @attributes = []
27:       @optionBlocks = []
28: 
29:       @reference.keywords.each_value do |kw|
30:         if kw.isProperty?
31:           @properties << kw
32:         else
33:           @attributes << kw
34:         end
35:         if !kw.optionalAttributes.empty?
36:           @optionBlocks << kw
37:         end
38:       end
39: 
40:       @file = nil
41:     end

Public Instance Methods

generate(file) click to toggle source

Generate the vim syntax file into file.

    # File lib/VimSyntax.rb, line 44
44:     def generate(file)
45:       @file = File.open(file, 'w')
46: 
47:       header
48:       setLocal
49:       keywords
50:       matches
51:       regions
52:       highlights
53: 
54:       @file.close
55:     end

Private Instance Methods

header() click to toggle source
    # File lib/VimSyntax.rb, line 59
59:     def header
60:       @file.write " Vim syntax file" Language:     TaskJuggler" Maintainer:   TaskJuggler Developers <taskjuggler-devel@googlegroups.com>" Last Change:  #{Time.now}" This file was automatically generated by VimSyntax.rbif exists("b:current_syntax")  finishendif
61:     end
highlights() click to toggle source
     # File lib/VimSyntax.rb, line 194
194:     def highlights
195:       @file.write hi def link tjp_macro PreProchi def link tjp_supplement Functionhi def link tjp_project Functionhi def link tjpproperty Functionhi def link tjpattribute Typehi def link tjparg Specialhi def link tjpstring Stringhi def link tjpcomment Commenthi def link tjpmlcomment Commenthi def link tjpinclude Includehi def link tjpdate Constanthi def link tjptime Constanthi def link tjpnumber Numberlet b:current_syntax = "tjp"
196:     end
keywords() click to toggle source
     # File lib/VimSyntax.rb, line 142
142:     def keywords
143:       %( macro project supplement ).each do |kw|
144:         @file.puts "syn keyword tjp_#{kw} #{kw} contained"
145:       end
146:       @file.puts
147: 
148:       # Property keywords
149:       @properties.each do |kw|
150:         single = kw.names.length == 1
151:         kw.names.each do |name|
152:           # Ignore the 'supplement' entries. They are not real properties.
153:           next if name == 'supplement'
154:           @file.puts "syn keyword tjp_#{normalize(kw.keyword)}" +
155:                      "#{single ? '' : "_#{name}"} #{name} contained"
156:           @file.puts "hi def link tjp_#{normalize(kw.keyword)}" +
157:                      "#{single ? '' : "_#{name}"} Function"
158:         end
159:       end
160:       @file.puts
161: 
162:       # Attribute keywords
163:       @attributes.each do |kw|
164:         next if %( resourcereport taskreport textreport ).include?(kw.keyword)
165:         single = kw.names.length == 1
166:         kw.names.each do |name|
167:           break if [ '%', '(', '~', 'include', 'macro', 'project',
168:                      'supplement' ].include?(name)
169:           @file.puts "syn keyword tjp_#{normalize(kw.keyword)}" +
170:                      "#{single ? '' : "_#{name}"} #{name}" +
171:                      "#{kw.globalScope? && !@optionBlocks.include?(kw) ?
172:                         '' : ' contained'}"
173:           @file.puts "hi def link tjp_#{normalize(kw.keyword)}" +
174:                      "#{single ? '' : "_#{name}"} Type"
175:         end
176:       end
177:       @file.puts
178:     end
matches() click to toggle source
     # File lib/VimSyntax.rb, line 180
180:     def matches
181:       @file.write syn match tjparg contained /\${.*}/syn match tjpcomment /#.*$/syn match tjpcomment "//.*$"syn match tjpinclude /include.*$/syn match tjpnumber /\s[-+]\?\d\+\(\.\d\+\)\?\([hdwmy]\|min\)\?/syn match tjpdate /\s\d\{4}-\d\{1,2}-\d\{1,2}\(-\d\{1,2}:\d\{1,2}\(:\d\{1,2}\)\?\(-[-+]\?\d\{4}\)\?\)\?/syn match tjptime /\s\d\{1,2}:\d\d\(:\d\d\)\?/syn cluster tjpcommon contains=tjpcomment,tjpdate,tjptime,tjpstring,tjpnumber
182:     end
normalize(str) click to toggle source
     # File lib/VimSyntax.rb, line 215
215:     def normalize(str)
216:       str.gsub(/\./, '_')
217:     end
regions() click to toggle source
     # File lib/VimSyntax.rb, line 93
 93:     def regions
 94:       @optionBlocks.each do |kw|
 95:         single = kw.names.length == 1
 96:         kw.names.each do |name|
 97:           normalizedName = "#{normalize(kw.keyword)}" +
 98:                            "#{single ? '' : "_#{name}"}"
 99:           tag = name == 'supplement' ?
100:                         kw.keyword.gsub(/\./, ' ') : name
101:           @file.write "syn region tjpblk_#{normalizedName}" +
102:                       " start=/^\\s*#{tag}\\s.*{/ end=/^\\s*}/ transparent"
103:           # We allow properties and special attributes to be folded.
104:           foldable = %( task.timesheet project )
105:           @file.write " fold" if @properties.include?(kw) ||
106:                                  foldable.include?(kw.keyword)
107:           # The header is part of the region. So we must make sure that common
108:           # parameters and the property/attribute name are contained as well.
109:           @file.write " contains=@tjpcommon,tjp_#{normalizedName}"
110:           kw.optionalAttributes.each do |oa|
111:             tag = normalize(oa.keyword)
112:             @file.write ",tjp_#{tag}"
113:             if !oa.optionalAttributes.empty?
114:               # Option blocks may be contained as block or non-block.
115:               @file.write ",tjpblk_#{tag}"
116:             end
117:           end
118:           if name == 'supplement'
119:             @file.write(',tjp_supplement')
120:           end
121:           if !kw.globalScope?
122:             # Every region but a property and 'project' is contained.
123:             @file.write " contained"
124:           end
125:           @file.puts
126:         end
127:       end
128: 
129:       @file.write syn region tjpblk_macro start=/macro\s\+\h\w*\s*\[/ end=/\]$/ transparent fold contains=ALLsyn region tjpstring start=/"/ skip=/\\"/ end=/"/syn region tjpstring start=/'/ skip=/\\'/ end=/'/syn region tjpstring start=/\s-8<-$/ end=/^\s*->8-/syn region tjpmlcomment start=+/\*+ end=+\*/+syn sync fromstartset foldmethod=syntax
130:     end
setLocal() click to toggle source
    # File lib/VimSyntax.rb, line 74
74:     def setLocal
75:       cinwords = []
76:       @optionBlocks.each { |kw| cinwords += kw.names }
77:       cinwords.uniq!.sort!
78:       @file.write setlocal softtabstop=2setlocal cindent shiftwidth=2setlocal tabstop=2setlocal expandtabsetlocal cinoptions=g0,t0,+0,(0,c0,C1
79:       @file.write "setlocal cinwords=#{cinwords.join(',')}\n"
80:       @file.write setlocal cinkeys=0{,0},!^F,o,Osetlocal cindent
81:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.