rouge 0.0.8 → 0.0.9
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.
- data/lib/rouge.rb +4 -0
- data/lib/rouge/lexer.rb +11 -5
- data/lib/rouge/lexers/c.rb +143 -0
- data/lib/rouge/lexers/cpp.rb +109 -0
- data/lib/rouge/lexers/java.rb +72 -0
- data/lib/rouge/version.rb +1 -1
- metadata +5 -2
data/lib/rouge.rb
CHANGED
@@ -30,6 +30,10 @@ load load_dir.join('rouge/lexers/python.rb')
|
|
30
30
|
|
31
31
|
load load_dir.join('rouge/lexers/haskell.rb')
|
32
32
|
|
33
|
+
load load_dir.join('rouge/lexers/c.rb')
|
34
|
+
load load_dir.join('rouge/lexers/cpp.rb')
|
35
|
+
load load_dir.join('rouge/lexers/java.rb')
|
36
|
+
|
33
37
|
load load_dir.join('rouge/formatter.rb')
|
34
38
|
load load_dir.join('rouge/formatters/html.rb')
|
35
39
|
|
data/lib/rouge/lexer.rb
CHANGED
@@ -307,18 +307,24 @@ module Rouge
|
|
307
307
|
stack.last
|
308
308
|
end
|
309
309
|
|
310
|
-
|
310
|
+
MAX_NULL_STEPS = 5
|
311
311
|
def scan(re, &b)
|
312
|
-
@
|
313
|
-
@steps += 1
|
312
|
+
@null_steps ||= 0
|
314
313
|
|
315
|
-
if @
|
316
|
-
|
314
|
+
if @null_steps >= MAX_NULL_STEPS
|
315
|
+
debug { " too many scans without consuming the string!" }
|
316
|
+
return false
|
317
317
|
end
|
318
318
|
|
319
319
|
scanner.scan(re)
|
320
320
|
|
321
321
|
if scanner.matched?
|
322
|
+
if scanner.matched_size == 0
|
323
|
+
@null_steps += 1
|
324
|
+
else
|
325
|
+
@null_steps = 0
|
326
|
+
end
|
327
|
+
|
322
328
|
yield self
|
323
329
|
return true
|
324
330
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class C < RegexLexer
|
4
|
+
tag 'c'
|
5
|
+
filenames '*.c', '*.h', '*.idc'
|
6
|
+
mimetypes 'text/x-chdr', 'text/x-csrc'
|
7
|
+
|
8
|
+
# optional comment or whitespace
|
9
|
+
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
|
10
|
+
id = /[a-zA-Z_][a-zA-Z0-9_]*/
|
11
|
+
|
12
|
+
keywords = %w(
|
13
|
+
auto break case const continue default do else enum extern
|
14
|
+
for goto if register restricted return sizeof static struct
|
15
|
+
switch typedef union volatile virtual while
|
16
|
+
)
|
17
|
+
|
18
|
+
keywords_type = %w(int long float short double char unsigned signed void)
|
19
|
+
|
20
|
+
__reserved = %w(
|
21
|
+
asm int8 based except int16 stdcall cdecl fastcall int32
|
22
|
+
declspec finally int61 try leave
|
23
|
+
)
|
24
|
+
|
25
|
+
state :whitespace do
|
26
|
+
rule /^#if\s+0\b/, 'Comment.Preproc', :if_0
|
27
|
+
rule /^#/, 'Comment.Preproc', :macro
|
28
|
+
rule /^#{ws}#if\s+0\b/, 'Comment.Preproc', :if_0
|
29
|
+
rule /^#{ws}#/, 'Comment.Preproc', :macro
|
30
|
+
rule /^(\s*)(#{id}:(?!:))/ do
|
31
|
+
group 'Text'
|
32
|
+
group 'Name.Label'
|
33
|
+
end
|
34
|
+
|
35
|
+
rule /\s+/m, 'Text'
|
36
|
+
rule /\\\n/, 'Text' # line continuation
|
37
|
+
rule %r(//(\n|(.|\n)*?[^\\]\n)), 'Comment.Single'
|
38
|
+
rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), 'Comment.Multiline'
|
39
|
+
end
|
40
|
+
|
41
|
+
state :statements do
|
42
|
+
rule /L?"/, 'Literal.String', :string
|
43
|
+
rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, 'Literal.String.Char'
|
44
|
+
rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i, 'Literal.Number.Float'
|
45
|
+
rule /0x[0-9a-f]+[lu]*/i, 'Literal.Number.Hex'
|
46
|
+
rule /0[0-7]+[lu]*/i, 'Literal.Number.Oct'
|
47
|
+
rule /\d+[lu]*/i, 'Literal.Number.Integer'
|
48
|
+
rule %r(\*/), 'Error'
|
49
|
+
rule %r([~!%^&*+=\|?:<>/-]), 'Operator'
|
50
|
+
rule /[()\[\],.]/, 'Punctuation'
|
51
|
+
rule /\bcase\b/, 'Keyword', :case
|
52
|
+
rule /(?:#{keywords.join('|')})\b/, 'Keyword'
|
53
|
+
rule /(?:#{keywords_type.join('|')})\b/, 'Keyword.Type'
|
54
|
+
rule /(?:_{0,2}inline|naked|restrict|thread|typename)\b/, 'Keyword.Reserved'
|
55
|
+
rule /__(?:#{__reserved.join('|')})\b/, 'Keyword.Reserved'
|
56
|
+
rule /(?:true|false|NULL)\b/, 'Name.Builtin'
|
57
|
+
rule id, 'Name'
|
58
|
+
end
|
59
|
+
|
60
|
+
state :case do
|
61
|
+
rule /:/, 'Punctuation', :pop!
|
62
|
+
mixin :statements
|
63
|
+
end
|
64
|
+
|
65
|
+
state :root do
|
66
|
+
mixin :whitespace
|
67
|
+
|
68
|
+
# functions
|
69
|
+
rule %r(
|
70
|
+
([\w*\s]+?[\s*]) # return arguments
|
71
|
+
(#{id}) # function name
|
72
|
+
(\s*\([^;]*?\)) # signature
|
73
|
+
(#{ws})({) # open brace
|
74
|
+
)mx do |m|
|
75
|
+
# TODO: do this better.
|
76
|
+
delegate C, m[1]
|
77
|
+
token 'Name.Function', m[2]
|
78
|
+
delegate C, m[3]
|
79
|
+
delegate C, m[4]
|
80
|
+
token 'Punctuation', m[5]
|
81
|
+
push :function
|
82
|
+
end
|
83
|
+
|
84
|
+
# function declarations
|
85
|
+
rule %r(
|
86
|
+
([\w*\s]+?[\s*]) # return arguments
|
87
|
+
(#{id}) # function name
|
88
|
+
(\s*\([^;]*?\)) # signature
|
89
|
+
(#{ws})(;) # semicolon
|
90
|
+
)mx do |m|
|
91
|
+
# TODO: do this better.
|
92
|
+
delegate C, m[1]
|
93
|
+
token 'Name.Function'
|
94
|
+
delegate C, m[3]
|
95
|
+
delegate C, m[4]
|
96
|
+
token 'Punctuation'
|
97
|
+
push :statement
|
98
|
+
end
|
99
|
+
|
100
|
+
rule(//) { push :statement }
|
101
|
+
end
|
102
|
+
|
103
|
+
state :statement do
|
104
|
+
rule /;/, 'Punctuation', :pop!
|
105
|
+
mixin :whitespace
|
106
|
+
mixin :statements
|
107
|
+
rule /[{}]/, 'Punctuation'
|
108
|
+
end
|
109
|
+
|
110
|
+
state :function do
|
111
|
+
mixin :whitespace
|
112
|
+
mixin :statements
|
113
|
+
rule /;/, 'Punctuation'
|
114
|
+
rule /{/, 'Punctuation', :function
|
115
|
+
rule /}/, 'Punctuation', :pop!
|
116
|
+
end
|
117
|
+
|
118
|
+
state :string do
|
119
|
+
rule /"/, 'Literal.String', :pop!
|
120
|
+
rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, 'Literal.String.Escape'
|
121
|
+
rule /[^\\"\n]+/, 'Literal.String'
|
122
|
+
rule /\\\n/, 'Literal.String'
|
123
|
+
rule /\\/, 'Literal.String' # stray backslash
|
124
|
+
end
|
125
|
+
|
126
|
+
state :macro do
|
127
|
+
rule %r([^/\n]+), 'Comment.Preproc'
|
128
|
+
rule %r(/[*].*?[*]/)m, 'Comment.Multiliine'
|
129
|
+
rule %r(//.*$), 'Comment.Single'
|
130
|
+
rule %r(/), 'Comment.Preproc'
|
131
|
+
rule /(?<=\\)\n/, 'Comment.Preproc'
|
132
|
+
rule /\n/, 'Comment.Preproc', :pop!
|
133
|
+
end
|
134
|
+
|
135
|
+
state :if_0 do
|
136
|
+
rule /^\s*#if.*?(?<!\\)\n/, 'Comment.Preproc', :if_0
|
137
|
+
rule /^\s*#el(?:se|if).*\n/, 'Comment.Preproc', :pop!
|
138
|
+
rule /^\s*#endif.*?(?<!\\)\n/, 'Comment.Preproc', :pop!
|
139
|
+
rule /.*?\n/, 'Comment'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class Cpp < RegexLexer
|
4
|
+
tag 'cpp'
|
5
|
+
aliases 'c++'
|
6
|
+
# the many varied filenames of c++ source files...
|
7
|
+
filenames '*.cpp', '*.hpp',
|
8
|
+
'*.c++', '*.h++',
|
9
|
+
'*.cc', '*.hh',
|
10
|
+
'*.cxx', '*.hxx'
|
11
|
+
mimetypes 'text/x-c++hdr', 'text/x-c++src'
|
12
|
+
|
13
|
+
keywords = %w(
|
14
|
+
asm auto break case catch const const_cast continue
|
15
|
+
default delete do dynamic_cast else enum explicit export
|
16
|
+
extern for friend goto if mutable namespace new operator
|
17
|
+
private protected public register reinterpret_cast return
|
18
|
+
restrict sizeof static static_cast struct switch template
|
19
|
+
this throw throws try typedef typeid typename union using
|
20
|
+
volatile virtual while
|
21
|
+
)
|
22
|
+
|
23
|
+
keywords_type = %w(
|
24
|
+
bool int long float short double char unsigned signed void wchar_t
|
25
|
+
)
|
26
|
+
|
27
|
+
__reserved = %w(
|
28
|
+
asm int8 based except int16 stdcall cdecl fastcall int32 declspec
|
29
|
+
finally int64 try leave wchar_t w64 virtual_inheritance uuidof
|
30
|
+
unaligned super single_inheritance raise noop multiple_inheritance
|
31
|
+
m128i m128d m128 m64 interface identifier forceinline event assume
|
32
|
+
)
|
33
|
+
|
34
|
+
# optional comments or whitespace
|
35
|
+
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
|
36
|
+
id = /[a-zA-Z_][a-zA-Z0-9]*/
|
37
|
+
|
38
|
+
state :whitespace do
|
39
|
+
rule /^#if\s+0/, 'Comment.Preproc', :if_0
|
40
|
+
rule /^#/, 'Comment.Preproc', :macro
|
41
|
+
rule /^#{ws}#if\s+0\b/, 'Comment.Preproc', :if_0
|
42
|
+
rule /^#{ws}#/, 'Comment.Preproc', :macro
|
43
|
+
rule /\s+/m, 'Text'
|
44
|
+
rule /\\\n/, 'Text'
|
45
|
+
rule %r(/(\\\n)?/(\n|(.|\n)*?[^\\]\n)), 'Comment.Single'
|
46
|
+
rule %r(/(\\\n)?[*](.|\n)*?[*](\\\n)?/), 'Comment.Multiline'
|
47
|
+
end
|
48
|
+
|
49
|
+
state :root do
|
50
|
+
mixin :whitespace
|
51
|
+
|
52
|
+
rule /L?"/, 'Literal.String', :string
|
53
|
+
rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, 'Literal.String.Char'
|
54
|
+
rule %r((\d+\.\d*|\.\d+|\d+)[e][+-]?\d+[lu]*)i, 'Literal.Number.Float'
|
55
|
+
rule /0x[0-9a-f]+[lu]*/i, 'Literal.Number.Hex'
|
56
|
+
rule /0[0-7]+[lu]*/i, 'Literal.Number.Oct'
|
57
|
+
rule /\d+[lu]*/i, 'Literal.Number.Integer'
|
58
|
+
rule %r(\*/), 'Error'
|
59
|
+
rule %r([~!%^&*+=\|?:<>/-]), 'Operator'
|
60
|
+
rule /[()\[\],.;{}]/, 'Punctuation'
|
61
|
+
|
62
|
+
rule /(?:#{keywords.join('|')})\b/, 'Keyword'
|
63
|
+
rule /class\b/, 'Keyword', :classname
|
64
|
+
rule /(?:#{keywords_type.join('|')})\b/, 'Keyword.Type'
|
65
|
+
rule /(?:_{0,2}inline|naked|thread)\b/, 'Keyword.Reserved'
|
66
|
+
rule /__(?:#{__reserved.join('|')})\b/, 'Keyoword.Reserved'
|
67
|
+
# Offload C++ extensions, http://offload.codeplay.com/
|
68
|
+
rule /(?:__offload|__blockingoffload|__outer)\b/, 'Keyword.Pseudo'
|
69
|
+
|
70
|
+
rule /(true|false)\b/, 'Keyword.Constant'
|
71
|
+
rule /NULL\b/, 'Name.Builtin'
|
72
|
+
rule /#{id}:(?!:)/, 'Name.Label'
|
73
|
+
rule id, 'Name'
|
74
|
+
end
|
75
|
+
|
76
|
+
state :classname do
|
77
|
+
rule id, 'Name.Class', :pop!
|
78
|
+
|
79
|
+
# template specification
|
80
|
+
rule /\s*(?=>)/m, 'Text', :pop!
|
81
|
+
mixin :whitespace
|
82
|
+
end
|
83
|
+
|
84
|
+
state :string do
|
85
|
+
rule /"/, 'Literal.String', :pop!
|
86
|
+
rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, 'Literal.String.Escape'
|
87
|
+
rule /[^\\"\n]+/, 'Literal.String'
|
88
|
+
rule /\\\n/, 'Literal.String'
|
89
|
+
rule /\\/, 'Literal.String' # stray backslash
|
90
|
+
end
|
91
|
+
|
92
|
+
state :macro do
|
93
|
+
rule %r([^/\n]+), 'Comment.Preproc'
|
94
|
+
rule %r(/[*].*?[*]/)m, 'Comment.Multiliine'
|
95
|
+
rule %r(//.*$), 'Comment.Single'
|
96
|
+
rule %r(/), 'Comment.Preproc'
|
97
|
+
rule /(?<=\\)\n/, 'Comment.Preproc'
|
98
|
+
rule /\n/, 'Comment.Preproc', :pop!
|
99
|
+
end
|
100
|
+
|
101
|
+
state :if_0 do
|
102
|
+
rule /^\s*#if.*?(?<!\\)\n/, 'Comment.Preproc', :if_0
|
103
|
+
rule /^\s*#el(?:se|if).*\n/, 'Comment.Preproc', :pop!
|
104
|
+
rule /^\s*#endif.*?(?<!\\)\n/, 'Comment.Preproc', :pop!
|
105
|
+
rule /.*?\n/, 'Comment'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class Java < RegexLexer
|
4
|
+
tag 'java'
|
5
|
+
filenames '*.java'
|
6
|
+
mimetypes 'text/x-java'
|
7
|
+
|
8
|
+
keywords = %w(
|
9
|
+
assert break case catch continue default do else finally for
|
10
|
+
if goto instanceof new return switch this throw try while
|
11
|
+
)
|
12
|
+
|
13
|
+
declarations = %w(
|
14
|
+
abstract const enum extends final implements native private protected
|
15
|
+
public static strictfp super synchronized throws transient volatile
|
16
|
+
)
|
17
|
+
|
18
|
+
types = %w(boolean byte char double float int long short void)
|
19
|
+
|
20
|
+
id = /[a-zA-Z_][a-zA-Z0-9_]*/
|
21
|
+
|
22
|
+
state :root do
|
23
|
+
rule %r(^
|
24
|
+
(\s*(?:[a-zA-Z_][a-zA-Z0-9_.\[\]]*\s+)+?) # return arguments
|
25
|
+
([a-zA-Z_][a-zA-Z0-9_]*) # method name
|
26
|
+
(\s*)(\() # signature start
|
27
|
+
)mx do |m|
|
28
|
+
# TODO: do this better, this shouldn't need a delegation
|
29
|
+
delegate Java, m[1]
|
30
|
+
token 'Name.Function', m[2]
|
31
|
+
token 'Text', m[3]
|
32
|
+
token 'Punctuation', m[4]
|
33
|
+
end
|
34
|
+
|
35
|
+
rule /\s+/, 'Text'
|
36
|
+
rule %r(//.*?$), 'Comment.Single'
|
37
|
+
rule %r(/\*.*?\*/)m, 'Comment.Multiline'
|
38
|
+
rule /@#{id}/, 'Name.Decorator'
|
39
|
+
rule /(?:#{keywords.join('|')})\b/, 'Keyword'
|
40
|
+
rule /(?:#{declarations.join('|')})\b/, 'Keyword.Declaration'
|
41
|
+
rule /(?:#{types.join('|')})/, 'Keyword.Type'
|
42
|
+
rule /package\b/, 'Keyword.Namespace'
|
43
|
+
rule /(?:true|false|null)\b/, 'Keyword.Constant'
|
44
|
+
rule /(?:class|interface)\b/, 'Keyword.Declaration', :class
|
45
|
+
rule /import\b/, 'Keyword.Namespace', :import
|
46
|
+
rule /"(\\\\|\\"|[^"])*"/, 'Literal.String'
|
47
|
+
rule /'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, 'Literal.String.Char'
|
48
|
+
rule /(\.)(#{id})/ do
|
49
|
+
group 'Operator'
|
50
|
+
group 'Name.Attribute'
|
51
|
+
end
|
52
|
+
rule /#{id}:/, 'Name.Label'
|
53
|
+
rule /\$?#{id}/, 'Name'
|
54
|
+
rule /[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, 'Operator'
|
55
|
+
rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, 'Literal.Number.Float'
|
56
|
+
rule /0x[0-9a-f]+/, 'Literal.Number.Hex'
|
57
|
+
rule /[0-9]+L?/, 'Literal.Number.Integer'
|
58
|
+
# rule /\n/, 'Text'
|
59
|
+
end
|
60
|
+
|
61
|
+
state :class do
|
62
|
+
rule /\s+/m, 'Text'
|
63
|
+
rule id, 'Name.Class', :pop!
|
64
|
+
end
|
65
|
+
|
66
|
+
state :import do
|
67
|
+
rule /\s+/m, 'Text'
|
68
|
+
rule /[a-z0-9_.]+\*?/i, 'Name.Namespace', :pop!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rouge/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.9
|
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: 2012-09-
|
12
|
+
date: 2012-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -41,10 +41,13 @@ files:
|
|
41
41
|
- lib/rouge/lexers/javascript.rb
|
42
42
|
- lib/rouge/lexers/diff.rb
|
43
43
|
- lib/rouge/lexers/haskell.rb
|
44
|
+
- lib/rouge/lexers/c.rb
|
44
45
|
- lib/rouge/lexers/text.rb
|
45
46
|
- lib/rouge/lexers/html.rb
|
47
|
+
- lib/rouge/lexers/java.rb
|
46
48
|
- lib/rouge/lexers/tcl.rb
|
47
49
|
- lib/rouge/lexers/css.rb
|
50
|
+
- lib/rouge/lexers/cpp.rb
|
48
51
|
- lib/rouge/plugins/redcarpet.rb
|
49
52
|
- lib/rouge/themes/thankful_eyes.rb
|
50
53
|
- lib/rouge/themes/colorful.rb
|