coderay 0.7.2.168 → 0.7.2.176

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,106 +1,106 @@
1
- # = WordList
2
- #
3
- # Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy cYcnus de>
4
- #
5
- # License:: LGPL / ask the author
6
- # Version:: 1.0 (2006-Feb-3)
7
- #
8
- # A WordList is a Hash with some additional features.
9
- # It is intended to be used for keyword recognition.
10
- #
11
- # WordList is highly optimized to be used in Scanners,
12
- # typically to decide whether a given ident is a keyword.
13
- #
14
- # For case insensitive words use CaseIgnoringWordList.
15
- #
16
- # Example:
17
- #
18
- # # define word arrays
19
- # RESERVED_WORDS = %w[
20
- # asm break case continue default do else
21
- # ...
22
- # ]
23
- #
24
- # PREDEFINED_TYPES = %w[
25
- # int long short char void
26
- # ...
27
- # ]
28
- #
29
- # PREDEFINED_CONSTANTS = %w[
30
- # EOF NULL ...
31
- # ]
32
- #
33
- # # make a WordList
34
- # IDENT_KIND = WordList.new(:ident).
35
- # add(RESERVED_WORDS, :reserved).
36
- # add(PREDEFINED_TYPES, :pre_type).
37
- # add(PREDEFINED_CONSTANTS, :pre_constant)
38
- #
39
- # ...
40
- #
41
- # def scan_tokens tokens, options
42
- # ...
43
- #
44
- # elsif scan(/[A-Za-z_][A-Za-z_0-9]*/)
45
- # # use it
46
- # kind = IDENT_KIND[match]
47
- # ...
48
- class WordList < Hash
49
-
50
- # Create a WordList for the given +words+.
51
- #
52
- # This WordList responds to [] with +true+, if the word is
53
- # in +words+, and with +false+ otherwise.
54
- def self.for words
55
- new.add words
56
- end
57
-
58
- # Creates a new WordList with +default+ as default value.
59
- def initialize default = false, &block
60
- super default, &block
61
- end
62
-
63
- # Checks if a word is included.
64
- def include? word
65
- has_key? word
66
- end
67
-
68
- # Add words to the list and associate them with +kind+.
69
- def add words, kind = true
70
- words.each do |word|
71
- self[word] = kind
72
- end
73
- self
74
- end
75
-
76
- end
77
-
78
-
79
- # A CaseIgnoringWordList is like a WordList, only that
80
- # keys are compared case-insensitively.
81
- class CaseIgnoringWordList < WordList
82
-
83
- # Creates a new WordList with +default+ as default value.
84
- #
85
- # Text case is ignored.
86
- def initialize default = false, &block
87
- block ||= proc do |h, k|
88
- h[k] = h.fetch k.downcase, default
89
- end
90
- super default
91
- end
92
-
93
- # Checks if a word is included.
94
- def include? word
95
- has_key? word.downcase
96
- end
97
-
98
- # Add words to the list and associate them with +kind+.
99
- def add words, kind = true
100
- words.each do |word|
101
- self[word.downcase] = kind
102
- end
103
- self
104
- end
105
-
106
- end
1
+ # = WordList
2
+ #
3
+ # Copyright (c) 2006 by murphy (Kornelius Kalnbach) <murphy cYcnus de>
4
+ #
5
+ # License:: LGPL / ask the author
6
+ # Version:: 1.0 (2006-Feb-3)
7
+ #
8
+ # A WordList is a Hash with some additional features.
9
+ # It is intended to be used for keyword recognition.
10
+ #
11
+ # WordList is highly optimized to be used in Scanners,
12
+ # typically to decide whether a given ident is a keyword.
13
+ #
14
+ # For case insensitive words use CaseIgnoringWordList.
15
+ #
16
+ # Example:
17
+ #
18
+ # # define word arrays
19
+ # RESERVED_WORDS = %w[
20
+ # asm break case continue default do else
21
+ # ...
22
+ # ]
23
+ #
24
+ # PREDEFINED_TYPES = %w[
25
+ # int long short char void
26
+ # ...
27
+ # ]
28
+ #
29
+ # PREDEFINED_CONSTANTS = %w[
30
+ # EOF NULL ...
31
+ # ]
32
+ #
33
+ # # make a WordList
34
+ # IDENT_KIND = WordList.new(:ident).
35
+ # add(RESERVED_WORDS, :reserved).
36
+ # add(PREDEFINED_TYPES, :pre_type).
37
+ # add(PREDEFINED_CONSTANTS, :pre_constant)
38
+ #
39
+ # ...
40
+ #
41
+ # def scan_tokens tokens, options
42
+ # ...
43
+ #
44
+ # elsif scan(/[A-Za-z_][A-Za-z_0-9]*/)
45
+ # # use it
46
+ # kind = IDENT_KIND[match]
47
+ # ...
48
+ class WordList < Hash
49
+
50
+ # Create a WordList for the given +words+.
51
+ #
52
+ # This WordList responds to [] with +true+, if the word is
53
+ # in +words+, and with +false+ otherwise.
54
+ def self.for words
55
+ new.add words
56
+ end
57
+
58
+ # Creates a new WordList with +default+ as default value.
59
+ def initialize default = false, &block
60
+ super default, &block
61
+ end
62
+
63
+ # Checks if a word is included.
64
+ def include? word
65
+ has_key? word
66
+ end
67
+
68
+ # Add words to the list and associate them with +kind+.
69
+ def add words, kind = true
70
+ words.each do |word|
71
+ self[word] = kind
72
+ end
73
+ self
74
+ end
75
+
76
+ end
77
+
78
+
79
+ # A CaseIgnoringWordList is like a WordList, only that
80
+ # keys are compared case-insensitively.
81
+ class CaseIgnoringWordList < WordList
82
+
83
+ # Creates a new WordList with +default+ as default value.
84
+ #
85
+ # Text case is ignored.
86
+ def initialize default = false, &block
87
+ block ||= proc do |h, k|
88
+ h[k] = h.fetch k.downcase, default
89
+ end
90
+ super default
91
+ end
92
+
93
+ # Checks if a word is included.
94
+ def include? word
95
+ has_key? word.downcase
96
+ end
97
+
98
+ # Add words to the list and associate them with +kind+.
99
+ def add words, kind = true
100
+ words.each do |word|
101
+ self[word.downcase] = kind
102
+ end
103
+ self
104
+ end
105
+
106
+ end
@@ -4,7 +4,7 @@ module CodeRay
4
4
 
