rouge 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/Gemfile +2 -0
  2. data/bin/rougify +1 -1
  3. data/lib/rouge/demos/{text → plaintext} +0 -0
  4. data/lib/rouge/formatters/html.rb +13 -8
  5. data/lib/rouge/formatters/terminal256.rb +15 -11
  6. data/lib/rouge/lexer.rb +3 -1
  7. data/lib/rouge/lexers/c.rb +65 -55
  8. data/lib/rouge/lexers/clojure.rb +19 -19
  9. data/lib/rouge/lexers/coffeescript.rb +42 -42
  10. data/lib/rouge/lexers/common_lisp.rb +49 -48
  11. data/lib/rouge/lexers/conf.rb +6 -6
  12. data/lib/rouge/lexers/cpp.rb +48 -48
  13. data/lib/rouge/lexers/csharp.rb +25 -25
  14. data/lib/rouge/lexers/css.rb +32 -33
  15. data/lib/rouge/lexers/diff.rb +8 -8
  16. data/lib/rouge/lexers/elixir.rb +30 -30
  17. data/lib/rouge/lexers/erb.rb +5 -5
  18. data/lib/rouge/lexers/erlang.rb +38 -38
  19. data/lib/rouge/lexers/factor.rb +56 -56
  20. data/lib/rouge/lexers/gherkin.rb +27 -27
  21. data/lib/rouge/lexers/go.rb +21 -21
  22. data/lib/rouge/lexers/groovy.rb +32 -32
  23. data/lib/rouge/lexers/haml.rb +35 -35
  24. data/lib/rouge/lexers/handlebars.rb +27 -27
  25. data/lib/rouge/lexers/haskell.rb +78 -79
  26. data/lib/rouge/lexers/html.rb +28 -28
  27. data/lib/rouge/lexers/http.rb +13 -13
  28. data/lib/rouge/lexers/ini.rb +13 -13
  29. data/lib/rouge/lexers/io.rb +19 -19
  30. data/lib/rouge/lexers/java.rb +29 -29
  31. data/lib/rouge/lexers/javascript.rb +49 -52
  32. data/lib/rouge/lexers/literate_haskell.rb +5 -5
  33. data/lib/rouge/lexers/llvm.rb +14 -14
  34. data/lib/rouge/lexers/lua.rb +33 -33
  35. data/lib/rouge/lexers/make.rb +26 -26
  36. data/lib/rouge/lexers/markdown.rb +49 -49
  37. data/lib/rouge/lexers/nginx.rb +19 -19
  38. data/lib/rouge/lexers/perl.rb +53 -54
  39. data/lib/rouge/lexers/php.rb +42 -43
  40. data/lib/rouge/lexers/{text.rb → plain_text.rb} +3 -2
  41. data/lib/rouge/lexers/prolog.rb +19 -19
  42. data/lib/rouge/lexers/puppet.rb +40 -40
  43. data/lib/rouge/lexers/python.rb +63 -63
  44. data/lib/rouge/lexers/r.rb +15 -15
  45. data/lib/rouge/lexers/racket.rb +29 -29
  46. data/lib/rouge/lexers/ruby.rb +94 -97
  47. data/lib/rouge/lexers/rust.rb +37 -37
  48. data/lib/rouge/lexers/sass.rb +15 -15
  49. data/lib/rouge/lexers/sass/common.rb +144 -136
  50. data/lib/rouge/lexers/scheme.rb +25 -25
  51. data/lib/rouge/lexers/scss.rb +7 -7
  52. data/lib/rouge/lexers/sed.rb +39 -39
  53. data/lib/rouge/lexers/shell.rb +45 -45
  54. data/lib/rouge/lexers/smalltalk.rb +36 -36
  55. data/lib/rouge/lexers/sql.rb +27 -27
  56. data/lib/rouge/lexers/tcl.rb +34 -34
  57. data/lib/rouge/lexers/tex.rb +24 -24
  58. data/lib/rouge/lexers/toml.rb +18 -18
  59. data/lib/rouge/lexers/viml.rb +19 -19
  60. data/lib/rouge/lexers/xml.rb +16 -16
  61. data/lib/rouge/lexers/yaml.rb +78 -81
  62. data/lib/rouge/plugins/redcarpet.rb +1 -1
  63. data/lib/rouge/regex_lexer.rb +31 -14
  64. data/lib/rouge/template_lexer.rb +1 -1
  65. data/lib/rouge/theme.rb +12 -10
  66. data/lib/rouge/themes/thankful_eyes.rb +43 -43
  67. data/lib/rouge/token.rb +145 -148
  68. data/lib/rouge/version.rb +1 -1
  69. metadata +4 -4
