rouge 0.2.7 → 0.2.8
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/demos/nginx +5 -0
- data/lib/rouge/formatters/html.rb +3 -0
- data/lib/rouge/lexers/nginx.rb +67 -0
- data/lib/rouge/lexers/objective_c.rb +104 -0
- data/lib/rouge/regex_lexer.rb +4 -1
- data/lib/rouge/version.rb +1 -1
- metadata +5 -2
@@ -40,6 +40,9 @@ module Rouge
|
|
40
40
|
span(tok, val) { |str| code << str }
|
41
41
|
end
|
42
42
|
|
43
|
+
# add an extra line number for non-newline-terminated strings
|
44
|
+
num_lines += 1 if code[-1] != "\n"
|
45
|
+
|
43
46
|
# generate a string of newline-separated line numbers for the gutter
|
44
47
|
numbers = num_lines.times.map do |x|
|
45
48
|
%<<div class="lineno">#{x+1}</div>>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class Nginx < RegexLexer
|
4
|
+
tag 'nginx'
|
5
|
+
mimetypes 'text/x-nginx-conf'
|
6
|
+
|
7
|
+
id = /[^\s$;{}()#]+/
|
8
|
+
|
9
|
+
state :root do
|
10
|
+
rule /(include)(\s+)([^\s;]+)/ do
|
11
|
+
group 'Keyword'; group 'Text'; group 'Name'
|
12
|
+
end
|
13
|
+
|
14
|
+
rule id, 'Keyword', :statement
|
15
|
+
|
16
|
+
mixin :base
|
17
|
+
end
|
18
|
+
|
19
|
+
state :block do
|
20
|
+
rule /}/, 'Punctuation', :pop!
|
21
|
+
rule id, 'Keyword.Namespace', :statement
|
22
|
+
mixin :base
|
23
|
+
end
|
24
|
+
|
25
|
+
state :statement do
|
26
|
+
rule /{/ do
|
27
|
+
token 'Punctuation'; pop!; push :block
|
28
|
+
end
|
29
|
+
|
30
|
+
rule /;/, 'Punctuation', :pop!
|
31
|
+
|
32
|
+
mixin :base
|
33
|
+
end
|
34
|
+
|
35
|
+
state :base do
|
36
|
+
rule /\s+/, 'Text'
|
37
|
+
|
38
|
+
rule /#.*?\n/, 'Comment.Single'
|
39
|
+
rule /(?:on|off)\b/, 'Name.Constant'
|
40
|
+
rule /[$][\w-]+/, 'Name.Variable'
|
41
|
+
|
42
|
+
# host/port
|
43
|
+
rule /([a-z0-9.-]+)(:)([0-9]+)/i do
|
44
|
+
group 'Name.Function'; group 'Punctuation'
|
45
|
+
group 'Literal.Number.Integer'
|
46
|
+
end
|
47
|
+
|
48
|
+
# mimetype
|
49
|
+
rule %r([a-z-]+/[a-z-]+)i, 'Name.Class'
|
50
|
+
|
51
|
+
rule /[0-9]+[kmg]?\b/i, 'Literal.Number.Integer'
|
52
|
+
rule /(~)(\s*)([^\s{]+)/ do
|
53
|
+
group 'Punctuation'; group 'Text'; group 'Literal.String.Regex'
|
54
|
+
end
|
55
|
+
|
56
|
+
rule /[:=~]/, 'Punctuation'
|
57
|
+
|
58
|
+
# pathname
|
59
|
+
rule %r(/#{id}?), 'Name'
|
60
|
+
|
61
|
+
rule /[^#\s;{}$\\]+/, 'Literal.String' # catchall
|
62
|
+
|
63
|
+
rule /[$;]/, 'Text'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Rouge
|
2
|
+
module Lexers
|
3
|
+
class ObjectiveC < RegexLexer
|
4
|
+
tag 'objective_c'
|
5
|
+
aliases 'objective-c', 'objectivec', 'obj_c', 'obj-c', 'objc'
|
6
|
+
# XXX TODO: objc has .h files too
|
7
|
+
filenames '*.m'
|
8
|
+
mimetypes 'text/x-objective-c'
|
9
|
+
|
10
|
+
id = /[a-zA-Z$_][a-zA-Z0-9$_]*/
|
11
|
+
|
12
|
+
def self.decorators
|
13
|
+
@decorators = Set.new %w(
|
14
|
+
private protected public encode synchronized try throw catch
|
15
|
+
finally end property synthesize dynamic selector
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.keywords_type
|
20
|
+
@keywords_type ||= Set.new %w(
|
21
|
+
int long float short double char unsigned signed void id BOOL
|
22
|
+
IBOutlet IBAction SEL
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.keywords
|
27
|
+
@keywords ||= Set.new %w(
|
28
|
+
auto break case const continue default do else enum extern
|
29
|
+
for goto if register restricted return sizeof static struct
|
30
|
+
switch typedef union volatile virtual while in
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.reserved
|
35
|
+
@reserved ||= Set.new %w(
|
36
|
+
inline naked restrict thread typename
|
37
|
+
_inline _naked _restrict _thread _typename
|
38
|
+
__inline __naked __restrict __thread __typename
|
39
|
+
|
40
|
+
__asm __int8 __based __except __int16 __stdcall __cdecl
|
41
|
+
__fastcall __int32 __declspec __finally __int64 __try __leave
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
state :whitespace do
|
46
|
+
rule /^\s*#if\s+0/, 'Comment', :if0
|
47
|
+
rule /^\s*#/, 'Comment.Preproc', :macro
|
48
|
+
rule /\n/, 'Text'
|
49
|
+
rule /\s+/, 'Text'
|
50
|
+
rule /\\\n/, 'Literal.String.Escape'
|
51
|
+
rule %r(//(\\.|.)*?\n), 'Comment.Single'
|
52
|
+
rule %r(/[*].*?[*]/), 'Comment.Multiline'
|
53
|
+
end
|
54
|
+
|
55
|
+
state :statements do
|
56
|
+
rule /[L@]?"/, 'Literal.String', :string
|
57
|
+
rule /(L|@)?'(\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\'\n]|\\.)'/,
|
58
|
+
'Literal.String.Char'
|
59
|
+
rule /(\d+[.]\d*|[.]\d+|\d+)e[+-]?\d+l?/i, 'Literal.Number.Float'
|
60
|
+
rule /(\d+[.]\d*|[.]\d+)f?/i, 'Literal.Number.Float'
|
61
|
+
rule /\d+f/i, 'Literal.Number.Float'
|
62
|
+
rule /0x[0-9a-f]+l?/i, 'Literal.Number.Hex'
|
63
|
+
rule /0[0-7]+l?/i, 'Literal.Number.Oct'
|
64
|
+
rule /\d+l?/i, 'Literal.Number.Integer'
|
65
|
+
rule %r([~!%^&*+=|?:<>/-]), 'Operator'
|
66
|
+
rule /[()\[\],.]/, 'Punctuation'
|
67
|
+
|
68
|
+
rule /#{id}:(?!:)/, 'Name.Label'
|
69
|
+
|
70
|
+
rule /@(#{id})/ do |m|
|
71
|
+
if self.class.decorators.include? m[1]
|
72
|
+
token 'Keyword'
|
73
|
+
else
|
74
|
+
token 'Error'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
rule /(TRUE|FALSE|nil|NULL)\b/, 'Name.Builtin'
|
79
|
+
|
80
|
+
rule id do |m|
|
81
|
+
name = m[0]
|
82
|
+
|
83
|
+
if self.class.keywords.include? name
|
84
|
+
token 'Keyword'
|
85
|
+
elsif self.class.keywords_type.include? name
|
86
|
+
token 'Keyword.Type'
|
87
|
+
elsif self.class.reserved.include? name
|
88
|
+
token 'Keyword.Reserved'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
state :root do
|
94
|
+
mixin :whitespace
|
95
|
+
|
96
|
+
rule %r(
|
97
|
+
([a-zA-Z0-9_*\s]+?[\s*]) # return arguments
|
98
|
+
(#{id}) # method name
|
99
|
+
(\s*[(][^;]*?[)]) # signature
|
100
|
+
)x
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/rouge/regex_lexer.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.8
|
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-10-
|
12
|
+
date: 2012-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -37,6 +37,7 @@ extra_rdoc_files: []
|
|
37
37
|
files:
|
38
38
|
- Gemfile
|
39
39
|
- lib/rouge/util.rb
|
40
|
+
- lib/rouge/lexers/nginx.rb
|
40
41
|
- lib/rouge/lexers/python.rb
|
41
42
|
- lib/rouge/lexers/sql.rb
|
42
43
|
- lib/rouge/lexers/common_lisp.rb
|
@@ -53,6 +54,7 @@ files:
|
|
53
54
|
- lib/rouge/lexers/javascript.rb
|
54
55
|
- lib/rouge/lexers/diff.rb
|
55
56
|
- lib/rouge/lexers/viml.rb
|
57
|
+
- lib/rouge/lexers/objective_c.rb
|
56
58
|
- lib/rouge/lexers/smalltalk.rb
|
57
59
|
- lib/rouge/lexers/php/builtins.rb
|
58
60
|
- lib/rouge/lexers/haskell.rb
|
@@ -118,6 +120,7 @@ files:
|
|
118
120
|
- lib/rouge/demos/yaml
|
119
121
|
- lib/rouge/demos/sql
|
120
122
|
- lib/rouge/demos/groovy
|
123
|
+
- lib/rouge/demos/nginx
|
121
124
|
- lib/rouge/demos/tcl
|
122
125
|
- lib/rouge/demos/c
|
123
126
|
- lib/rouge/demos/perl
|