5
5
  # = Scanners
6
6
  #
7
- # $Id: scanner.rb 154 2006-07-11 05:37:50Z murphy $
7
+ # $Id: scanner.rb 174 2006-10-15 09:08:50Z murphy $
8
8
  #
9
9
  # This module holds the Scanner class and its subclasses.
10
10
  # For example, the Ruby scanner is named CodeRay::Scanners::Ruby
@@ -191,7 +191,7 @@ module CodeRay
191
191
  end
192
192
 
193
193
  # Scanner error with additional status information
194
- def raise_inspect msg, tokens, state = nil, ambit = 30
194
+ def raise_inspect msg, tokens, state = 'No state given!', ambit = 30
195
195
  raise ScanError, <<-EOE % [
196
196
 
197
197
 
@@ -101,6 +101,7 @@ module Scanners
101
101
  state = :initial
102
102
  next
103
103
  elsif scan(/\n/)
104
+ kind = :error
104
105
  state = :initial
105
106
  else
106
107
  raise "else case \' reached; %p not handled." % peek(1), tokens
@@ -114,7 +115,7 @@ module Scanners
114
115
  match ||= matched
115
116
  if $DEBUG and not kind
116
117
  raise_inspect 'Error token %p in line %d' %
117
- [[match, kind], line], tokens
118
+ [[match, kind], line], tokens, state
118
119
  end
119
120
  raise_inspect 'Empty token', tokens unless match
120
121
 
@@ -107,6 +107,7 @@ module Scanners
107
107
  kind = :tag
108
108
  state = :initial
109
109
  elsif scan(/./)
110
+ kind = :error
110
111
  state = :attribute
111
112
  end
112
113
 
@@ -137,6 +138,8 @@ module Scanners
137
138
  next
138
139
  elsif scan(/#{ENTITY}/ox)
139
140
  kind = :entity
141
+ elsif scan(/&/)
142
+ kind = :content
140
143
  elsif scan(/[\n>]/)
141
144
  tokens << [:close, :string]
142
145
  kind = :error
@@ -113,6 +113,9 @@ module Scanners
113
113
 
114
114
  elsif entity = scan(/#{NITRO_ENTITY}/o)
115
115
  tokens << [entity, :entity]
116
+
117
+ elsif scan(/%/)
118
+ tokens << [matched, :error]
116
119
 
117
120
  else
118
121
  raise_inspect 'else-case reached!', tokens
@@ -21,14 +21,8 @@ module Scanners
21
21
 
22
22
  helper :patterns
23
23
 
24
- DEFAULT_OPTIONS = {
25
- :parse_regexps => true,
26
- }
27
-
28
24
  private
29
25
  def scan_tokens tokens, options
30
- parse_regexp = false # options[:parse_regexps]
31
- first_bake = saved_tokens = nil
32
26
  last_token_dot = false
33
27
  fancy_allowed = regexp_allowed = true
34
28
  heredocs = nil
@@ -72,36 +66,6 @@ module Scanners
72
66
  if state.type == :regexp and not eos?
73
67
  modifiers = scan(/#{patterns::REGEXP_MODIFIERS}/ox)
74
68
  tokens << [modifiers, :modifier] unless modifiers.empty?
75
- if parse_regexp
76
- extended = modifiers.index ?x
77
- tokens = saved_tokens
78
- regexp = tokens
79
- for text, kind in regexp
80
- if text.is_a? ::String
81
- case kind
82
- when :content
83
- text.scan(/([^#]+)|(#.*)/) do |plain, comment|
84
- if plain
85
- tokens << [plain, :content]
86
- else
87
- tokens << [comment, :comment]
88
- end
89
- end
90
- when :character
91
- if text[/\\(?:[swdSWDAzZbB]|\d+)/]
92
- tokens << [text, :modifier]
93
- else
94
- tokens << [text, kind]
95
- end
96
- else
97
- tokens << [text, kind]
98
- end
99
- else
100
- tokens << [text, kind]
101
- end
102
- end
103
- first_bake = saved_tokens = nil
104
- end
105
69
  end
106
70
  tokens << [:close, state.type]
107
71
  fancy_allowed = regexp_allowed = false
@@ -241,10 +205,6 @@ module Scanners
241
205
  kind = :delimiter
242
206
  interpreted = true
243
207
  state = patterns::StringState.new :regexp, interpreted, match
244
- if parse_regexp
245
- tokens = []
246
- saved_tokens = tokens
247
- end
248
208
 
249
209
  elsif match = scan(/#{patterns::NUMERIC}/o)
250
210
  kind = if self[1] then :float else :integer end
@@ -1,7 +1,7 @@
1
- module CodeRay
2
- module Styles
3
-
4
- default :cycnus
5
-
6
- end
7
- end
1
+ module CodeRay
2
+ module Styles
3
+
4
+ default :cycnus
5
+
6
+ end
7
+ end
@@ -1,125 +1,125 @@
1
- module CodeRay
2
- module Styles
3
-
4
- class Cycnus < Style
5
-
6
- register_for :cycnus
7
-
8
- code_background = '#f8f8f8'
9
- numbers_background = '#def'
10
- border_color = 'silver'
11
- normal_color = '#100'
12
-
13
- CSS_MAIN_STYLES = <<-MAIN
14
- .CodeRay {
15
- background-color: #{code_background};
16
- border: 1px solid #{border_color};
17
- font-family: 'Courier New', 'Terminal', monospace;
18
- color: #{normal_color};
19
- }
20
- .CodeRay pre { margin: 0px }
21
-
22
- div.CodeRay { }
23
-
24
- span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25
-
26
- table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27
- table.CodeRay td { padding: 2px 4px; vertical-align: top }
28
-
29
- .CodeRay .line_numbers, .CodeRay .no {
30
- background-color: #{numbers_background};
31
- color: gray;
32
- text-align: right;
33
- }
34
- .CodeRay .line_numbers tt { font-weight: bold }
35
- .CodeRay .no { padding: 0px 4px }
36
- .CodeRay .code { width: 100% }
37
-
38
- ol.CodeRay { font-size: 10pt }
39
- ol.CodeRay li { white-space: pre }
40
-
41
- .CodeRay .code pre { overflow: auto }
42
- MAIN
43
-
44
- TOKEN_COLORS = <<-'TOKENS'
45
- .af { color:#00C }
46
- .an { color:#007 }
47
- .av { color:#700 }
48
- .aw { color:#C00 }
49
- .bi { color:#509; font-weight:bold }
50
- .c { color:#888 }
51
-
52
- .ch { color:#04D }
53
- .ch .k { color:#04D }
54
- .ch .dl { color:#039 }
55
-
56
- .cl { color:#B06; font-weight:bold }
57
- .co { color:#036; font-weight:bold }
58
- .cr { color:#0A0 }
59
- .cv { color:#369 }
60
- .df { color:#099; font-weight:bold }
61
- .di { color:#088; font-weight:bold }
62
- .dl { color:black }
63
- .do { color:#970 }
64
- .ds { color:#D42; font-weight:bold }
65
- .e { color:#666; font-weight:bold }
66
- .en { color:#800; font-weight:bold }
67
- .er { color:#F00; background-color:#FAA }
68
- .ex { color:#F00; font-weight:bold }
69
- .fl { color:#60E; font-weight:bold }
70
- .fu { color:#06B; font-weight:bold }
71
- .gv { color:#d70; font-weight:bold }
72
- .hx { color:#058; font-weight:bold }
73
- .i { color:#00D; font-weight:bold }
74
- .ic { color:#B44; font-weight:bold }
75
-
76
- .il { background: #eee }
77
- .il .il { background: #ddd }
78
- .il .il .il { background: #ccc }
79
- .il .dl { font-weight: bold ! important; color: #888 ! important }
80
-
81
- .in { color:#B2B; font-weight:bold }
82
- .iv { color:#33B }
83
- .la { color:#970; font-weight:bold }
84
- .lv { color:#963 }
85
- .oc { color:#40E; font-weight:bold }
86
- .on { color:#000; font-weight:bold }
87
- .op { }
88
- .pc { color:#038; font-weight:bold }
89
- .pd { color:#369; font-weight:bold }
90
- .pp { color:#579 }
91
- .pt { color:#339; font-weight:bold }
92
- .r { color:#080; font-weight:bold }
93
-
94
- .rx { background-color:#fff0ff }
95
- .rx .k { color:#808 }
96
- .rx .dl { color:#404 }
97
- .rx .mod { color:#C2C }
98
- .rx .fu { color:#404; font-weight: bold }
99
-
100
- .s { background-color:#fff0f0 }
101
- .s .s { background-color:#ffe0e0 }
102
- .s .s .s { background-color:#ffd0d0 }
103
- .s .k { color:#D20 }
104
- .s .dl { color:#710 }
105
-
106
- .sh { background-color:#f0fff0 }
107
- .sh .k { color:#2B2 }
108
- .sh .dl { color:#161 }
109
-
110
- .sy { color:#A60 }
111
- .sy .k { color:#A60 }
112
- .sy .dl { color:#630 }
113
-
114
- .ta { color:#070 }
115
- .tf { color:#070; font-weight:bold }
116
- .ts { color:#D70; font-weight:bold }
117
- .ty { color:#339; font-weight:bold }
118
- .v { color:#036 }
119
- .xt { color:#444 }
120
- TOKENS
121
-
122
- end
123
-
124
- end
125
- end
1
+ module CodeRay
2
+ module Styles
3
+
4
+ class Cycnus < Style
5
+
6
+ register_for :cycnus
7
+
8
+ code_background = '#f8f8f8'
9
+ numbers_background = '#def'
10
+ border_color = 'silver'
11
+ normal_color = '#100'
12
+
13
+ CSS_MAIN_STYLES = <<-MAIN
14
+ .CodeRay {
15
+ background-color: #{code_background};
16
+ border: 1px solid #{border_color};
17
+ font-family: 'Courier New', 'Terminal', monospace;
18
+ color: #{normal_color};
19
+ }
20
+ .CodeRay pre { margin: 0px }
21
+
22
+ div.CodeRay { }
23
+
24
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
25
+
26
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
27
+ table.CodeRay td { padding: 2px 4px; vertical-align: top }
28
+
29
+ .CodeRay .line_numbers, .CodeRay .no {
30
+ background-color: #{numbers_background};
31
+ color: gray;
32
+ text-align: right;
33
+ }
34
+ .CodeRay .line_numbers tt { font-weight: bold }
35
+ .CodeRay .no { padding: 0px 4px }
36
+ .CodeRay .code { width: 100% }
37
+
38
+ ol.CodeRay { font-size: 10pt }
39
+ ol.CodeRay li { white-space: pre }
40
+
41
+ .CodeRay .code pre { overflow: auto }
42
+ MAIN
43
+
44
+ TOKEN_COLORS = <<-'TOKENS'
45
+ .af { color:#00C }
46
+ .an { color:#007 }
47
+ .av { color:#700 }
48
+ .aw { color:#C00 }
49
+ .bi { color:#509; font-weight:bold }
50
+ .c { color:#888 }
51
+
52
+ .ch { color:#04D }
53
+ .ch .k { color:#04D }
54
+ .ch .dl { color:#039 }
55
+
56
+ .cl { color:#B06; font-weight:bold }
57
+ .co { color:#036; font-weight:bold }
58
+ .cr { color:#0A0 }
59
+ .cv { color:#369 }
60
+ .df { color:#099; font-weight:bold }
61
+ .di { color:#088; font-weight:bold }
62
+ .dl { color:black }
63
+ .do { color:#970 }
64
+ .ds { color:#D42; font-weight:bold }
65
+ .e { color:#666; font-weight:bold }
66
+ .en { color:#800; font-weight:bold }
67
+ .er { color:#F00; background-color:#FAA }
68
+ .ex { color:#F00; font-weight:bold }
69
+ .fl { color:#60E; font-weight:bold }
70
+ .fu { color:#06B; font-weight:bold }
71
+ .gv { color:#d70; font-weight:bold }
72
+ .hx { color:#058; font-weight:bold }
73
+ .i { color:#00D; font-weight:bold }
74
+ .ic { color:#B44; font-weight:bold }
75
+
76
+ .il { background: #eee }
77
+ .il .il { background: #ddd }
78
+ .il .il .il { background: #ccc }
79
+ .il .dl { font-weight: bold ! important; color: #888 ! important }
80
+
81
+ .in { color:#B2B; font-weight:bold }
82
+ .iv { color:#33B }
83
+ .la { color:#970; font-weight:bold }
84
+ .lv { color:#963 }
85
+ .oc { color:#40E; font-weight:bold }
86
+ .on { color:#000; font-weight:bold }
87
+ .op { }
88
+ .pc { color:#038; font-weight:bold }
89
+ .pd { color:#369; font-weight:bold }
90
+ .pp { color:#579 }
91
+ .pt { color:#339; font-weight:bold }
92
+ .r { color:#080; font-weight:bold }
93
+
94
+ .rx { background-color:#fff0ff }
95
+ .rx .k { color:#808 }
96
+ .rx .dl { color:#404 }
97
+ .rx .mod { color:#C2C }
98
+ .rx .fu { color:#404; font-weight: bold }
99
+
100
+ .s { background-color:#fff0f0 }
101
+ .s .s { background-color:#ffe0e0 }
102
+ .s .s .s { background-color:#ffd0d0 }
103
+ .s .k { color:#D20 }
104
+ .s .dl { color:#710 }
105
+
106
+ .sh { background-color:#f0fff0 }
107
+ .sh .k { color:#2B2 }
108
+ .sh .dl { color:#161 }
109
+
110
+ .sy { color:#A60 }
111
+ .sy .k { color:#A60 }
112
+ .sy .dl { color:#630 }
113
+
114
+ .ta { color:#070 }
115
+ .tf { color:#070; font-weight:bold }
116
+ .ts { color:#D70; font-weight:bold }
117
+ .ty { color:#339; font-weight:bold }
118
+ .v { color:#036 }
119
+ .xt { color:#444 }
120
+ TOKENS
121
+
122
+ end
123
+
124
+ end
125
+ end