@@ -85,52 +85,52 @@ module Rouge
85
85
  end
86
86
 
87
87
  state :root do
88
- rule /\s+/m, 'Text'
89
- rule /--.*?\n/, 'Comment.Single'
90
- rule %r(/\*), 'Comment.Multiline', :multiline_comments
91
- rule /\d+/, 'Literal.Number.Integer'
92
- rule /'/, 'Literal.String.Single', :single_string
93
- rule /"/, 'Name.Variable', :double_string
94
- rule /`/, 'Name.Variable', :backtick
88
+ rule /\s+/m, Text
89
+ rule /--.*?\n/, Comment::Single
90
+ rule %r(/\*), Comment::Multiline, :multiline_comments
91
+ rule /\d+/, Num::Integer
92
+ rule /'/, Str::Single, :single_string
93
+ rule /"/, Name::Variable, :double_string
94
+ rule /`/, Name::Variable, :backtick
95
95
 
96
96
  rule /\w[\w\d]*/ do |m|
97
97
  if self.class.keywords.include? m[0].upcase
98
- token 'Keyword'
98
+ token Keyword
99
99
  else
100
- token 'Name'
100
+ token Name
101
101
  end
102
102
  end
103
103
 
104
- rule %r([+*/<>=~!@#%^&|?^-]), 'Operator'
105
- rule /[;:()\[\],.]/, 'Punctuation'
104
+ rule %r([+*/<>=~!@#%^&|?^-]), Operator
105
+ rule /[;:()\[\],.]/, Punctuation
106
106
  end
107
107
 
108
108
  state :multiline_comments do
109
- rule %r(/[*]), 'Comment.Multiline', :multiline_comments
110
- rule %r([*]/), 'Comment.Multiline', :pop!
111
- rule %r([^/*]+), 'Comment.Multiline'
112
- rule %r([/*]), 'Comment.Multiline'
109
+ rule %r(/[*]), Comment::Multiline, :multiline_comments
110
+ rule %r([*]/), Comment::Multiline, :pop!
111
+ rule %r([^/*]+), Comment::Multiline
112
+ rule %r([/*]), Comment::Multiline
113
113
  end
114
114
 
115
115
  state :backtick do
116
- rule /\\./, 'Literal.String.Escape'
117
- rule /``/, 'Literal.String.Escape'
118
- rule /`/, 'Name.Variable', :pop!
119
- rule /[^\\`]+/, 'Name.Variable'
116
+ rule /\\./, Str::Escape
117
+ rule /``/, Str::Escape
118
+ rule /`/, Name::Variable, :pop!
119
+ rule /[^\\`]+/, Name::Variable
120
120
  end
121
121
 
122
122
  state :single_string do
123
- rule /\\./, 'Literal.String.Escape'
124
- rule /''/, 'Literal.String.Escape'
125
- rule /'/, 'Literal.String.Single', :pop!
126
- rule /[^\\']+/, 'Literal.String.Single'
123
+ rule /\\./, Str::Escape
124
+ rule /''/, Str::Escape
125
+ rule /'/, Str::Single, :pop!
126
+ rule /[^\\']+/, Str::Single
127
127
  end
128
128
 
129
129
  state :double_string do
130
- rule /\\./, 'Literal.String.Escape'
131
- rule /""/, 'Literal.String.Escape'
132
- rule /"/, 'Name.Variable', :pop!
133
- rule /[^\\"]+/, 'Name.Variable'
130
+ rule /\\./, Str::Escape
131
+ rule /""/, Str::Escape
132
+ rule /"/, Name::Variable, :pop!
133
+ rule /[^\\"]+/, Name::Variable
134
134
  end
135
135
  end
136
136
  end
@@ -41,21 +41,21 @@ module Rouge
41
41
  NOT_CHARS = lambda { |list| Regexp.new %/[^#{list.join}]/ }
42
42
 
43
43
  state :word do
44
- rule /\{\*\}/, 'Keyword'
44
+ rule /\{\*\}/, Keyword
45
45
 
46
46
  mixin :brace_abort
47
47
  mixin :interp
48
- rule /\{/, 'Punctuation', :brace
49
- rule /\(/, 'Punctuation', :paren
50
- rule /"/, 'Literal.String.Double', :string
51
- rule /#{NOT_CHARS[END_WORD]}+?(?=#{CHARS[OPEN+['\\\\']]})/, 'Text'
48
+ rule /\{/, Punctuation, :brace
49
+ rule /\(/, Punctuation, :paren
50
+ rule /"/, Str::Double, :string
51
+ rule /#{NOT_CHARS[END_WORD]}+?(?=#{CHARS[OPEN+['\\\\']]})/, Text
52
52
  end
53
53
 
54
54
  def self.gen_command_state(name='')
55
55
  state(:"command#{name}") do
56
56
  mixin :word
57
57
 
58
- rule /##{NOT_CHARS[END_LINE]}+/, 'Comment.Single'
58
+ rule /##{NOT_CHARS[END_LINE]}+/, Comment::Single
59
59
 
60
60
  rule /(?=#{CHARS[END_WORD]})/ do
61
61
  push :"params#{name}"
@@ -63,11 +63,11 @@ module Rouge
63
63
 
64
64
  rule /#{NOT_CHARS[END_WORD]}+/ do |m|
65
65
  if KEYWORDS.include? m[0]
66
- token 'Keyword'
66
+ token Keyword
67
67
  elsif BUILTINS.include? m[0]
68
- token 'Name.Builtin'
68
+ token Name::Builtin
69
69
  else
70
- token 'Text'
70
+ token Text
71
71
  end
72
72
  end
73
73
 
@@ -80,24 +80,24 @@ module Rouge
80
80
 
81
81
  state :"params_in_#{name}" do
82
82
  rule close do
83
- token 'Punctuation'
84
- pop!; pop!
83
+ token Punctuation
84
+ pop! 2
85
85
  end
86
86
 
87
87
  # mismatched delimiters. Braced strings with mismatched
88
88
  # closing delimiters should be okay, since this is standard
89
89
  # practice, like {]]]]}
90
90
  if opts[:strict]
91
- rule CHARS[CLOSE - [close]], 'Error'
91
+ rule CHARS[CLOSE - [close]], Error
92
92
  else
93
- rule CHARS[CLOSE - [close]], 'Text'
93
+ rule CHARS[CLOSE - [close]], Text
94
94
  end
95
95
 
96
96
  mixin :params
97
97
  end
98
98
 
99
99
  state name do
100
- rule close, 'Punctuation', :pop!
100
+ rule close, Punctuation, :pop!
101
101
  mixin :"command_in_#{name}"
102
102
  end
103
103
  end
@@ -116,20 +116,20 @@ module Rouge
116
116
  if in_state? :brace
117
117
  pop! until state? :brace
118
118
  pop!
119
- token 'Punctuation'
119
+ token Punctuation
120
120
  else
121
- token 'Error'
121
+ token Error
122
122
  end
123
123
  end
124
124
  end
125
125
 
126
126
  state :params do
127
- rule /;/, 'Punctuation', :pop!
128
- rule /\n/, 'Text', :pop!
129
- rule /else|elseif|then/, 'Keyword'
127
+ rule /;/, Punctuation, :pop!
128
+ rule /\n/, Text, :pop!
129
+ rule /else|elseif|then/, Keyword
130
130
  mixin :word
131
131
  mixin :whitespace
132
- rule /#{NOT_CHARS[END_WORD]}+/, 'Text'
132
+ rule /#{NOT_CHARS[END_WORD]}+/, Text
133
133
  end
134
134
 
135
135
  gen_delimiter_states :brace, /\}/, :strict => false
@@ -143,26 +143,26 @@ module Rouge
143
143
 
144
144
  state :whitespace do
145
145
  # not a multiline regex because we want to capture \n sometimes
146
- rule /\s+/, 'Text'
146
+ rule /\s+/, Text
147
147
  end
148
148
 
149
149
  state :interp do
150
- rule /\[/, 'Punctuation', :bracket
151
- rule /\$[a-z0-9.:-]+/, 'Name.Variable'
152
- rule /\$\{.*?\}/m, 'Name.Variable'
153
- rule /\$/, 'Text'
150
+ rule /\[/, Punctuation, :bracket
151
+ rule /\$[a-z0-9.:-]+/, Name::Variable
152
+ rule /\$\{.*?\}/m, Name::Variable
153
+ rule /\$/, Text
154
154
 
155
155
  # escape sequences
156
- rule /\\[0-7]{3}/, 'Literal.String.Escape'
157
- rule /\\x[0-9a-f]{2}/i, 'Literal.String.Escape'
158
- rule /\\u[0-9a-f]{4}/i, 'Literal.String.Escape'
159
- rule /\\./m, 'Literal.String.Escape'
156
+ rule /\\[0-7]{3}/, Str::Escape
157
+ rule /\\x[0-9a-f]{2}/i, Str::Escape
158
+ rule /\\u[0-9a-f]{4}/i, Str::Escape
159
+ rule /\\./m, Str::Escape
160
160
  end
161
161
 
162
162
  state :string do
163
- rule /"/, 'Literal.String.Double', :pop!
163
+ rule /"/, Str::Double, :pop!
164
164
  mixin :interp
165
- rule /[^\\\[\$"{}]+/m, 'Literal.String.Double'
165
+ rule /[^\\\[\$"{}]+/m, Str::Double
166
166
 
167
167
  # strings have to keep count of their internal braces, to support
168
168
  # for example { "{ }" }.
@@ -170,17 +170,17 @@ module Rouge
170
170
  @brace_count ||= 0
171
171
  @brace_count += 1
172
172
 
173
- token 'Literal.String.Double'
173
+ token Str::Double
174
174
  end
175
175
 
176
176
  rule /}/ do
177
177
  if in_state? :brace and @brace_count.to_i == 0
178
178
  pop! until state? :brace
179
179
  pop!
180
- token 'Punctuation'
180
+ token Punctuation
181
181
  else
182
182
  @brace_count -= 1
183
- token 'Literal.String.Double'
183
+ token Str::Double
184
184
  end
185
185
  end
186
186
  end
@@ -18,53 +18,53 @@ module Rouge
18
18
  command = /\\([a-z]+|\s+|.)/i
19
19
 
20
20
  state :general do
21
- rule /%.*$/, 'Comment'
22
- rule /[{}&_^]/, 'Punctuation'
21
+ rule /%.*$/, Comment
22
+ rule /[{}&_^]/, Punctuation
23
23
  end
24
24
 
25
25
  state :root do
26
- rule /\\\[/, 'Punctuation', :displaymath
27
- rule /\\\(/, 'Punctuation', :inlinemath
28
- rule /\$\$/, 'Punctuation', :displaymath
29
- rule /\$/, 'Punctuation', :inlinemath
30
- rule /\\(begin|end)\{.*?\}/, 'Name.Tag'
26
+ rule /\\\[/, Punctuation, :displaymath
27
+ rule /\\\(/, Punctuation, :inlinemath
28
+ rule /\$\$/, Punctuation, :displaymath
29
+ rule /\$/, Punctuation, :inlinemath
30
+ rule /\\(begin|end)\{.*?\}/, Name::Tag
31
31
 
32
32
  rule /(\\verb)\b(\S)(.*?)(\2)/ do |m|
33
- group 'Name.Builtin'
34
- group 'Keyword.Pseudo'
35
- group 'Literal.String.Other'
36
- group 'Keyword.Pseudo'
33
+ group Name::Builtin
34
+ group Keyword::Pseudo
35
+ group Str::Other
36
+ group Keyword::Pseudo
37
37
  end
38
38
 
39
- rule command, 'Keyword', :command
39
+ rule command, Keyword, :command
40
40
  mixin :general
41
- rule /[^\\$%&_^{}]+/, 'Text'
41
+ rule /[^\\$%&_^{}]+/, Text
42
42
  end
43
43
 
44
44
  state :math do
45
- rule command, 'Name.Variable'
45
+ rule command, Name::Variable
46
46
  mixin :general
47
- rule /[0-9]+/, 'Literal.Number'
48
- rule /[-=!+*\/()\[\]]/, 'Operator'
49
- rule /[^=!+*\/()\[\]\\$%&_^{}0-9-]+/, 'Name.Builtin'
47
+ rule /[0-9]+/, Num
48
+ rule /[-=!+*\/()\[\]]/, Operator
49
+ rule /[^=!+*\/()\[\]\\$%&_^{}0-9-]+/, Name::Builtin
50
50
  end
51
51
 
52
52
  state :inlinemath do
53
- rule /\\\)/, 'Punctuation', :pop!
54
- rule /\$/, 'Punctuation', :pop!
53
+ rule /\\\)/, Punctuation, :pop!
54
+ rule /\$/, Punctuation, :pop!
55
55
  mixin :math
56
56
  end
57
57
 
58
58
  state :displaymath do
59
- rule /\\\]/, 'Punctuation', :pop!
60
- rule /\$\$/, 'Punctuation', :pop!
61
- rule /\$/, 'Name.Builtin'
59
+ rule /\\\]/, Punctuation, :pop!
60
+ rule /\$\$/, Punctuation, :pop!
61
+ rule /\$/, Name::Builtin
62
62
  mixin :math
63
63
  end
64
64
 
65
65
  state :command do
66
- rule /\[.*?\]/, 'Name.Attribute'
67
- rule /\*/, 'Keyword'
66
+ rule /\[.*?\]/, Name::Attribute
67
+ rule /\*/, Keyword
68
68
  rule(//) { pop! }
69
69
  end
70
70
  end
@@ -14,55 +14,55 @@ module Rouge
14
14
  identifier = /[\w.\S]+/
15
15
 
16
16
  state :basic do
17
- rule /\s+/, 'Text'
18
- rule /#.*?$/, 'Comment'
19
- rule /(true|false)/, 'Keyword.Constant'
20
- rule /(?<!=)\s*\[[\w\d\S]+\]/, 'Name.Namespace'
17
+ rule /\s+/, Text
18
+ rule /#.*?$/, Comment
19
+ rule /(true|false)/, Keyword::Constant
20
+ rule /(?<!=)\s*\[[\w\d\S]+\]/, Name::Namespace
21
21
 
22
- rule /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, 'Literal.Date'
22
+ rule /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date
23
23
 
24
- rule /(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?/, 'Literal.Number.Float'
25
- rule /\d+[eE][+-]?[0-9]+j?/, 'Literal.Number.Float'
26
- rule /\-?\d+/, 'Literal.Number.Integer'
24
+ rule /(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?/, Num::Float
25
+ rule /\d+[eE][+-]?[0-9]+j?/, Num::Float
26
+ rule /\-?\d+/, Num::Integer
27
27
  end
28
28
 
29
29
  state :root do
30
30
  mixin :basic
31
31
 
32
32
  rule /(#{identifier})(\s*)(=)/ do
33
- group 'Name.Property'; group 'Text'
34
- group 'Punctuation'
33
+ group Name::Property; group Text
34
+ group Punctuation
35
35
  push :value
36
36
  end
37
37
 
38
38
  end
39
39
 
40
40
  state :value do
41
- rule /\n/, 'Text', :pop!
41
+ rule /\n/, Text, :pop!
42
42
  mixin :content
43
43
  end
44
44
 
45
45
  state :content do
46
46
  mixin :basic
47
- rule /"/, 'Literal.String', :dq
47
+ rule /"/, Str, :dq
48
48
  mixin :esc_str
49
- rule /\,/, 'Punctuation'
50
- rule /\[/, 'Punctuation', :array
49
+ rule /\,/, Punctuation
50
+ rule /\[/, Punctuation, :array
51
51
  end
52
52
 
53
53
  state :dq do
54
- rule /"/, 'Literal.String', :pop!
54
+ rule /"/, Str, :pop!
55
55
  mixin :esc_str
56
- rule /[^\\"]+/, 'Literal.String'
56
+ rule /[^\\"]+/, Str
57
57
  end
58
58
 
59
59
  state :esc_str do
60
- rule /\\[0t\tn\n "\\ r]/, 'Literal.String.Escape'
60
+ rule /\\[0t\tn\n "\\ r]/, Str::Escape
61
61
  end
62
62
 
63
63
  state :array do
64
64
  mixin :content
65
- rule /\]/, 'Punctuation', :pop!
65
+ rule /\]/, Punctuation, :pop!
66
66
  end
67
67
  end
68
68
  end
@@ -16,48 +16,48 @@ module Rouge
16
16
 
17
17
  state :root do
18
18
  rule /^(\s*)(".*?)$/ do
19
- group 'Text'; group 'Comment'
19
+ group Text; group Comment
20
20
  end
21
21
 
22
- rule /^\s*\\/, 'Literal.String.Escape'
22
+ rule /^\s*\\/, Str::Escape
23
23
 
24
- rule /[ \t]+/, 'Text'
24
+ rule /[ \t]+/, Text
25
25
 
26
26
  # TODO: regexes can have other delimiters
27
- rule %r(/(\\\\|\\/|[^\n/])*/), 'Literal.String.Regex'
28
- rule %r("(\\\\|\\"|[^\n"])*"), 'Literal.String.Double'
29
- rule %r('(\\\\|\\'|[^\n'])*'), 'Literal.String.Single'
27
+ rule %r(/(\\\\|\\/|[^\n/])*/), Str::Regex
28
+ rule %r("(\\\\|\\"|[^\n"])*"), Str::Double
29
+ rule %r('(\\\\|\\'|[^\n'])*'), Str::Single
30
30
 
31
31
  # if it's not a string, it's a comment.
32
- rule /(?<=\s)"[^-:.%#=*].*?$/, 'Comment'
32
+ rule /(?<=\s)"[^-:.%#=*].*?$/, Comment
33
33
 
34
- rule /-?\d+/, 'Literal.Number'
35
- rule /#[0-9a-f]{6}/i, 'Literal.Number.Hex'
36
- rule /^:/, 'Punctuation'
37
- rule /[():<>+=!\[\]{}\|,~.-]/, 'Punctuation'
34
+ rule /-?\d+/, Num
35
+ rule /#[0-9a-f]{6}/i, Num::Hex
36
+ rule /^:/, Punctuation
37
+ rule /[():<>+=!\[\]{}\|,~.-]/, Punctuation
38
38
  rule /\b(let|if|else|endif|elseif|fun|function|endfunction)\b/,
39
- 'Keyword'
39
+ Keyword
40
40
 
41
- rule /\b(NONE|bold|italic|underline|dark|light)\b/, 'Name.Builtin'
41
+ rule /\b(NONE|bold|italic|underline|dark|light)\b/, Name::Builtin
42
42
 
43
- rule /[absg]:\w+\b/, 'Name.Variable'
43
+ rule /[absg]:\w+\b/, Name::Variable
44
44
  rule /\b\w+\b/ do |m|
45
45
  name = m[0]
46
46
  keywords = self.class.keywords
47
47
 
48
48
  if mapping_contains?(keywords[:command], name)
49
- token 'Keyword'
49
+ token Keyword
50
50
  elsif mapping_contains?(keywords[:option], name)
51
- token 'Name.Builtin'
51
+ token Name::Builtin
52
52
  elsif mapping_contains?(keywords[:auto], name)
53
- token 'Name.Builtin'
53
+ token Name::Builtin
54
54
  else
55
- token 'Text'
55
+ token Text
56
56
  end
57
57
  end
58
58
 
59
59
  # no errors in VimL!
60
- rule /./m, 'Text'
60
+ rule /./m, Text
61
61
  end
62
62
 
63
63
  def mapping_contains?(mapping, word)