rouge 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,6 +85,8 @@ load load_dir.join('rouge/lexers/cpp.rb')
85
85
  load load_dir.join('rouge/lexers/java.rb')
86
86
  load load_dir.join('rouge/lexers/rust.rb')
87
87
 
88
+ load load_dir.join('rouge/lexers/csharp.rb')
89
+
88
90
  load load_dir.join('rouge/lexers/smalltalk.rb')
89
91
 
90
92
  load load_dir.join('rouge/formatter.rb')
@@ -0,0 +1,5 @@
1
+ // reverse byte order (16-bit)
2
+ public static UInt16 ReverseBytes(UInt16 value)
3
+ {
4
+ return (UInt16)((value & 0xFFU) << 8 | (value & 0xFF00U) >> 8);
5
+ }
@@ -0,0 +1,17 @@
1
+ module Rouge
2
+ module Lexers
3
+ class ASP < TemplateLexer
4
+ tag 'asp'
5
+ aliases 'asp.net'
6
+
7
+ default_options :parent => XML
8
+
9
+ state :root do
10
+ rule /(<%[@=#]?)(.*?)(%>)/ do
11
+ group 'Name.Tag'
12
+ group 'Other
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,83 @@
1
+ module Rouge
2
+ module Lexers
3
+ class CSharp < RegexLexer
4
+ tag 'csharp'
5
+ aliases 'c#', 'cs'
6
+ filenames '*.cs'
7
+ mimetypes 'text/x-csharp'
8
+
9
+ # TODO: support more of unicode
10
+ id = /@?[_a-z]\w*/i
11
+
12
+ keywords = %w(
13
+ abstract alias as base break case catch checked const continue
14
+ default delegate do else enum event explicit extern false
15
+ finally fixed for foreach global goto if implicit in interface
16
+ internal is lock new null operator out override params private
17
+ protected public readonly ref return sealed sizeof stackalloc
18
+ static switch this throw true try typeof unchecked unsafe
19
+ virtual void while get set new partial yield add remove value
20
+ )
21
+
22
+ keywords_type = %w(
23
+ bool byte char decimal double float int long object sbyte
24
+ short string uint ulong ushort
25
+ )
26
+
27
+ cpp_keywords = %w(
28
+ if endif else elif define undef line error warning region
29
+ endregion pragma
30
+ )
31
+
32
+ state :whitespace do
33
+ rule /\s+/m, 'Text'
34
+ rule %r(//.*?\n), 'Comment.Single'
35
+ rule %r(/[*].*?[*]/)m, 'Comment.Multiline'
36
+ end
37
+
38
+ state :root do
39
+ mixin :whitespace
40
+
41
+ rule /^\s*\[.*?\]/, 'Name.Attribute'
42
+ rule /[$]\s*"/, 'Literal.String', :splice_string
43
+ rule /[$]\s*<#/, 'Literal.String', :splice_recstring
44
+ rule /<#/, 'Literal.String', :recstring
45
+
46
+ rule /(<\[)\s*(#{id}:)?/, 'Keyword'
47
+ rule /\]>/, 'Keyword'
48
+
49
+ rule /[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, 'Punctuation'
50
+ rule /@"(\\.|.)*?"/, 'Literal.String'
51
+ rule /"(\\.|.)*?["\n]/, 'Literal.String'
52
+ rule /'(\\.|.)'/, 'Literal.String.Char'
53
+ rule %r(
54
+ [0-9]
55
+ ([.][0-9]*)? # decimal
56
+ (e[+-][0-9]+)? # exponent
57
+ [fld]? # type
58
+ )ix, 'Literal.Number'
59
+ rule /0x[0-9a-f]+l?/i, 'Literal.Number'
60
+ rule /^#[ \t]*(#{cpp_keywords.join('|')})\b.*?\n/,
61
+ 'Comment.Preproc'
62
+ rule /\b(#{keywords.join('|')})\b/, 'Keyword'
63
+ rule /\b(#{keywords_type.join('|')})\b/, 'Keyword.Type'
64
+ rule /class|struct/, 'Keyword', :class
65
+ rule /namespace|using/, 'Keyword', :namespace
66
+ rule /#{id}(?=\s*[(])/, 'Name.Function'
67
+ rule id, 'Name'
68
+ end
69
+
70
+ state :class do
71
+ mixin :whitespace
72
+ rule id, 'Name.Class', :pop!
73
+ end
74
+
75
+ state :namespace do
76
+ mixin :whitespace
77
+ rule /(?=[(])/, 'Text', :pop!
78
+ rule /(#{id}|[.])+/, 'Name.Namespace', :pop!
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -146,7 +146,16 @@ module Rouge
146
146
 
147
147
  state :strings do
148
148
  rule /%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, 'Literal.String.Interpol'
149
- rule /[^\\'"%\n]+/, 'Literal.String'
149
+ end
150
+
151
+ state :strings_double do
152
+ rule /[^\\"%\n]+/, 'Literal.String'
153
+ mixin :strings
154
+ end
155
+
156
+ state :strings_single do
157
+ rule /[^\\'%\n]+/, 'Literal.String'
158
+ mixin :strings
150
159
  end
151
160
 
152
161
  state :nl do
@@ -169,24 +178,25 @@ module Rouge
169
178
  state :dqs do
170
179
  rule /"/, 'Literal.String', :pop!
171
180
  rule /\\\\|\\"|\\\n/, 'Literal.String.Escape'
172
- mixin :strings
181
+ mixin :strings_double
173
182
  end
174
183
 
175
184
  state :sqs do
176
185
  rule /'/, 'Literal.String', :pop!
177
186
  rule /\\\\|\\'|\\\n/, 'Literal.String.Escape'
178
- mixin :strings
187
+ mixin :strings_single
179
188
  end
180
189
 
181
190
  state :tdqs do
182
191
  rule /"""/, 'Literal.String', :pop!
183
- mixin :strings
192
+ mixin :strings_double
184
193
  mixin :nl
185
194
  end
186
195
 
187
196
  state :tsqs do
188
197
  rule /'''/, 'Literal.String', :pop!
189
- mixin :strings
198
+ rule /[^\\'%\n]+/, 'Literal.String'
199
+ mixin :strings_single
190
200
  mixin :nl
191
201
  end
192
202
 
@@ -33,6 +33,16 @@ module Rouge
33
33
  )
34
34
  end
35
35
 
36
+ def macro_closed?
37
+ @macro_delims.values.all?(&:zero?)
38
+ end
39
+
40
+ start {
41
+ @macro_delims = { ']' => 0, ')' => 0, '}' => 0 }
42
+ }
43
+
44
+ delim_map = { '[' => ']', '(' => ')', '{' => '}' }
45
+
36
46
  id = /[a-z_]\w*/i
37
47
  hex = /[0-9a-f]/i
38
48
  escapes = %r(
@@ -74,14 +84,15 @@ module Rouge
74
84
  rule /[()\[\]{}|,:;]/, 'Punctuation'
75
85
  rule /[*!@~&+%^<>=-]/, 'Operator'
76
86
 
77
- rule /[.]?#{id}(?=\s*[(])/m, 'Name.Function'
78
- rule /[.]#{id}/, 'Name.Property'
87
+ rule /([.]\s*)?#{id}(?=\s*[(])/m, 'Name.Function'
88
+ rule /[.]\s*#{id}/, 'Name.Property'
79
89
  rule /(#{id})(::)/m do
80
90
  group 'Name.Namespace'; group 'Punctuation'
81
91
  end
82
92
 
83
93
  # macros
84
- rule /#{id}!/, 'Name.Decorator'
94
+ rule /\bmacro_rules!/, 'Name.Decorator', :macro_rules
95
+ rule /#{id}!/, 'Name.Decorator', :macro
85
96
 
86
97
  rule /#{id}/ do |m|
87
98
  name = m[0]
@@ -93,11 +104,40 @@ module Rouge
93
104
  end
94
105
  end
95
106
 
107
+ state :macro do
108
+ mixin :has_literals
109
+
110
+ rule /[\[{(]/ do |m|
111
+ @macro_delims[delim_map[m[0]]] += 1
112
+ debug { " macro_delims: #{@macro_delims.inspect}" }
113
+ token 'Punctuation'
114
+ end
115
+
116
+ rule /[\]})]/ do |m|
117
+ @macro_delims[m[0]] -= 1
118
+ debug { " macro_delims: #{@macro_delims.inspect}" }
119
+ pop! if macro_closed?
120
+ token 'Punctuation'
121
+ end
122
+
123
+ # same as the rule in root, but don't push another macro state
124
+ rule /#{id}!/, 'Name.Decorator'
125
+ mixin :root
126
+
127
+ # No syntax errors in macros
128
+ rule /./, 'Text'
129
+ end
130
+
131
+ state :macro_rules do
132
+ rule /[$]#{id}(:#{id})?/, 'Name.Variable'
133
+ rule /[$]/, 'Name.Variable'
134
+
135
+ mixin :macro
136
+ end
137
+
96
138
  state :has_literals do
97
139
  # constants
98
140
  rule /\b(?:true|false|nil)\b/, 'Keyword.Constant'
99
- # ()
100
- rule /[(]\s*[)]/, 'Keyword.Constant'
101
141
  # characters
102
142
  rule %r(
103
143
  ' (?: #{escapes} | [^\\] ) '
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.2.10"
3
+ "0.2.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -58,9 +58,11 @@ files:
58
58
  - lib/rouge/lexers/io.rb
59
59
  - lib/rouge/lexers/viml.rb
60
60
  - lib/rouge/lexers/rust.rb
61
+ - lib/rouge/lexers/csharp.rb
61
62
  - lib/rouge/lexers/objective_c.rb
62
63
  - lib/rouge/lexers/smalltalk.rb
63
64
  - lib/rouge/lexers/php/builtins.rb
65
+ - lib/rouge/lexers/asp.rb
64
66
  - lib/rouge/lexers/haskell.rb
65
67
  - lib/rouge/lexers/c.rb
66
68
  - lib/rouge/lexers/sed.rb
@@ -131,6 +133,7 @@ files:
131
133
  - lib/rouge/demos/nginx
132
134
  - lib/rouge/demos/rust
133
135
  - lib/rouge/demos/tcl
136
+ - lib/rouge/demos/csharp
134
137
  - lib/rouge/demos/c
135
138
  - lib/rouge/demos/perl
136
139
  - lib/rouge/demos/text