File: KateSyntax.rb

package info (click to toggle)
tj3 3.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,048 kB
  • sloc: ruby: 36,481; javascript: 1,113; sh: 19; makefile: 17
file content (213 lines) | stat: -rw-r--r-- 7,359 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = KateSyntax.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
#               by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'taskjuggler/SyntaxReference'

class TaskJuggler

  # This class is a generator for Kate (http://kate-editor.org/) TaskJuggler syntax
  # highlighting files.
  class KateSyntax

    # Create a generator object.
    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

    # Generate the Kate syntax file into _file_.
    def generate(file)
      @file = File.open(file, 'w')

      header
      keywords
      contexts
      highlights
      footer

      @file.close
    end

    private

    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 &lt;taskjuggler-devel@googlegroups.com&gt;">
<highlighting>
<!-- This file was automatically generated by KateSyntax.rb -->

EOT
    end

    def footer
      # Generate the footer section. Mostly consists of closing tags.
      @file.write <<"EOT"
</highlighting>
<general>
  <comments>
    <comment name="singleLine" start="#"/>
    <comment name="singleLine" start="//"/>
    <comment name="multiLine" start="/*" end="*/"/>
  </comments>
  <keywords casesensitive="0"/>
</general>
</language>
EOT
    end

    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&lt;-"/>
    <!-- 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="-&gt;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

    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

    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

  end

end