rouge 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,8 +45,10 @@ load load_dir.join('rouge/lexers/php.rb')
45
45
  load load_dir.join('rouge/lexers/haml.rb')
46
46
  load load_dir.join('rouge/lexers/sass.rb')
47
47
  load load_dir.join('rouge/lexers/scss.rb')
48
+ load load_dir.join('rouge/lexers/coffeescript.rb')
48
49
 
49
50
  load load_dir.join('rouge/lexers/erb.rb')
51
+ load load_dir.join('rouge/lexers/handlebars.rb')
50
52
 
51
53
  load load_dir.join('rouge/lexers/tcl.rb')
52
54
  load load_dir.join('rouge/lexers/python.rb')
@@ -64,6 +66,8 @@ load load_dir.join('rouge/lexers/c.rb')
64
66
  load load_dir.join('rouge/lexers/cpp.rb')
65
67
  load load_dir.join('rouge/lexers/java.rb')
66
68
 
69
+ load load_dir.join('rouge/lexers/smalltalk.rb')
70
+
67
71
  load load_dir.join('rouge/formatter.rb')
68
72
  load load_dir.join('rouge/formatters/html.rb')
69
73
  load load_dir.join('rouge/formatters/terminal256.rb')
@@ -0,0 +1,176 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Coffeescript < RegexLexer
4
+ tag 'coffeescript'
5
+ aliases 'coffee', 'coffee-script'
6
+ filenames '*.coffee', 'Cakefile'
7
+ mimetypes 'text/coffeescript'
8
+
9
+ desc 'The Coffeescript programming language (coffeescript.org)'
10
+
11
+ def self.analyze_text(text)
12
+ return 1 if text.shebang? 'coffee'
13
+ end
14
+
15
+ def self.keywords
16
+ @keywords ||= Set.new %w(
17
+ for in of while break return continue switch when then if else
18
+ throw try catch finally new delete typeof instanceof super
19
+ extends this class by
20
+ )
21
+ end
22
+
23
+ def self.constants
24
+ @constants ||= Set.new %w(
25
+ true false yes no on off null NaN Infinity undefined
26
+ )
27
+ end
28
+
29
+ def self.builtins
30
+ @builtins ||= Set.new %w(
31
+ Array Boolean Date Error Function Math netscape Number Object
32
+ Packages RegExp String sun decodeURI decodeURIComponent
33
+ encodeURI encodeURIComponent eval isFinite isNaN parseFloat
34
+ parseInt document window
35
+ )
36
+ end
37
+
38
+ id = /[$a-zA-Z_][a-zA-Z0-9_]*/
39
+ lval = /@?#{id}([.]#{id})*/
40
+
41
+ state :comments_and_whitespace do
42
+ rule /\s+/m, 'Text'
43
+ rule /###.*?###/m, 'Comment.Multiline'
44
+ rule /#.*?\n/, 'Comment.Single'
45
+ end
46
+
47
+ state :multiline_regex do
48
+ mixin :comments_and_whitespace
49
+ rule %r(///([gim]+\b|\B)), 'Literal.String.Regex', :pop!
50
+ rule %r(/), 'Literal.String.Regex'
51
+ rule %r([^/#]+), 'Literal.String.Regex'
52
+ end
53
+
54
+ state :slash_starts_regex do
55
+ mixin :comments_and_whitespace
56
+ rule %r(///) do
57
+ token 'Literal.String.Regex'
58
+ pop!; push :multiline_regex
59
+ end
60
+
61
+ rule %r(
62
+ /(\\.|[^\[/\\\n]|\[(\\.|[^\]\\\n])*\])+/ # a regex
63
+ ([gim]+\b|\B)
64
+ )x, 'Literal.String.Regex', :pop!
65
+
66
+ rule(//) { pop! }
67
+ end
68
+
69
+ state :root do
70
+ rule(%r(^(?=\s|/|<!--))) { push :slash_starts_regex }
71
+ mixin :comments_and_whitespace
72
+ rule %r(
73
+ [+][+]|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|[?]|:|=|
74
+ [|][|]|\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&|^/])=?
75
+ )x, 'Operator', :slash_starts_regex
76
+
77
+ rule /[-=]>/, 'Name.Function'
78
+
79
+ rule /(@)([ \t]*)(#{id})/ do
80
+ group 'Name.Variable.Instance'; group 'Text'
81
+ group 'Name.Attribute'
82
+ push :slash_starts_regex
83
+ end
84
+
85
+ rule /([.])([ \t]*)(#{id})/ do
86
+ group 'Punctuation'; group 'Text'
87
+ group 'Name.Attribute'
88
+ push :slash_starts_regex
89
+ end
90
+
91
+ rule /#{id}(?=\s*:)/, 'Name.Attribute', :slash_starts_regex
92
+
93
+ rule /#{id}/, 'Name.Other', :slash_starts_regex
94
+
95
+ rule /[{(\[;,]/, 'Punctuation', :slash_starts_regex
96
+ rule /[})\].]/, 'Punctuation'
97
+
98
+ rule /\d+[.]\d+([eE]\d+)?[fd]?/, 'Literal.Number.Float'
99
+ rule /0x[0-9a-fA-F]+/, 'Literal.Number.Hex'
100
+ rule /\d+/, 'Literal.Number.Integer'
101
+ rule /"""/, 'Literal.String', :tdqs
102
+ rule /'''/, 'Literal.String', :tsqs
103
+ rule /"/, 'Literal.String', :dqs
104
+ rule /'/, 'Literal.String', :sqs
105
+ end
106
+
107
+ state :strings do
108
+ # all coffeescript strings are multi-line
109
+ rule /[^#\\'"]+/m, 'Literal.String'
110
+
111
+ rule /\\./, 'Literal.String.Escape'
112
+ rule /#/, 'Literal.String'
113
+ end
114
+
115
+ state :double_strings do
116
+ rule /'/, 'Literal.String'
117
+ mixin :has_interpolation
118
+ mixin :strings
119
+ end
120
+
121
+ state :single_strings do
122
+ rule /"/, 'Literal.String'
123
+ mixin :strings
124
+ end
125
+
126
+ state :interpolation do
127
+ rule /}/, 'Literal.String.Interpol', :pop!
128
+ mixin :root
129
+ end
130
+
131
+ state :has_interpolation do
132
+ rule /[#][{]/, 'Literal.String.Interpol', :interpolation
133
+ end
134
+
135
+ state :dqs do
136
+ rule /"/, 'Literal.String', :pop!
137
+ mixin :double_strings
138
+ end
139
+
140
+ state :tdqs do
141
+ rule /"""/, 'Literal.String', :pop!
142
+ rule /"/, 'Literal.String'
143
+ mixin :double_strings
144
+ end
145
+
146
+ state :sqs do
147
+ rule /'/, 'Literal.String', :pop!
148
+ mixin :single_strings
149
+ end
150
+
151
+ state :tsqs do
152
+ rule /'''/, 'Literal.String', :pop!
153
+ rule /'/, 'Literal.String'
154
+ mixin :single_strings
155
+ end
156
+
157
+ postprocess 'Name' do |tok, val|
158
+ if tok.name == 'Name.Attribute'
159
+ if self.class.keywords.include? val
160
+ tok = 'Error' # keywords as attributes = nono
161
+ else
162
+ # pass. leave attributes alone.
163
+ end
164
+ elsif self.class.keywords.include? val
165
+ tok = 'Keyword'
166
+ elsif self.class.constants.include? val
167
+ tok = 'Name.Constant'
168
+ elsif self.class.builtins.include? val
169
+ tok = 'Name.Builtin'
170
+ end
171
+
172
+ token tok, val
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,76 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Handlebars < TemplateLexer
4
+ desc 'the Handlebars and Mustache templating languages'
5
+ tag 'handlebars'
6
+ aliases 'hbs', 'mustache'
7
+ filenames '*.handlebars', '*.hbs', '*.mustache'
8
+ mimetypes 'text/x-handlebars', 'text/x-mustache'
9
+
10
+ id = %r([\w$-]+)
11
+
12
+ state :root do
13
+ # escaped slashes
14
+ rule(/\\{+/) { delegate parent }
15
+
16
+ # block comments
17
+ rule /{{!--/, 'Comment', :comment
18
+ rule /{{!.*?}}/, 'Comment'
19
+
20
+ rule /{{{?/ do
21
+ token 'Keyword'
22
+ push :stache
23
+ push :open_sym
24
+ end
25
+
26
+ rule(/(.+?)(?=\\|{{)/m) { delegate parent }
27
+
28
+ # if we get here, there's no more mustache tags, so we eat
29
+ # the rest of the doc
30
+ rule(/.+/m) { delegate parent }
31
+ end
32
+
33
+ state :comment do
34
+ rule(/{{/) { token 'Comment'; push }
35
+ rule(/}}/) { token 'Comment'; pop! }
36
+ rule(/[^{}]+/m) { token 'Comment' }
37
+ rule(/[{}]/) { token 'Comment' }
38
+ end
39
+
40
+ state :stache do
41
+ rule /}}}?/, 'Keyword', :pop!
42
+ rule /\s+/m, 'Text'
43
+ rule /[=]/, 'Operator'
44
+ rule /[\[\]]/, 'Punctuation'
45
+ rule /[.](?=[}\s])/, 'Name.Variable'
46
+ rule /[.][.]/, 'Name.Variable'
47
+ rule %r([/.]), 'Punctuation'
48
+ rule /"(\\.|.)*?"/, 'Literal.String.Double'
49
+ rule /'(\\.|.)*?'/, 'Literal.String.Single'
50
+ rule /\d+(?=}\s)/, 'Literal.Number'
51
+ rule /(true|false)(?=[}\s])/, 'Keyword.Constant'
52
+ rule /else(?=[}\s])/, 'Keyword'
53
+ rule /this(?=[}\s])/, 'Name.Builtin.Pseudo'
54
+ rule /@#{id}/, 'Name.Attribute'
55
+ rule id, 'Name.Variable'
56
+ end
57
+
58
+ state :open_sym do
59
+ rule %r([#/]) do
60
+ token 'Keyword'
61
+ pop!; push :block_name
62
+ end
63
+
64
+ rule /[>^&]/, 'Keyword'
65
+
66
+ rule(//) { pop! }
67
+ end
68
+
69
+ state :block_name do
70
+ rule /if(?=[}\s])/, 'Keyword'
71
+ rule id, 'Name.Namespace', :pop!
72
+ rule(//) { pop! }
73
+ end
74
+ end
75
+ end
76
+ end
@@ -3,6 +3,8 @@ module Rouge
3
3
  class Sass < RegexLexer
4
4
  include Indentation
5
5
 
6
+ desc 'The Sass stylesheet language language (sass-lang.com)'
7
+
6
8
  tag 'sass'
7
9
  filenames '*.sass'
8
10
  mimetypes 'text/x-sass'
@@ -0,0 +1,114 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Smalltalk < RegexLexer
4
+ desc 'The Smalltalk programming language'
5
+
6
+ tag 'smalltalk'
7
+ aliases 'st', 'squeak'
8
+ filenames '*.st'
9
+ mimetypes 'text/x-smalltalk'
10
+
11
+ ops = %r([-+*/\\~<>=|&!?,@%])
12
+
13
+ state :root do
14
+ rule /(<)(\w+:)(.*?)(>)/ do
15
+ group 'Punctuation'; group 'Keyword'; group 'Text'; group 'Punctuation'
16
+ end
17
+
18
+ # mixin :squeak_fileout
19
+ mixin :whitespaces
20
+ mixin :method_definition
21
+ rule /([|])([\w\s]*)([|])/ do
22
+ group 'Punctuation'; group 'Name.Variable'; group 'Punctuation'
23
+ end
24
+ mixin :objects
25
+ rule /\^|:=|_/, 'Operator'
26
+
27
+ rule /[)}\]]/, 'Punctuation', :after_object
28
+ rule /[({\[!]/, 'Punctuation'
29
+ end
30
+
31
+ state :method_definition do
32
+ rule /([a-z]\w*:)(\s*)(\w+)/i do
33
+ group 'Name.Function'; group 'Text'; group 'Name.Variable'
34
+ end
35
+
36
+ rule /^(\s*)(\b[a-z]\w*\b)(\s*)$/i do
37
+ group 'Text'; group 'Name.Function'; group 'Text'
38
+ end
39
+
40
+ rule %r(^(\s*)(#{ops}+)(\s*)(\w+)(\s*)$) do
41
+ group 'Text'; group 'Name.Function';
42
+ group 'Text'; group 'Name.Variable'; group 'Text';
43
+ end
44
+ end
45
+
46
+ state :block_variables do
47
+ mixin :whitespaces
48
+ rule /(:)(\s*)(\w+)/ do
49
+ group 'Operator'; group 'Text'; group 'Name.Variable'
50
+ end
51
+
52
+ rule /[|]/, 'Punctuation', :pop!
53
+
54
+ rule(//) { pop! }
55
+ end
56
+
57
+ state :literals do
58
+ rule /'(''|.)*?'/m, 'Literal.String', :after_object
59
+ rule /[$]./, 'Literal.String.Char', :after_object
60
+ rule /#[(]/, 'Literal.String.Symbol', :parenth
61
+ rule /(\d+r)?-?\d+(\.\d+)?(e-?\d+)?/,
62
+ 'Literal.Number', :after_object
63
+ rule /#("[^"]*"|#{ops}+|[\w:]+)/,
64
+ 'Literal.String.Symbol', :after_object
65
+ end
66
+
67
+ state :parenth do
68
+ rule /[)]/ do
69
+ token 'Literal.String.Symbol'
70
+ pop!; push :after_object
71
+ end
72
+
73
+ mixin :inner_parenth
74
+ end
75
+
76
+ state :inner_parenth do
77
+ rule /#[(]/, 'Literal.String.Symbol', :inner_parenth
78
+ rule /[)]/, 'Literal.String.Symbol', :pop!
79
+ mixin :whitespaces
80
+ mixin :literals
81
+ rule /(#{ops}|[\w:])+/, 'Literal.String.Symbol'
82
+ end
83
+
84
+ state :whitespaces do
85
+ rule /! !$/, 'Keyword' # squeak chunk delimiter
86
+ rule /\s+/m, 'Text'
87
+ rule /".*?"/m, 'Comment'
88
+ end
89
+
90
+ state :objects do
91
+ rule /\[/, 'Punctuation', :block_variables
92
+ rule /(self|super|true|false|nil|thisContext)\b/,
93
+ 'Name.Builtin.Pseudo', :after_object
94
+ rule /[A-Z]\w*(?!:)\b/, 'Name.Class', :after_object
95
+ rule /[a-z]\w*(?!:)\b/, 'Name.Variable', :after_object
96
+ mixin :literals
97
+ end
98
+
99
+ state :after_object do
100
+ mixin :whitespaces
101
+ rule /(ifTrue|ifFalse|whileTrue|whileFalse|timesRepeat):/,
102
+ 'Name.Builtin', :pop!
103
+ rule /new(?!:)\b/, 'Name.Builtin'
104
+ rule /:=|_/, 'Operator', :pop!
105
+ rule /[a-z]+\w*:/i, 'Name.Function', :pop!
106
+ rule /[a-z]+\w*/i, 'Name.Function'
107
+ rule /#{ops}+/, 'Name.Function', :pop!
108
+ rule /[.]/, 'Punctuation', :pop!
109
+ rule /;/, 'Punctuation'
110
+ rule(//) { pop! }
111
+ end
112
+ end
113
+ end
114
+ end
@@ -196,7 +196,7 @@ module Rouge
196
196
  # @see #step #step (where (2.) is implemented)
197
197
  def stream_tokens(stream, &b)
198
198
  stream_without_postprocessing(stream) do |tok, val|
199
- _, processor = self.class.postprocesses.find { |t, _| t == tok }
199
+ _, processor = self.class.postprocesses.find { |t, _| t === tok }
200
200
 
201
201
  if processor
202
202
  with_output_stream(b) do
@@ -385,6 +385,7 @@ module Rouge
385
385
 
386
386
  private
387
387
  def with_output_stream(output_stream, &b)
388
+ old_output_stream = @output_stream
388
389
  @output_stream = Yielder.new do |tok, val|
389
390
  debug { " yielding #{tok.to_s.inspect}, #{val.inspect}" }
390
391
  output_stream.call(Token[tok], val)
@@ -393,7 +394,7 @@ module Rouge
393
394
  yield
394
395
 
395
396
  ensure
396
- @output_stream = nil
397
+ @output_stream = old_output_stream
397
398
  end
398
399
  end
399
400
  end
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.2.2"
3
+ "0.2.3"
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.2
4
+ version: 0.2.3
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-13 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -53,9 +53,11 @@ files:
53
53
  - lib/rouge/lexers/javascript.rb
54
54
  - lib/rouge/lexers/diff.rb
55
55
  - lib/rouge/lexers/viml.rb
56
+ - lib/rouge/lexers/smalltalk.rb
56
57
  - lib/rouge/lexers/php/builtins.rb
57
58
  - lib/rouge/lexers/haskell.rb
58
59
  - lib/rouge/lexers/c.rb
60
+ - lib/rouge/lexers/handlebars.rb
59
61
  - lib/rouge/lexers/tex.rb
60
62
  - lib/rouge/lexers/text.rb
61
63
  - lib/rouge/lexers/html.rb
@@ -63,6 +65,7 @@ files:
63
65
  - lib/rouge/lexers/java.rb
64
66
  - lib/rouge/lexers/php.rb
65
67
  - lib/rouge/lexers/yaml.rb
68
+ - lib/rouge/lexers/coffeescript.rb
66
69
  - lib/rouge/lexers/tcl.rb
67
70
  - lib/rouge/lexers/css.rb
68
71
  - lib/rouge/lexers/cpp.rb