syntax 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ Syntax: a syntax highlighting library for Ruby.
2
+
3
+ 1.1.0 In Progress
4
+ Published from https://github.com/dblock/syntax, a now maintained fork.
5
+ The project builds again and runs, fixes by @dblock, @distler.
6
+
7
+ 1.0.0: 18 Jun 2005
8
+ Added user manual
9
+ Fixed various bugs
10
+
11
+ 0.7.0: 23 Mar 2005
12
+ Added Syntax.all to enumerate all supported syntaxes.
13
+ Much improved heredoc support.
14
+ Support for syntax "regions"
15
+ Added sample CSS files for the supported syntaxes
16
+ Added the example "to_html.rb" script
17
+ Bug fixes.
18
+
19
+ 0.5.0: 11 Jan 2005
20
+ First release.
21
+
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ * The names of its contributors may not be used to endorse or promote
15
+ products derived from this software without specific prior written
16
+ permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,49 @@
1
+ = Syntax
2
+
3
+ A syntax highlighting a library for Ruby.
4
+
5
+ This fork is maintained and version 1.1.0 has been published from it. However, there's currently none or not much new development going on here and the original author, @jamis[https://github.com/jamis], recommends using CodeRay[http://coderay.rubychan.de], over this library.
6
+
7
+ == About
8
+
9
+ This is a simple syntax highlighting library for Ruby. It is a naive syntax analysis tool, meaning that it does not "understand" the syntaxes of the languages it processes, but merely does some semi-intelligent pattern matching.
10
+
11
+ == Usage
12
+
13
+ There are primarily two uses for the Syntax library:
14
+
15
+ # Convert text from a supported syntax to a supported highlight format (like HTML).
16
+ # Tokenize text in a supported syntax and process the tokens directly.
17
+
18
+ === Highlighting a supported syntax
19
+
20
+ require 'syntax/convertors/html'
21
+
22
+ convertor = Syntax::Convertors::HTML.for_syntax "ruby"
23
+ puts convertor.convert( File.read( "file.rb" ) )
24
+
25
+ The above snippet will emit HTML, using spans and CSS to indicate the different highlight "groups". (Sample CSS files are included in the "data" directory.)
26
+
27
+ === Tokenize text
28
+
29
+ require 'syntax'
30
+
31
+ tokenizer = Syntax.load "ruby"
32
+ tokenizer.tokenize( File.read( "file.rb" ) ) do |token|
33
+ puts "group(#{token.group}, #{token.instruction}) lexeme(#{token})"
34
+ end
35
+
36
+ Tokenizing is straightforward process. Each time a new token is discovered by the tokenizer, it is yielded to the given block.
37
+
38
+ * <tt>token.group</tt> is the lexical group to which the token belongs. Each supported syntax may have it's own set of lexical groups.
39
+ * <tt>token.instruction</tt> is an instruction used to determine how this token should be treated. It will be <tt>:none</tt> for normal tokens, <tt>:region_open</tt> if the token starts a nested region, and <tt>:region_close</tt> if it closes the last opened region.
40
+ * <tt>token</tt> is itself a subclass of String, so you can use it just as you would a string. It represents the lexeme that was actually parsed.
41
+
42
+ == Releasing Syntax
43
+
44
+ * Update version in <tt>lib/syntax/version.rb</tt>.
45
+
46
+ * Build the gem, use Ruby 1.9.3.
47
+
48
+ rake clean
49
+ rake package
@@ -0,0 +1,69 @@
1
+ require 'syntax'
2
+
3
+ module Syntax
4
+
5
+ class AnsiC < Tokenizer
6
+
7
+ def self.add_type(name)
8
+ ANSIC_PREDEFINED_TYPES << name
9
+ end
10
+
11
+ ANSIC_KEYWORDS =
12
+ Set.new %w{asm break case continue default do else for goto if return
13
+ switch while struct union enum typedef static register
14
+ auto extern sizeof volatile const inline restrict} unless const_defined?(:ANSIC_KEYWORDS)
15
+
16
+ ANSIC_PREDEFINED_TYPES =
17
+ Set.new %w{int long short char void signed unsigned
18
+ float double bool complex} unless const_defined?(:ANSIC_PREDEFINED_TYPES)
19
+
20
+ ANSIC_PREDEFINED_CONSTANTS =
21
+ %w{EOF NULL true false} unless const_defined?(:ANSIC_PREDEFINED_CONSTANTS)
22
+
23
+ ANSIC_ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x unless const_defined?(:ANSIC_ESCAPE)
24
+
25
+ def step
26
+ case
27
+ when scan(/\s+/)
28
+ start_group :normal, matched
29
+ when match = scan(/#\s*(\w*)/)
30
+ match << scan_until(/\n/)
31
+ start_group :preprocessor, match
32
+ when scan(/ L?' (?: [^\'\n\\] | \\ #{ANSIC_ESCAPE} )? '? /ox)
33
+ start_group :char, matched
34
+ when scan(/0[xX][0-9A-Fa-f]+/)
35
+ start_group :hex, matched
36
+ when scan(/(?:0[0-7]+)(?![89.eEfF])/)
37
+ start_group :oct, matched
38
+ when scan(/(?:\d+)(?![.eEfF])/)
39
+ start_group :integer, matched
40
+ when scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
41
+ start_group :float, matched
42
+ when scan(/"(?:[^"\\]|\\.)*"/)
43
+ start_group :string, matched
44
+ when scan( %r{ ('(?: . | [\t\b\n] )') }x )
45
+ start_group :char, matched
46
+ when scan(/[a-z_][a-z_\d]+/)
47
+ if ANSIC_KEYWORDS.include?( matched )
48
+ start_group :keyword, matched
49
+ elsif ANSIC_PREDEFINED_TYPES.include?( matched )
50
+ start_group :predefined_types, matched
51
+ else
52
+ start_group :ident, matched
53
+ end
54
+ when scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
55
+ start_group :comment, matched
56
+ else
57
+ start_group :other, scan(/./x)
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ SYNTAX["ansic"] = AnsiC
64
+
65
+ end
66
+
67
+
68
+
69
+
@@ -0,0 +1,324 @@
1
+ require 'syntax'
2
+
3
+ module Syntax
4
+
5
+ class CSS21 < Tokenizer
6
+
7
+ CSS21_PROPERTIES = Set.new %w{font-family font-style font-variant font-weight
8
+ font-size font background-color background-image
9
+ background-repeat background-attachment background-position
10
+ color background word-spacing letter-spacing
11
+ border-top-width border-right-width border-left-width
12
+ border-bottom-width border-width list-style-type
13
+ list-style-image list-style-position text-decoration
14
+ vertical-align text-transform text-align text-indent
15
+ line-height margin-top margin-right margin-bottom
16
+ margin-left margin padding-top padding-right padding-bottom
17
+ padding-left padding border-top border-right border-bottom
18
+ border-left border width height float clear display
19
+ list-style white-space border-style border-color
20
+ azimuth border-bottom-color border-bottom-style
21
+ border-collapse border-left-color border-left-style
22
+ border-right-color border-right-style border-top-color
23
+ border-top-style caption-side cell-spacing clip column-span
24
+ content cue cue-after cue-before cursor direction
25
+ elevation font-size-adjust marks max-height max-width
26
+ min-height min-width orphans overflow page-break-after
27
+ page-break-before pause pause-after pause-before pitch
28
+ pitch-range play-during position richness right row-span
29
+ size speak speak-date speak-header speak-punctuation
30
+ speak-time speech-rate stress table-layout text-shadow top
31
+ visibility voice-family volume
32
+ widows z-index quotes
33
+ marker-offset outline outline-color outline-style outline-width
34
+ border-spacing border-collapse
35
+ page-break-before page-break-after page-break-inside
36
+ orphans widows} unless const_defined?(:CSS21_PROPERTIES)
37
+
38
+ CSS21_KEYWORDS = Set.new %w{maroon red orange yellow olive purple
39
+ fuchsia white lime green navy blue aqua teal black silver gray
40
+ scroll fixed transparent none top center bottom
41
+ left right repeat repeat-x repeat-y no-repeat
42
+ thin medium thick dotted dashed solid double groove ridge
43
+ inset outset both block inline list-item
44
+ xx-small x-small small medium large x-large xx-large
45
+ smaller italic oblique small-caps bold bolder lighter auto
46
+ disc circle square decimal lower-roman upper-roman lower-alpha
47
+ upper-alpha inside outside justify underline overline line-through
48
+ blink capitalize uppercase lowercase baseline sub super
49
+ top text-top middle bottom text-bottom pre nowrap
50
+ compact run-in inherit caption icon menu message-box small-caption
51
+ status-bar marker
52
+ table inline-table table-column-group table-column
53
+ table-row-group table-row table-cell table-caption
54
+ table-header-group table-footer-group
55
+ screen print projection braille embosed aural tv
56
+ tty handheld cross hidden open-quote close-quote
57
+ absolute relative normal collapse
58
+ serif sans-serif monospace cursive
59
+ fantasy, always} unless const_defined?(:CSS21_KEYWORDS)
60
+
61
+ HTML_TAGS = Set.new %w{a abbr address area article aside
62
+ audio b base bdo blockquote body br button canvas caption
63
+ cite code col colgroup command datalist dd del details dfn
64
+ div dl dt em embed fieldset figure footer form h1 h2 h3
65
+ h4 h5 h6 head header hgroup hr html i iframe img input ins
66
+ kbd keygen label legend li link map mark menu meta meter
67
+ nav noscript object ol optgroup option output p param pre
68
+ progress q rp rt ruby samp script section select small
69
+ source span strong style sub sup table tbody td textarea
70
+ tfoot th thead time title tr ul var video
71
+ acronym applet big center frame frameset isindex marquee
72
+ noframes s tt u} unless const_defined?(:HTML_TAGS)
73
+
74
+ MATHML_TAGS = Set.new %w{annotation annotation-xml maction
75
+ malign maligngroup malignmark malignscope math menclose
76
+ merror mfenced mfrac mglyph mi mlabeledtr mlongdiv mmultiscripts
77
+ mn mo mover mpadded mphantom mprescripts mroot mrow ms mscarries
78
+ mscarry msgroup msline mspace msqrt msrow mstack mstyle msub
79
+ msubsup msup mtable mtd mtext mtr munder munderover none
80
+ semantics} unless const_defined?(:MATHML_TAGS)
81
+
82
+ SVG_TAGS = Set.new %w{a altGlyph altGlyphDef altGlyphItem animate
83
+ animateColor animateMotion animateTransform circle clipPath
84
+ color-profile cursor definition-src defs desc ellipse feBlend
85
+ feColorMatrix feComponentTransfer feComposite feConvolveMatrix
86
+ feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA
87
+ feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode
88
+ feMorphology feOffset fePointLight feSpecularLighting feSpotLight
89
+ feTile feTurbulence filter font font-face font-face-format
90
+ font-face-name font-face-src font-face-uri foreignObject g glyph
91
+ glyphRef hkern image line linearGradient marker mask metadata
92
+ missing-glyph mpath path pattern polygon polyline radialGradient
93
+ rect script set stop style svg switch symbol text textPath title
94
+ tref tspan use view vkern} unless const_defined?(:SVG_TAGS)
95
+
96
+ MY_TAGS = HTML_TAGS + MATHML_TAGS + SVG_TAGS unless const_defined?(:MY_TAGS)
97
+
98
+ def setup
99
+ @selector = true
100
+ @macros = {}
101
+ @tokens = {}
102
+
103
+ # http://www.w3.org/TR/CSS21/syndata.html
104
+ macro(:h, /([0-9a-fA-F])/ ) # uppercase A-Z added?
105
+ macro(:nonascii, /([^\000-\177])/ )
106
+ macro(:nl, /(\n|\r\n|\r|\f)/ )
107
+ macro(:unicode, /(\\#{m(:h)}{1,6}(\r\n|[ \t\r\n\f])?)/ )
108
+ macro(:escape, /(#{m(:unicode)}|\\[^\r\n\f0-9a-f])/ )
109
+ macro(:nmstart, /([_a-z]|#{m(:nonascii)}|#{m(:escape)})/ )
110
+ macro(:nmchar, /([_a-z0-9-]|#{m(:nonascii)}|#{m(:escape)})/ )
111
+ macro(:string1, /(\"([^\n\r\f\\\"]|\\#{m(:nl)}|#{m(:escape)})*\")/ )
112
+ macro(:string2, /(\'([^\n\r\f\\']|\\#{m(:nl)}|#{m(:escape)})*\')/ )
113
+ macro(:invalid1, /(\"([^\n\r\f\\\"]|\\#{m(:nl)}|#{m(:escape)})*)/ )
114
+ macro(:invalid2, /(\'([^\n\r\f\\']|\\#{m(:nl)}|#{m(:escape)})*)/ )
115
+ macro(:comment, /(\/\*[^*]*\*+([^\/*][^*]*\*+)*\/)/ )
116
+ macro(:ident, /(-?#{m(:nmstart)}#{m(:nmchar)}*)/ )
117
+ macro(:name, /(#{m(:nmchar)}+)/ )
118
+ macro(:num, /([0-9]+|[0-9]*\.[0-9]+)/ )
119
+ macro(:string, /(#{m(:string1)}|#{m(:string2)})/ )
120
+ macro(:invalid, /(#{m(:invalid1)}|#{m(:invalid2)})/ )
121
+ macro(:s, /([ \t\r\n\f]+)/ )
122
+ macro(:w, /(#{m(:s)}?)/ )
123
+ macro(:A, /(a|\\0{0,4}(41|61)(\r\n|[ \t\r\n\f])?)/ )
124
+ macro(:C, /(c|\\0{0,4}(43|63)(\r\n|[ \t\r\n\f])?)/ )
125
+ macro(:D, /(d|\\0{0,4}(44|64)(\r\n|[ \t\r\n\f])?)/ )
126
+ macro(:E, /(e|\\0{0,4}(45|65)(\r\n|[ \t\r\n\f])?)/ )
127
+ macro(:G, /(g|\\0{0,4}(47|67)(\r\n|[ \t\r\n\f])?|\\g)/ )
128
+ macro(:H, /(h|\\0{0,4}(48|68)(\r\n|[ \t\r\n\f])?|\\h)/ )
129
+ macro(:I, /(i|\\0{0,4}(49|69)(\r\n|[ \t\r\n\f])?|\\i)/ )
130
+ macro(:K, /(k|\\0{0,4}(4b|6b)(\r\n|[ \t\r\n\f])?|\\k)/ )
131
+ macro(:M, /(m|\\0{0,4}(4d|6d)(\r\n|[ \t\r\n\f])?|\\m)/ )
132
+ macro(:N, /(n|\\0{0,4}(4e|6e)(\r\n|[ \t\r\n\f])?|\\n)/ )
133
+ macro(:O, /(o|\\0{0,4}(51|71)(\r\n|[ \t\r\n\f])?|\\o)/ )
134
+ macro(:P, /(p|\\0{0,4}(50|70)(\r\n|[ \t\r\n\f])?|\\p)/ )
135
+ macro(:R, /(r|\\0{0,4}(52|72)(\r\n|[ \t\r\n\f])?|\\r)/ )
136
+ macro(:S, /(s|\\0{0,4}(53|73)(\r\n|[ \t\r\n\f])?|\\s)/ )
137
+ macro(:T, /(t|\\0{0,4}(54|74)(\r\n|[ \t\r\n\f])?|\\t)/ )
138
+ macro(:X, /(x|\\0{0,4}(58|78)(\r\n|[ \t\r\n\f])?|\\x)/ )
139
+ macro(:Z, /(z|\\0{0,4}(5a|7a)(\r\n|[ \t\r\n\f])?|\\z)/ )
140
+
141
+ token(:COMMENT, /#{m(:comment)}/)
142
+
143
+ token(:HASH, /\#/)
144
+ token(:IDENT, /#{m(:ident)}/)
145
+ token(:LBRACE, /#{m(:w)}\{/)
146
+ token(:RBRACE, /#{m(:w)}\}/)
147
+
148
+ token(:S, /#{m(:s)}/)
149
+
150
+ token(:FUNCTION, /#{m(:ident)}(?=\()/)
151
+
152
+ token(:PLUS, /#{m(:w)}\+/)
153
+ token(:GREATER, /#{m(:w)}>/)
154
+ token(:COMMA, /#{m(:w)},/)
155
+
156
+ token(:CDO, /<!--/)
157
+ token(:CDC, /-->/)
158
+ token(:INCLUDES, /~=/)
159
+ token(:DASHMATCH, /\|=/)
160
+ token(:STRING, /#{m(:string)}/)
161
+ token(:INVALID, /#{m(:invalid)}/)
162
+ token(:IMPORT_SYM, /@#{m(:I)}#{m(:M)}#{m(:P)}#{m(:O)}#{m(:R)}#{m(:T)}/)
163
+ token(:PAGE_SYM, /@#{m(:P)}#{m(:A)}#{m(:G)}#{m(:E)}/)
164
+ token(:MEDIA_SYM, /@#{m(:M)}#{m(:E)}#{m(:D)}#{m(:I)}#{m(:A)}/)
165
+ token(:CHARSET_SYM, /@#{m(:C)}#{m(:H)}#{m(:A)}#{m(:R)}#{m(:S)}#{m(:E)}#{m(:T)}/)
166
+ token(:IMPORTANT_SYM, /!(#{m(:w)}|#{m(:comment)})*#{m(:I)}#{m(:M)}#{m(:P)}#{m(:O)}#{m(:R)}#{m(:T)}#{m(:A)}#{m(:N)}#{m(:T)}/)
167
+ token(:EMS, /#{m(:num)}#{m(:E)}#{m(:M)}/)
168
+ token(:EXS, /#{m(:num)}#{m(:E)}#{m(:X)}/)
169
+
170
+ token :LENGTH do |patterns|
171
+ patterns << /#{m(:num)}#{m(:P)}#{m(:X)}/
172
+ patterns << /#{m(:num)}#{m(:C)}#{m(:M)}/
173
+ patterns << /#{m(:num)}#{m(:M)}#{m(:M)}/
174
+ patterns << /#{m(:num)}#{m(:I)}#{m(:N)}/
175
+ patterns << /#{m(:num)}#{m(:P)}#{m(:T)}/
176
+ patterns << /#{m(:num)}#{m(:P)}#{m(:C)}/
177
+ end
178
+
179
+ token :ANGLE do |patterns|
180
+ patterns << /#{m(:num)}#{m(:D)}#{m(:E)}#{m(:G)}/
181
+ patterns << /#{m(:num)}#{m(:R)}#{m(:A)}#{m(:D)}/
182
+ patterns << /#{m(:num)}#{m(:G)}#{m(:R)}#{m(:A)}#{m(:D)}/
183
+ end
184
+
185
+ token :TIME do |patterns|
186
+ patterns << /#{m(:num)}#{m(:M)}#{m(:S)}/
187
+ patterns << /#{m(:num)}#{m(:S)}/
188
+ end
189
+
190
+ token :FREQ do |patterns|
191
+ patterns << /#{m(:num)}#{m(:H)}#{m(:Z)}/
192
+ patterns << /#{m(:num)}#{m(:K)}#{m(:H)}#{m(:Z)}/
193
+ end
194
+
195
+ token :URI do |patterns|
196
+ patterns << /url\(#{m(:w)}#{m(:string)}#{m(:w)}\)/
197
+ patterns << /url\(#{m(:w)}([!$%&*-~]|#{m(:nonascii)}|#{m(:escape)})*#{m(:w)}\)/
198
+ end
199
+
200
+ token(:DIMENSION, /#{m(:num)}#{m(:ident)}/)
201
+ token(:PERCENTAGE, /#{m(:num)}%/)
202
+ token(:HEXNUM, /##{m(:h)}{2,6}/)
203
+ token(:NUMBER, /#{m(:num)}/)
204
+
205
+ end
206
+
207
+ def step
208
+
209
+ case
210
+
211
+ # scanning selectors only
212
+ when @selector && scan(@tokens[:LBRACE])
213
+ @selector = false
214
+ start_group :normal, matched
215
+ when @selector && scan(@tokens[:IMPORT_SYM])
216
+ start_group :import, matched
217
+ when @selector && scan(@tokens[:PAGE_SYM])
218
+ start_group :page, matched
219
+ when @selector && scan(@tokens[:MEDIA_SYM])
220
+ start_group :media, matched
221
+ when @selector && scan(@tokens[:CHARSET_SYM])
222
+ start_group :charset, matched
223
+ when @selector && scan(@tokens[:HASH])
224
+ start_group :normal, matched
225
+ when @selector && scan(@tokens[:URI])
226
+ start_group :uri, matched
227
+
228
+ when @selector && scan(@tokens[:IDENT])
229
+ if MY_TAGS.include?( matched )
230
+ start_group :tag, matched
231
+ else
232
+ start_group :ident, matched
233
+ end
234
+
235
+ # scanning declarations only
236
+ when !@selector && scan(@tokens[:RBRACE])
237
+ @selector = true
238
+ start_group :normal, matched
239
+ when !@selector && scan(@tokens[:FUNCTION])
240
+ start_group :function, matched
241
+ when !@selector && scan(@tokens[:EMS])
242
+ start_group :ems, matched
243
+ when !@selector && scan(@tokens[:EXS])
244
+ start_group :exs, matched
245
+ when !@selector && scan(@tokens[:LENGTH])
246
+ start_group :length, matched
247
+ when !@selector && scan(@tokens[:ANGLE])
248
+ start_group :angle, matched
249
+ when !@selector && scan(@tokens[:TIME])
250
+ start_group :time, matched
251
+ when !@selector && scan(@tokens[:FREQ])
252
+ start_group :freq, matched
253
+ when !@selector && scan(@tokens[:PERCENTAGE])
254
+ start_group :percentage, matched
255
+ when !@selector && scan(@tokens[:DIMENSION])
256
+ start_group :dimension, matched
257
+ when !@selector && scan(@tokens[:NUMBER])
258
+ start_group :number, matched
259
+ when !@selector && scan(@tokens[:HEXNUM])
260
+ start_group :number, matched
261
+ when !@selector && scan(@tokens[:IMPORTANT_SYM])
262
+ start_group :important, matched
263
+
264
+ when !@selector && scan(@tokens[:IDENT])
265
+ if CSS21_PROPERTIES.include?( matched ) # are they disjoint?
266
+ start_group :property, matched
267
+ elsif CSS21_KEYWORDS.include?( matched )
268
+ start_group :keyword, matched
269
+ else
270
+ start_group :ident, matched
271
+ end
272
+
273
+ # scanning both
274
+ when scan(@tokens[:S])
275
+ start_group :normal, matched
276
+ when scan(@tokens[:COMMENT])
277
+ start_group :comment, matched
278
+ when scan(@tokens[:STRING])
279
+ start_group :string, matched
280
+ when scan(@tokens[:CDO])
281
+ start_group :cdo, matched
282
+ when scan(@tokens[:CDC])
283
+ start_group :cdc, matched
284
+ when scan(@tokens[:INVALID])
285
+ start_group :invalid, matched
286
+ else
287
+ start_group :normal, scan(/./x)
288
+ end
289
+
290
+ end
291
+
292
+ private
293
+
294
+ def macro(name, regex=nil)
295
+ regex ? @macros[name] = regex : @macros[name].source
296
+ end
297
+
298
+ def token(name, pattern=nil, &block)
299
+ raise ArgumentError, "name required" unless name
300
+
301
+ patterns = []
302
+ patterns << pattern if pattern
303
+ yield(patterns) if block_given?
304
+ if patterns.empty?
305
+ raise ArgumentError, "at least one pattern required"
306
+ end
307
+ patterns.collect! do |pattern|
308
+ source = pattern.source
309
+ source = "\\A#{source}"
310
+ Regexp.new(source, Regexp::IGNORECASE + Regexp::MULTILINE)
311
+ end
312
+
313
+ @tokens[name] = Regexp.union(*patterns)
314
+ end
315
+
316
+ alias :m :macro
317
+
318
+ end
319
+
320
+ SYNTAX["css21"] = CSS21
321
+
322
+ end
323
+
324
+
@@ -0,0 +1,149 @@
1
+ # fortran.rb -- a free-form Fortran module for the Ruby Syntax library
2
+ #
3
+ # Copyright (C) 2009-2010 Jason Blevins
4
+ # License: 3-clause BSD (the same as Syntax itself)
5
+
6
+ require 'syntax'
7
+
8
+ module Syntax
9
+
10
+ # A tokenizer for free-form Fortran source code.
11
+ class Fortran < Tokenizer
12
+
13
+ # Fortran keywords
14
+ LC_KEYWORDS =
15
+ %w{ assign backspace call close common continue data dimension do
16
+ else end endfile endif enddo entry equivalence external
17
+ format function goto if implicit inquire intrinsic open
18
+ parameter pause print program read return rewind
19
+ save stop subroutine then write } +
20
+ [ "block data", "go to" ] +
21
+ # Fortran 90 keywords
22
+ %w{ allocate allocatable case contains cycle deallocate
23
+ elsewhere exit include interface intent module namelist nullify
24
+ only operator optional pointer private procedure public
25
+ result recursive select sequence target type use while where } +
26
+ # Fortran 95 keywords
27
+ %w{ elemental forall pure } +
28
+ # Fortran 2003 keywords
29
+ %w{ abstract associate asynchronous bind class deferred enum enumerator
30
+ extends final flush generic import non_overridable nopass pass
31
+ protected value volatile wait } +
32
+ # Fortran 2008 keywords
33
+ %w{ block codimension concurrent contiguous critical submodule
34
+ lock unlock } +
35
+ [ "error stop", "sync all", "sync images", "sync memory" ]
36
+
37
+ # List of identifiers recognized as types
38
+ LC_TYPES = [ "character", "complex", "logical", "integer", "real",
39
+ "double precision" ]
40
+
41
+ # Fortran intrinsic procedures
42
+ LC_INTRINSICS = %w{
43
+ abs achar acos acosh adjustl adjustr aimag
44
+ aint all allocated anint any asin asinh
45
+ associated atan atan2 atanh atomic_define atomic_ref
46
+ bessel_j0 bessel_j1 bessel_jn
47
+ bessel_y0 bessel_y1 bessel_yn
48
+ bit_size btest
49
+ bge bgt ble blt
50
+ c_associated c_f_pointer c_f_procpointer
51
+ c_funloc c_loc c_sizeof
52
+ ceiling char cmplx command_argument_count
53
+ compiler_version compiler_options
54
+ conjg cos cosh count cpu_time cshift
55
+ date_and_time dble digits dim dot_product dprod
56
+ dshiftl dshiftr
57
+ eoshift epsilon erf erfc erfc_scaled exp exponent
58
+ execute_command_line extends_type_of
59
+ findloc float floor fraction
60
+ gamma get_command get_command_argument
61
+ get_environment_variable
62
+ huge hypot
63
+ iachar iall iand iany ibclr ibits ibset ichar image_index
64
+ int ior iparity is_contiguous is_iostat_end is_iostat_eor
65
+ ishft ishftc
66
+ kind
67
+ lbound lcobound leadz len len_trim lge lgt lle llt
68
+ log log10 log_gamma logical
69
+ maskl maskr matmul max maxexponent maxloc maxval merge merge_bits
70
+ min minexponent minloc minval mod modulo
71
+ move_alloc mvbits
72
+ nearest new_line nint norm2 not null num_images
73
+ pack parity popcnt poppar precision present product
74
+ radix random_number random_seed range real
75
+ repeat reshape rrspacing
76
+ same_type_as scale scan selected_char_kind selected_int_kind
77
+ selected_real_kind set_exponent shape shiftl shiftr sign
78
+ sin sinh size sngl spacing spread sqrt storage_size sum system_clock
79
+ tan tanh this_image tiny trailz transfer transpose trim
80
+ ubound ucobound unpack
81
+ verify
82
+ }
83
+
84
+ # Also support all uppercase keywords, types, and procedures
85
+ KEYWORDS = Set.new LC_KEYWORDS + LC_KEYWORDS.map { |x| x.upcase }
86
+ TYPES = Set.new LC_TYPES + LC_TYPES.map { |x| x.upcase }
87
+ INTRINSICS = Set.new LC_INTRINSICS + LC_INTRINSICS.map { |x| x.upcase }
88
+
89
+ # Step through a single iteration of the tokenization process.
90
+ def step
91
+ case
92
+ when check( /program\s+/ )
93
+ start_group :keyword, scan( /program\s+/ )
94
+ start_group :function, scan_until( /(?=[;(\s]|#{EOL})/ )
95
+ when check( /subroutine\s+/ )
96
+ start_group :keyword, scan( /subroutine\s+/ )
97
+ start_group :function, scan_until( /(?=[;(\s]|#{EOL})/ )
98
+ when check( /function\s+/ )
99
+ start_group :keyword, scan( /function\s+/ )
100
+ start_group :function, scan_until( /(?=[;(\s]|#{EOL})/ )
101
+ when check( /module\s+/ )
102
+ start_group :keyword, scan( /module\s+/ )
103
+ start_group :function, scan_until( /(?=[;\s]|#{EOL})/ )
104
+ when check( /\.true\.|\.false\.|\.TRUE\.|\.FALSE\./ )
105
+ start_group :constant,
106
+ scan(/\.true\.|\.false\.|\.TRUE\.|\.FALSE\./)
107
+ when scan( /(\d+\.?\d*|\d*\.?\d+)([eEdDqQ][+-]?\d+)?(_\w+)?/ )
108
+ start_group :number, matched
109
+ when scan( /[bB]\'[01]+\'|[oO]\'[0-7]+\'|[zZ]\'[0-9a-fA-F]+\'/ )
110
+ start_group :number, matched
111
+ else
112
+ case peek(1)
113
+ when /[\n\r]/
114
+ start_group :normal, scan( /\s+/ )
115
+ when /\s/
116
+ start_group :normal, scan( /\s+/ )
117
+ when "!"
118
+ start_group :comment, scan( /![^\n\r]*/ )
119
+ when /[A-Za-z]/
120
+ word = scan( /\w+/ )
121
+ if KEYWORDS.include?(word)
122
+ start_group :keyword, word
123
+ elsif TYPES.include?(word)
124
+ start_group :type, word
125
+ elsif INTRINSICS.include?(word)
126
+ start_group :function, word
127
+ elsif
128
+ start_group :ident, word
129
+ end
130
+ when '"'
131
+ # allow for continuation characters within strings
132
+ start_group :string, scan(/"([^"]*(&[ ]*[\n\r]+)?)*"/)
133
+ when "'"
134
+ # allow for continuation characters within strings
135
+ start_group :string, scan(/'([^']*(&[ ]*[\n\r]+)?)*'/)
136
+ when /[-!?*\/+=<>()\[\]\{}:;,&|%]/
137
+ start_group :punct, scan(/./)
138
+ else
139
+ # pass everything else through
140
+ append getch
141
+ end
142
+ end
143
+ end
144
+
145
+ end
146
+
147
+ SYNTAX["fortran"] = Fortran
148
+
149
+ end
@@ -0,0 +1,58 @@
1
+ require 'syntax'
2
+
3
+ module Syntax
4
+
5
+ class Javascript < Tokenizer
6
+
7
+ JAVASCRIPT_KEYWORDS =
8
+ Set.new %w{abstract break case catch class const continue
9
+ debugger default delete do else enum export extends
10
+ final finally for function goto if implements
11
+ import in instanceof interface native new
12
+ package private protected public return
13
+ static super switch synchronized this throw
14
+ throws transient try typeof
15
+ var void volatile while with} unless const_defined?(:JAVASCRIPT_KEYWORDS)
16
+
17
+ JAVASCRIPT_PREDEFINED_TYPES =
18
+ Set.new %w{boolean byte char double float int long short} unless const_defined?(:JAVASCRIPT_PREDEFINED_TYPES)
19
+
20
+ JAVASCRIPT_PREDEFINED_CONSTANTS =
21
+ %w{null true false} unless const_defined?(:JAVASCRIPT_PREDEFINED_CONSTANTS)
22
+
23
+ def step
24
+ case
25
+ when scan(/\s+/)
26
+ start_group :normal, matched
27
+ when scan(/\\u[0-9a-f]{4}/i)
28
+ start_group :unicode, matched
29
+ when scan(/0[xX][0-9A-Fa-f]+/)
30
+ start_group :hex, matched
31
+ when scan(/(?:0[0-7]+)(?![89.eEfF])/)
32
+ start_group :oct, matched
33
+ when scan(/(?:\d+)(?![.eEfF])/)
34
+ start_group :integer, matched
35
+ when scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
36
+ start_group :float, matched
37
+ when (scan(/"(?:[^"\\]|\\.)*"/) or scan(/'(?:[^'\\]|\\.)*'/) )
38
+ start_group :string, matched
39
+ when scan(/[a-z_$][a-z_\d]*/i)
40
+ if JAVASCRIPT_KEYWORDS.include?( matched )
41
+ start_group :keyword, matched
42
+ elsif JAVASCRIPT_PREDEFINED_TYPES.include?( matched )
43
+ start_group :predefined_types, matched
44
+ else
45
+ start_group :ident, matched
46
+ end
47
+ when scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
48
+ start_group :comment, matched
49
+ else
50
+ start_group :other, scan(/./x)
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ SYNTAX["javascript"] = Javascript
57
+
58
+ end
@@ -9,7 +9,7 @@ module Syntax
9
9
 
10
10
  # The list of all identifiers recognized as keywords.
11
11
  KEYWORDS =
12
- %w{if then elsif else end begin do rescue ensure while for
12
+ Set.new %w{if then elsif else end begin do rescue ensure while for
13
13
  class module def yield raise until unless and or not when
14
14
  case super undef break next redo retry in return alias
15
15
  defined?}
@@ -0,0 +1,77 @@
1
+ require 'syntax'
2
+
3
+ module Syntax
4
+
5
+ class SQLite < Tokenizer
6
+
7
+ def self.add_function(name)
8
+ SQLite_PREDEFINED_FUNCTIONS << name
9
+ end
10
+
11
+ SQLite_PREDEFINED_FUNCTIONS = Set.new %w{abs avg coalesce count glob
12
+ hex ifnull last_insert_rowid length like load_extension lower
13
+ ltrim max min sum nullif
14
+ quote random randomblob replace round
15
+ rtrim soundex sqlite_version substr total
16
+ trim typeof upper zeroblob
17
+ date time datetime julianday
18
+ strftime over} unless const_defined?(:SQLite_PREDEFINED_FUNCTIONS)
19
+
20
+ SQLite_KEYWORDS = Set.new %w{abort add after all alter analyze
21
+ asc attach autoincrement before by cascade change character
22
+ check commit conflict constraint create cross collate
23
+ current_date current_time current_timestamp database default
24
+ deferrable deferred delete desc detach distinct drop each
25
+ escape except exclusive explain fail for foreign from
26
+ full group having if ignore immediate
27
+ index initially inner insert instead intersect into is
28
+ join key left limit modify natural of offset on or order
29
+ outer plan pragma primary query raise references reindex
30
+ rename replace restrict right rollback row select set
31
+ table temp temporary to transaction trigger union
32
+ unique update using vacuum values view virtual
33
+ where partition} unless const_defined?(:SQLite_KEYWORDS)
34
+
35
+ SQLite_DATATYPES = Set.new %w{null none text numeric integer
36
+ text blob int varchar char real float
37
+ double} unless const_defined?(:SQLite_DATATYPES)
38
+
39
+ SQLite_OPERATORS = Set.new %w{not escape isnull notnull between and
40
+ in exists case when then else begin end cast as
41
+ like glob regexp < > || * / % + - << >>
42
+ & | <= >= = == != <>
43
+ match} unless const_defined?(:SQLite_OPERATORS)
44
+
45
+ def step
46
+ case
47
+ when scan(/\s+/)
48
+ start_group :normal, matched
49
+ when scan(%r{ "(?: \\. | \\" | [^"\n])*" }x)
50
+ start_group :string, matched
51
+ when scan(%r{ '(?: \\. | \\' | [^'\n])*' }x )
52
+ start_group :string, matched
53
+ when (scan(/[a-z_][a-z_\d]+/i) or scan(/[<>\|\*%&!=]+/))
54
+ m = matched.downcase
55
+ if SQLite_PREDEFINED_FUNCTIONS.include?( m )
56
+ start_group :function, matched
57
+ elsif SQLite_KEYWORDS.include?( m )
58
+ start_group :keyword, matched
59
+ elsif SQLite_DATATYPES.include?( m )
60
+ start_group :datatype, matched
61
+ elsif SQLite_OPERATORS.include?( m )
62
+ start_group :operator, matched
63
+ else
64
+ start_group :ident, matched
65
+ end
66
+ when scan(/--.*$/)
67
+ start_group :comment, matched
68
+ else
69
+ start_group :other, scan(/./x)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ SYNTAX["sqlite"] = SQLite
76
+
77
+ end
@@ -61,6 +61,7 @@ module Syntax
61
61
  indent = check(/ */)
62
62
  start_group :string
63
63
  loop do
64
+ break if eos?
64
65
  line = check_until(/[\n\r]|\Z/)
65
66
  break if line.nil?
66
67
  if line.chomp.length > 0
@@ -1,7 +1,7 @@
1
1
  module Syntax
2
2
  module Version
3
3
  MAJOR=1
4
- MINOR=0
4
+ MINOR=1
5
5
  TINY=0
6
6
 
7
7
  STRING=[MAJOR,MINOR,TINY].join('.')
@@ -2,4 +2,4 @@
2
2
  $:.unshift "../lib"
3
3
 
4
4
  Dir.chdir File.dirname(__FILE__)
5
- Dir["**/tc_*.rb"].each { |file| load file }
5
+ Dir["**/tc_*.rb"].each { |file| load File.expand_path(file) }
metadata CHANGED
@@ -1,58 +1,67 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: syntax
5
- version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2005-06-18
8
- summary: Syntax is Ruby library for performing simple syntax highlighting.
9
- require_paths:
10
- - lib
11
- email: jamis@jamisbuck.org
12
- homepage:
13
- rubyforge_project:
14
- description:
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jamis Buck
15
9
  autorequire: syntax
16
- default_executable:
17
10
  bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
25
- version:
26
- platform: ruby
27
- authors:
28
- - Jamis Buck
29
- files:
30
- - data/ruby.css
31
- - data/xml.css
32
- - data/yaml.css
33
- - lib/syntax
34
- - lib/syntax.rb
35
- - lib/syntax/common.rb
36
- - lib/syntax/convertors
37
- - lib/syntax/lang
38
- - lib/syntax/version.rb
39
- - lib/syntax/convertors/abstract.rb
40
- - lib/syntax/convertors/html.rb
41
- - lib/syntax/lang/ruby.rb
42
- - lib/syntax/lang/xml.rb
43
- - lib/syntax/lang/yaml.rb
44
- - test/ALL-TESTS.rb
45
- - test/syntax
46
- - test/tc_syntax.rb
47
- - test/syntax/tc_ruby.rb
48
- - test/syntax/tc_xml.rb
49
- - test/syntax/tc_yaml.rb
50
- - test/syntax/tokenizer_testcase.rb
51
- test_files:
52
- - test/ALL-TESTS.rb
53
- rdoc_options: []
54
- extra_rdoc_files: []
11
+ cert_chain: []
12
+ date: 2013-12-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: jamis@jamisbuck.org
55
16
  executables: []
56
17
  extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/syntax/common.rb
21
+ - lib/syntax/convertors/abstract.rb
22
+ - lib/syntax/convertors/html.rb
23
+ - lib/syntax/lang/ansic.rb
24
+ - lib/syntax/lang/css21.rb
25
+ - lib/syntax/lang/fortran.rb
26
+ - lib/syntax/lang/javascript.rb
27
+ - lib/syntax/lang/ruby.rb
28
+ - lib/syntax/lang/sqlite.rb
29
+ - lib/syntax/lang/xml.rb
30
+ - lib/syntax/lang/yaml.rb
31
+ - lib/syntax/version.rb
32
+ - lib/syntax.rb
33
+ - test/ALL-TESTS.rb
34
+ - test/syntax/tc_ruby.rb
35
+ - test/syntax/tc_xml.rb
36
+ - test/syntax/tc_yaml.rb
37
+ - test/syntax/tokenizer_testcase.rb
38
+ - test/tc_syntax.rb
39
+ - README.rdoc
40
+ - LICENSE
41
+ - CHANGELOG
42
+ homepage:
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
57
60
  requirements: []
58
- dependencies: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.25
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Syntax is Ruby library for performing simple syntax highlighting.
66
+ test_files:
67
+ - test/ALL-TESTS.rb
@@ -1,18 +0,0 @@
1
- .ruby .normal {}
2
- .ruby .comment { color: #005; font-style: italic; }
3
- .ruby .keyword { color: #A00; font-weight: bold; }
4
- .ruby .method { color: #077; }
5
- .ruby .class { color: #074; }
6
- .ruby .module { color: #050; }
7
- .ruby .punct { color: #447; font-weight: bold; }
8
- .ruby .symbol { color: #099; }
9
- .ruby .string { color: #944; background: #FFE; }
10
- .ruby .char { color: #F07; }
11
- .ruby .ident { color: #004; }
12
- .ruby .constant { color: #07F; }
13
- .ruby .regex { color: #B66; background: #FEF; }
14
- .ruby .number { color: #F99; }
15
- .ruby .attribute { color: #7BB; }
16
- .ruby .global { color: #7FB; }
17
- .ruby .expr { color: #227; }
18
- .ruby .escape { color: #277; }
@@ -1,8 +0,0 @@
1
- .xml .normal {}
2
- .xml .namespace { color: #B66; font-weight: bold; }
3
- .xml .tag { color: #F88; }
4
- .xml .comment { color: #005; font-style: italic; }
5
- .xml .punct { color: #447; font-weight: bold; }
6
- .xml .string { color: #944; }
7
- .xml .number { color: #F99; }
8
- .xml .attribute { color: #BB7; }
@@ -1,12 +0,0 @@
1
- .yaml .normal {}
2
- .yaml .document { font-weight: bold; color: #07F; }
3
- .yaml .type { font-weight: bold; color: #05C; }
4
- .yaml .key { color: #F88; }
5
- .yaml .comment { color: #005; font-style: italic; }
6
- .yaml .punct { color: #447; font-weight: bold; }
7
- .yaml .string { color: #944; }
8
- .yaml .number { color: #F99; }
9
- .yaml .time { color: #F99; }
10
- .yaml .date { color: #F99; }
11
- .yaml .ref { color: #944; }
12
- .yaml .anchor { color: #944; }