class TaskJuggler::KateSyntax
This class is a generator for Kate (kate-editor.org/) TaskJuggler syntax highlighting files.
Public Class Methods
new()
click to toggle source
Create a generator object.
# File lib/taskjuggler/KateSyntax.rb, line 22 def initialize # Create a syntax reference for all current keywords. @reference = SyntaxReference.new(nil, true) @properties = [] @attributes = [] @reference.keywords.each_value do |kw| if kw.isProperty? @properties << kw else @attributes << kw end end @file = nil end
Public Instance Methods
generate(file)
click to toggle source
Generate the Kate syntax file into file.
# File lib/taskjuggler/KateSyntax.rb, line 41 def generate(file) @file = File.open(file, 'w') header keywords contexts highlights footer @file.close end
Private Instance Methods
contexts()
click to toggle source
# File lib/taskjuggler/KateSyntax.rb, line 88 def contexts @file.write <<'EOT' <contexts> <context attribute="Normal Text" lineEndContext="#stay" name="Normal"> <!-- Date(+Time) values --> <RegExpr attribute="Date" String="\d{4}-\d{2}-\d{2}\S*"/> <!-- Time values --> <RegExpr attribute="Time" String="\d{1-2}:\d{2}(:\d{2}|)"/> <!-- Duration specifications --> <RegExpr attribute="Duration" String="\d(min|h|d|w|m|y)"/> <!-- keywords and other builtins --> <keyword attribute="Builtin Function" String="builtinfuncs" context="#stay"/> <keyword attribute="Keyword" String="keywords" context="#stay"/> <keyword attribute="Data Types" String="types" context="#stay"/> <!-- Include --> <RegExpr attribute="Include" String="include.*$"/> <!-- Arguments --> <RegExpr attribute="Arguments" String="\{.*}$"/> <!-- region (brace) folding --> <DetectChar attribute="Symbol" context="#stay" char="{" beginRegion="Brace2"/> <DetectChar attribute="Symbol" context="#stay" char="}" endRegion="Brace2"/> <DetectChar attribute="Symbol" context="#stay" char="[" beginRegion="Brace1"/> <DetectChar attribute="Symbol" context="#stay" char="]" endRegion="Brace1"/> <!-- number hilighting --> <Float attribute="Float" context="#stay"> <AnyChar String="fF" attribute="Float" context="#stay"/> </Float> <Int attribute="Decimal" context="#stay"> <StringDetect attribute="Decimal" context="#stay" String="ULL" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="LUL" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="LLU" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="UL" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="LU" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="LL" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="U" insensitive="TRUE"/> <StringDetect attribute="Decimal" context="#stay" String="L" insensitive="TRUE"/> </Int> <!-- strings --> <DetectChar attribute="String" context="String1" char="'"/> <DetectChar attribute="String" context="String2" char='"'/> <StringDetect attribute="String" context="String3" String="-8<-"/> <!-- comments --> <DetectChar attribute="Comment" context="Comment1" char="#"/> <Detect2Chars attribute="Comment" context="Comment2" char="/" char1="/"/> <Detect2Chars attribute="Comment" context="Comment3" char="/" char1="*"/> </context> <context attribute="String" lineEndContext="#stay" name="String1"> <DetectChar attribute="String" context="#pop" char="'"/> </context> <context attribute="String" lineEndContext="#stay" name="String2"> <DetectChar attribute="String" context="#pop" char='"'/> </context> <context attribute="String" lineEndContext="#stay" name="String3"> <StringDetect attribute="String" context="#pop" String="->8-"/> </context> <context attribute="Comment" lineEndContext="#pop" name="Comment1"> <IncludeRules context="##Alerts"/> </context> <context attribute="Comment" lineEndContext="#pop" name="Comment2"> <IncludeRules context="##Alerts"/> </context> <context attribute="Comment" lineEndContext="#stay" name="Comment3"> <Detect2Chars attribute="Comment" context="#pop" char="*" char1="/"/> </context> </contexts> EOT #syn match tjparg contained /\${.*}/ end
header()
click to toggle source
# File lib/taskjuggler/KateSyntax.rb, line 55 def header # Generate the header section. Mostly consists of comments and # description attributes @file.write <<"EOT" <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE language SYSTEM "language.dtd"> <language name="TaskJuggler" version="3.0" kateversion="2.1" section="Scripts" extensions="*.tjp;*.tji" author="TaskJuggler Developers <taskjuggler-devel@googlegroups.com>"> <highlighting> <!-- This file was automatically generated by KateSyntax.rb --> EOT end
highlights()
click to toggle source
# File lib/taskjuggler/KateSyntax.rb, line 190 def highlights @file.write <<'EOT' <itemDatas> <itemData name="Normal Text" defStyleNum="dsNormal"/> <itemData name="Keyword" defStyleNum="dsKeyword"/> <itemData name="Builtin Function" defStyleNum="dsFunction"/> <itemData name="Data Types" defStyleNum="dsDataType"/> <itemData name="Decimal" defStyleNum="dsDecVal"/> <itemData name="Float" defStyleNum="dsDecVal"/> <itemData name="Date" defStyleNum="dsBaseN"/> <itemData name="Time" defStyleNum="dsBaseN"/> <itemData name="String" defStyleNum="dsString"/> <itemData name="String Char" defStyleNum="dsChar"/> <itemData name="Comment" defStyleNum="dsComment"/> <itemData name="Symbol" defStyleNum="dsNormal"/> </itemDatas> EOT end
keywords()
click to toggle source
# File lib/taskjuggler/KateSyntax.rb, line 158 def keywords @file.puts "<list name=\"keywords\">" %w( macro project supplement include supplement ).each do |kw| @file.puts "<item> #{kw} </item>" end @file.puts "</list>" # Property keywords @file.puts "<list name=\"builtinfuncs\">" @properties.each do |kw| kw.names.each do |name| # Ignore the 'supplement' entries. They are not real properties. next if name == 'supplement' @file.puts "<item> #{name} </item>" end end @file.puts "</list>" # Attribute keywords @file.puts "<list name=\"types\">" @attributes.each do |kw| next if %w( resourcereport taskreport textreport ).include?(kw.keyword) single = kw.names.length == 1 kw.names.each do |name| break if [ '%', '(', '~', 'include', 'macro', 'project', 'supplement' ].include?(name) @file.puts "<item> #{name} </item>" end end @file.puts "</list>" end