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
@@ -23,160 +23,159 @@ module Rouge
23
23
  )
24
24
 
25
25
  state :basic do
26
- rule /\s+/m, 'Text'
27
- rule /{-#/, 'Comment.Preproc', :comment_preproc
28
- rule /{-/, 'Comment.Multiline', :comment
29
- rule /^--\s+\|.*?$/, 'Comment.Doc'
26
+ rule /\s+/m, Text
27
+ rule /{-#/, Comment::Preproc, :comment_preproc
28
+ rule /{-/, Comment::Multiline, :comment
29
+ rule /^--\s+\|.*?$/, Comment::Doc
30
30
  # this is complicated in order to support custom symbols
31
31
  # like -->
32
- rule /--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, 'Comment.Single'
32
+ rule /--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
33
33
  end
34
34
 
35
35
  # nested commenting
36
36
  state :comment do
37
- rule /-}/, 'Comment.Multiline', :pop!
38
- rule /{-/, 'Comment.Multiline', :comment
39
- rule /[^-{}]+/, 'Comment.Multiline'
40
- rule /[-{}]/, 'Comment.Multiline'
37
+ rule /-}/, Comment::Multiline, :pop!
38
+ rule /{-/, Comment::Multiline, :comment
39
+ rule /[^-{}]+/, Comment::Multiline
40
+ rule /[-{}]/, Comment::Multiline
41
41
  end
42
42
 
43
43
  state :comment_preproc do
44
- rule /-}/, 'Comment.Preproc', :pop!
45
- rule /{-/, 'Comment.Preproc', :comment
46
- rule /[^-{}]+/, 'Comment.Preproc'
47
- rule /[-{}]/, 'Comment.Preproc'
44
+ rule /-}/, Comment::Preproc, :pop!
45
+ rule /{-/, Comment::Preproc, :comment
46
+ rule /[^-{}]+/, Comment::Preproc
47
+ rule /[-{}]/, Comment::Preproc
48
48
  end
49
49
 
50
50
  state :root do
51
51
  mixin :basic
52
52
 
53
- rule /\bimport\b/, 'Keyword.Reserved', :import
54
- rule /\bmodule\b/, 'Keyword.Reserved', :module
55
- rule /\berror\b/, 'Name.Exception'
56
- rule /\b(?:#{reserved.join('|')})\b/, 'Keyword.Reserved'
53
+ rule /\bimport\b/, Keyword::Reserved, :import
54
+ rule /\bmodule\b/, Keyword::Reserved, :module
55
+ rule /\berror\b/, Name::Exception
56
+ rule /\b(?:#{reserved.join('|')})\b/, Keyword::Reserved
57
57
  # not sure why, but ^ doesn't work here
58
- # rule /^[_a-z][\w']*/, 'Name.Function'
59
- rule /[_a-z][\w']*/, 'Name'
60
- rule /[A-Z][\w']*/, 'Keyword.Type'
58
+ # rule /^[_a-z][\w']*/, Name::Function
59
+ rule /[_a-z][\w']*/, Name
60
+ rule /[A-Z][\w']*/, Keyword::Type
61
61
 
62
62
  # lambda operator
63
- rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), 'Name.Function'
63
+ rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
64
64
  # special operators
65
- rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), 'Operator'
65
+ rule %r((<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Operator
66
66
  # constructor/type operators
67
- rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), 'Operator'
67
+ rule %r(:[:!#\$\%&*+.\\/<=>?@^\|~-]*), Operator
68
68
  # other operators
69
- rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), 'Operator'
69
+ rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), Operator
70
70
 
71
- rule /\d+e[+-]?\d+/i, 'Literal.Number.Float'
72
- rule /\d+\.\d+(e[+-]?\d+)?/i, 'Literal.Number.Float'
73
- rule /0o[0-7]+/i, 'Literal.Number.Oct'
74
- rule /0x[\da-f]+/i, 'Literal.Number.Hex'
75
- rule /\d+/, 'Literal.Number.Integer'
71
+ rule /\d+e[+-]?\d+/i, Num::Float
72
+ rule /\d+\.\d+(e[+-]?\d+)?/i, Num::Float
73
+ rule /0o[0-7]+/i, Num::Oct
74
+ rule /0x[\da-f]+/i, Num::Hex
75
+ rule /\d+/, Num::Integer
76
76
 
77
- rule /'/, 'Literal.String.Char', :character
78
- rule /"/, 'Literal.String', :string
77
+ rule /'/, Str::Char, :character
78
+ rule /"/, Str, :string
79
79
 
80
- rule /\[\s*\]/, 'Keyword.Type'
81
- rule /\(\s*\)/, 'Name.Builtin'
82
- rule /[\[\](),;`{}]/, 'Punctuation'
80
+ rule /\[\s*\]/, Keyword::Type
81
+ rule /\(\s*\)/, Name::Builtin
82
+ rule /[\[\](),;`{}]/, Punctuation
83
83
  end
84
84
 
85
85
  state :import do
86
- rule /\s+/, 'Text'
87
- rule /"/, 'Literal.String', :string
88
- rule /\bqualified\b/, 'Keyword'
86
+ rule /\s+/, Text
87
+ rule /"/, Str, :string
88
+ rule /\bqualified\b/, Keyword
89
89
  # import X as Y
90
90
  rule /([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
91
- group 'Name.Namespace' # X
92
- group 'Text'
93
- group 'Keyword' # as
94
- group 'Text'
95
- group 'Name' # Y
91
+ group Name::Namespace # X
92
+ group Text
93
+ group Keyword # as
94
+ group Text
95
+ group Name # Y
96
96
  pop!
97
97
  end
98
98
 
99
99
  # import X hiding (functions)
100
100
  rule /([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
101
- group 'Name.Namespace' # X
102
- group 'Text'
103
- group 'Keyword' # hiding
104
- group 'Text'
105
- group 'Punctuation' # (
101
+ group Name::Namespace # X
102
+ group Text
103
+ group Keyword # hiding
104
+ group Text
105
+ group Punctuation # (
106
106
  pop!
107
107
  push :funclist
108
108
  end
109
109
 
110
110
  # import X (functions)
111
111
  rule /([A-Z][\w.]*)(\s+)(\()/ do
112
- group 'Name.Namespace' # X
113
- group 'Text'
114
- group 'Punctuation' # (
112
+ group Name::Namespace # X
113
+ group Text
114
+ group Punctuation # (
115
115
  pop!
116
116
  push :funclist
117
117
  end
118
118
 
119
- rule /[\w.]+/, 'Name.Namespace', :pop!
119
+ rule /[\w.]+/, Name::Namespace, :pop!
120
120
  end
121
121
 
122
122
  state :module do
123
- rule /\s+/, 'Text'
123
+ rule /\s+/, Text
124
124
  # module Foo (functions)
125
125
  rule /([A-Z][\w.]*)(\s+)(\()/ do
126
- group 'Name.Namespace'
127
- group 'Text'
128
- group 'Punctuation'
126
+ group Name::Namespace
127
+ group Text
128
+ group Punctuation
129
129
  push :funclist
130
130
  end
131
131
 
132
- rule /\bwhere\b/, 'Keyword.Reserved', :pop!
132
+ rule /\bwhere\b/, Keyword::Reserved, :pop!
133
133
 
134
- rule /[A-Z][a-zA-Z0-9_.]*/, 'Name.Namespace', :pop!
134
+ rule /[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
135
135
  end
136
136
 
137
137
  state :funclist do
138
138
  mixin :basic
139
- rule /[A-Z]\w*/, 'Keyword.Type'
140
- rule /(_[\w\']+|[a-z][\w\']*)/, 'Name.Function'
141
- rule /,/, 'Punctuation'
142
- rule /[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, 'Operator'
143
- rule /\(/, 'Punctuation', :funclist
144
- rule /\)/, 'Punctuation', :pop!
139
+ rule /[A-Z]\w*/, Keyword::Type
140
+ rule /(_[\w\']+|[a-z][\w\']*)/, Name::Function
141
+ rule /,/, Punctuation
142
+ rule /[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
143
+ rule /\(/, Punctuation, :funclist
144
+ rule /\)/, Punctuation, :pop!
145
145
  end
146
146
 
147
147
  state :character do
148
148
  rule /\\/ do
149
- token 'Literal.String.Escape'
149
+ token Str::Escape
150
150
  push :character_end
151
151
  push :escape
152
152
  end
153
153
 
154
154
  rule /./ do
155
- token 'Literal.String.Char'
156
- pop!
157
- push :character_end
155
+ token Str::Char
156
+ goto :character_end
158
157
  end
159
158
  end
160
159
 
161
160
  state :character_end do
162
- rule /'/, 'Literal.String.Char', :pop!
163
- rule /./, 'Error', :pop!
161
+ rule /'/, Str::Char, :pop!
162
+ rule /./, Error, :pop!
164
163
  end
165
164
 
166
165
  state :string do
167
- rule /"/, 'Literal.String', :pop!
168
- rule /\\/, 'Literal.String.Escape', :escape
169
- rule /[^\\"]+/, 'Literal.String'
166
+ rule /"/, Str, :pop!
167
+ rule /\\/, Str::Escape, :escape
168
+ rule /[^\\"]+/, Str
170
169
  end
171
170
 
172
171
  state :escape do
173
- rule /[abfnrtv"'&\\]/, 'Literal.String.Escape', :pop!
174
- rule /\^[\]\[A-Z@\^_]/, 'Literal.String.Escape', :pop!
175
- rule /#{ascii.join('|')}/, 'Literal.String.Escape', :pop!
176
- rule /o[0-7]+/i, 'Literal.String.Escape', :pop!
177
- rule /x[\da-f]/i, 'Literal.String.Escape', :pop!
178
- rule /\d+/, 'Literal.String.Escape', :pop!
179
- rule /\s+\\/, 'Literal.String.Escape', :pop!
172
+ rule /[abfnrtv"'&\\]/, Str::Escape, :pop!
173
+ rule /\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
174
+ rule /#{ascii.join('|')}/, Str::Escape, :pop!
175
+ rule /o[0-7]+/i, Str::Escape, :pop!
176
+ rule /x[\da-f]/i, Str::Escape, :pop!
177
+ rule /\d+/, Str::Escape, :pop!
178
+ rule /\s+\\/, Str::Escape, :pop!
180
179
  end
181
180
  end
182
181
  end
@@ -12,76 +12,76 @@ module Rouge
12
12
  end
13
13
 
14
14
  state :root do
15
- rule /[^<&]+/m, 'Text'
16
- rule /&\S*?;/, 'Name.Entity'
17
- rule /<!DOCTYPE .*?>/i, 'Comment.Preproc'
18
- rule /<!\[CDATA\[.*?\]\]>/m, 'Comment.Preproc'
19
- rule /<!--/, 'Comment', :comment
20
- rule /<\?.*?\?>/m, 'Comment.Preproc' # php? really?
15
+ rule /[^<&]+/m, Text
16
+ rule /&\S*?;/, Name::Entity
17
+ rule /<!DOCTYPE .*?>/i, Comment::Preproc
18
+ rule /<!\[CDATA\[.*?\]\]>/m, Comment::Preproc
19
+ rule /<!--/, Comment, :comment
20
+ rule /<\?.*?\?>/m, Comment::Preproc # php? really?
21
21
 
22
22
  rule /<\s*script\s*/m do
23
- token 'Name.Tag'
23
+ token Name::Tag
24
24
  push :script_content
25
25
  push :tag
26
26
  end
27
27
 
28
28
  rule /<\s*style\s*/m do
29
- token 'Name.Tag'
29
+ token Name::Tag
30
30
  push :style_content
31
31
  push :tag
32
32
  end
33
33
 
34
- rule %r(<\s*[a-zA-Z0-9:]+), 'Name.Tag', :tag # opening tags
35
- rule %r(<\s*/\s*[a-zA-Z0-9:]+\s*>), 'Name.Tag' # closing tags
34
+ rule %r(<\s*[a-zA-Z0-9:]+), Name::Tag, :tag # opening tags
35
+ rule %r(<\s*/\s*[a-zA-Z0-9:]+\s*>), Name::Tag # closing tags
36
36
  end
37
37
 
38
38
  state :comment do
39
- rule /[^-]+/, 'Comment'
40
- rule /-->/, 'Comment', :pop!
41
- rule /-/, 'Comment'
39
+ rule /[^-]+/, Comment
40
+ rule /-->/, Comment, :pop!
41
+ rule /-/, Comment
42
42
  end
43
43
 
44
44
  state :tag do
45
- rule /\s+/m, 'Text'
46
- rule /[a-zA-Z0-9_:-]+\s*=/m, 'Name.Attribute', :attr
47
- rule /[a-zA-Z0-9_:-]+/, 'Name.Attribute'
48
- rule %r(/?\s*>)m, 'Name.Tag', :pop!
45
+ rule /\s+/m, Text
46
+ rule /[a-zA-Z0-9_:-]+\s*=/m, Name::Attribute, :attr
47
+ rule /[a-zA-Z0-9_:-]+/, Name::Attribute
48
+ rule %r(/?\s*>)m, Name::Tag, :pop!
49
49
  end
50
50
 
51
51
  state :attr do
52
52
  # TODO: are backslash escapes valid here?
53
53
  rule /"/ do
54
- token 'Literal.String'
55
- pop!; push :dq
54
+ token Str
55
+ goto :dq
56
56
  end
57
57
 
58
58
  rule /'/ do
59
- token 'Literal.String'
60
- pop!; push :sq
59
+ token Str
60
+ goto :sq
61
61
  end
62
62
 
63
- rule /[^\s>]+/, 'Literal.String', :pop!
63
+ rule /[^\s>]+/, Str, :pop!
64
64
  end
65
65
 
66
66
  state :dq do
67
- rule /"/, 'Literal.String', :pop!
68
- rule /[^"]+/, 'Literal.String'
67
+ rule /"/, Str, :pop!
68
+ rule /[^"]+/, Str
69
69
  end
70
70
 
71
71
  state :sq do
72
- rule /'/, 'Literal.String', :pop!
73
- rule /[^']+/, 'Literal.String'
72
+ rule /'/, Str, :pop!
73
+ rule /[^']+/, Str
74
74
  end
75
75
 
76
76
  state :script_content do
77
- rule %r(<\s*/\s*script\s*>)m, 'Name.Tag', :pop!
77
+ rule %r(<\s*/\s*script\s*>)m, Name::Tag, :pop!
78
78
  rule %r(.*?(?=<\s*/\s*script\s*>))m do
79
79
  delegate Javascript
80
80
  end
81
81
  end
82
82
 
83
83
  state :style_content do
84
- rule %r(<\s*/\s*style\s*>)m, 'Name.Tag', :pop!
84
+ rule %r(<\s*/\s*style\s*>)m, Name::Tag, :pop!
85
85
  rule %r(.*(?=<\s*/\s*style\s*>))m do
86
86
  delegate CSS
87
87
  end
@@ -17,10 +17,10 @@ module Rouge
17
17
  ([^ ]+)([ ]+) # path
18
18
  (HTTPS?)(/)(1[.][01])(\r?\n|$) # http version
19
19
  )ox do
20
- group 'Name.Function'; group 'Text'
21
- group 'Name.Namespace'; group 'Text'
22
- group 'Keyword'; group 'Operator'
23
- group 'Literal.Number'; group 'Text'
20
+ group Name::Function; group Text
21
+ group Name::Namespace; group Text
22
+ group Keyword; group Operator
23
+ group Num; group Text
24
24
  push :headers
25
25
  end
26
26
 
@@ -30,10 +30,10 @@ module Rouge
30
30
  (\d{3})([ ]+) # status
31
31
  ([^\r\n]+)(\r?\n|$) # status message
32
32
  )x do
33
- group 'Keyword'; group 'Operator'
34
- group 'Literal.Number'; group 'Text'
35
- group 'Literal.Number'; group 'Text'
36
- group 'Name.Exception'; group 'Text'
33
+ group Keyword; group Operator
34
+ group Num; group Text
35
+ group Num; group Text
36
+ group Name::Exception; group Text
37
37
  push :headers
38
38
  end
39
39
  end
@@ -46,16 +46,16 @@ module Rouge
46
46
  @content_type = value.split(';')[0].downcase
47
47
  end
48
48
 
49
- group 'Name.Attribute'; group 'Text'
50
- group 'Punctuation'; group 'Text'
51
- group 'Literal.String'; group 'Text'
49
+ group Name::Attribute; group Text
50
+ group Punctuation; group Text
51
+ group Str; group Text
52
52
  end
53
53
 
54
54
  rule /([^\r\n]+)(\r?\n|$)/ do
55
- group 'Literal.String'; group 'Text'
55
+ group Str; group Text
56
56
  end
57
57
 
58
- rule /\r?\n/, 'Text', :content
58
+ rule /\r?\n/, Text, :content
59
59
  end
60
60
 
61
61
  state :content do
@@ -15,40 +15,40 @@ module Rouge
15
15
  identifier = /[\w.]+/
16
16
 
17
17
  state :basic do
18
- rule /[;#].*?\n/, 'Comment'
19
- rule /\s+/, 'Text'
20
- rule /\\\n/, 'Literal.String.Escape'
18
+ rule /[;#].*?\n/, Comment
19
+ rule /\s+/, Text
20
+ rule /\\\n/, Str::Escape
21
21
  end
22
22
 
23
23
  state :root do
24
24
  mixin :basic
25
25
 
26
26
  rule /(#{identifier})(\s*)(=)/ do
27
- group 'Name.Property'; group 'Text'
28
- group 'Punctuation'
27
+ group Name::Property; group Text
28
+ group Punctuation
29
29
  push :value
30
30
  end
31
31
 
32
- rule /\[.*?\]/, 'Name.Namespace'
32
+ rule /\[.*?\]/, Name::Namespace
33
33
  end
34
34
 
35
35
  state :value do
36
- rule /\n/, 'Text', :pop!
36
+ rule /\n/, Text, :pop!
37
37
  mixin :basic
38
- rule /"/, 'Literal.String', :dq
39
- rule /'.*?'/, 'Literal.String'
38
+ rule /"/, Str, :dq
39
+ rule /'.*?'/, Str
40
40
  mixin :esc_str
41
- rule /[^\\\n]+/, 'Literal.String'
41
+ rule /[^\\\n]+/, Str
42
42
  end
43
43
 
44
44
  state :dq do
45
- rule /"/, 'Literal.String', :pop!
45
+ rule /"/, Str, :pop!
46
46
  mixin :esc_str
47
- rule /[^\\"]+/m, 'Literal.String'
47
+ rule /[^\\"]+/m, Str
48
48
  end
49
49
 
50
50
  state :esc_str do
51
- rule /\\./m, 'Literal.String.Escape'
51
+ rule /\\./m, Str::Escape
52
52
  end
53
53
  end
54
54
  end