rouge 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58d67e05c1ce7c2db44d5ce537e17a233f77148b
4
- data.tar.gz: 879be7fc4c49e621e7c88107138bf44a2d43f8b6
3
+ metadata.gz: 93043d4d750807111180be1a7d6582d7d8338470
4
+ data.tar.gz: 9b99367f2a290e9c4c0a040142866a641bb06803
5
5
  SHA512:
6
- metadata.gz: 54fbeee82ad363f158c292fbf3140befa2a8a5164f73d167ecdf3e1f012956e958137ec77f5d4bb539e707e6e4db0111d513d2a6042b991a43f32e9755885ae0
7
- data.tar.gz: df96e836f4254a16ad9acbe5a3612dff4ec0c309365b546334eb87179f7cff604f536e664c8e3b31ecab7cb969c56004f8473b0722ffab325105bb0e11c324e3
6
+ metadata.gz: 302965016c0054702b7a0e97c1d8fecb6a755ae4957e127870e2d6eecd4131d8589e4f20b6c44b751edcceb0d3030cdfa27004ac9388d6b44e72b0133451a6f9
7
+ data.tar.gz: 52de7875d8d80e34c93cec6c86afdf8292bebfeabcac389a746c18b95bd46bb070b9410020ca609bd4beec241fdf243a07792cc927a4b7832254005f007c40c1
@@ -6,6 +6,11 @@ require 'pathname'
6
6
  # The containing module for Rouge
7
7
  module Rouge
8
8
  class << self
9
+ def reload!
10
+ Object.send :remove_const, :Rouge
11
+ load __FILE__
12
+ end
13
+
9
14
  # Highlight some text with a given lexer and formatter.
10
15
  #
11
16
  # @example
@@ -1,14 +1,13 @@
1
- # ref.tlp
2
1
  @module ref
3
2
 
4
- ref value = Instance (spawn [! loop value ])
3
+ ref value = Ref (spawn [ ! => loop value ])
5
4
 
6
5
  loop value = receive [
7
6
  .set new-value => loop new-value
8
- p, .get => (send p value; loop value)
7
+ p, id, .get => { send p (id, value); loop value }
9
8
  ]
10
9
 
11
- @module Instance pid [
10
+ @object Ref pid [
12
11
  set val = .set val > send pid
13
12
  get! = .get > send-wait pid
14
13
  ]
@@ -7,7 +7,7 @@ module Rouge
7
7
  end
8
8
 
9
9
  def stream(tokens, &b)
10
- yield %<<pre class="#@css_class"><code>>
10
+ yield %(<pre class="#{@css_class}"><code>)
11
11
  @inner.stream(tokens, &b)
12
12
  yield "</code></pre>"
13
13
  end
@@ -41,16 +41,16 @@ module Rouge
41
41
  sprintf("#{@line_format}", i) << "\n"
42
42
  end.join('')
43
43
 
44
- numbers = %<<pre class="lineno">#{formatted_line_numbers}</pre>>
44
+ numbers = %(<pre class="lineno">#{formatted_line_numbers}</pre>)
45
45
 
46
- yield %<<table class="#@table_class"><tbody><tr>>
46
+ yield %(<table class="#@table_class"><tbody><tr>)
47
47
 
48
48
  # the "gl" class applies the style for Generic.Lineno
49
- yield %<<td class="#@gutter_class gl">>
49
+ yield %(<td class="#@gutter_class gl">)
50
50
  yield numbers
51
51
  yield '</td>'
52
52
 
53
- yield %<<td class="#@code_class"><pre>>
53
+ yield %(<td class="#@code_class"><pre>)
54
54
  yield formatted
55
55
  yield '</pre></td>'
56
56
 
@@ -1,5 +1,14 @@
1
1
  module Rouge
2
2
  class Guesser
3
+ class Ambiguous < StandardError
4
+ attr_reader :alternatives
5
+ def initialize(alternatives); @alternatives = alternatives; end
6
+
7
+ def message
8
+ "Ambiguous guess: can't decide between #{alternatives.map(&:tag).inspect}"
9
+ end
10
+ end
11
+
3
12
  def self.guess(guessers, lexers)
4
13
  original_size = lexers.size
5
14
 
@@ -122,15 +122,6 @@ module Rouge
122
122
  Guesser.guess(guessers, Lexer.all)
123
123
  end
124
124
 
125
- class AmbiguousGuess < StandardError
126
- attr_reader :alternatives
127
- def initialize(alternatives); @alternatives = alternatives; end
128
-
129
- def message
130
- "Ambiguous guess: can't decide between #{alternatives.map(&:tag).inspect}"
131
- end
132
- end
133
-
134
125
  # Guess which lexer to use based on a hash of info.
135
126
  #
136
127
  # @option info :mimetype
@@ -150,7 +141,7 @@ module Rouge
150
141
  return Lexers::PlainText if lexers.empty?
151
142
  return lexers[0] if lexers.size == 1
152
143
 
153
- raise AmbiguousGuess.new(lexers)
144
+ raise Guesser::Ambiguous.new(lexers)
154
145
  end
155
146
 
156
147
  def guess_by_mimetype(mt)
@@ -46,7 +46,7 @@ module Rouge
46
46
 
47
47
  rule /\n\n(( |\t).*?\n|\n)+/, Str::Backtick
48
48
 
49
- rule /(`+)#{edot}*\1/, Str::Backtick
49
+ rule /(`+)#{edot}+?\1/, Str::Backtick
50
50
 
51
51
  # various uses of * are in order of precedence
52
52
 
@@ -90,7 +90,7 @@ module Rouge
90
90
  end
91
91
 
92
92
  rule /[~!%^&*+=\|:.<>\/?@-]+/, Operator
93
- rule /[\[\]{}();,]+/, Punctuation
93
+ rule /[\[\]{}();,]/, Punctuation
94
94
  rule /class\b/, Keyword, :classname
95
95
  # anonymous functions
96
96
  rule /(function)(\s*)(?=\()/ do
@@ -37,7 +37,7 @@ module Rouge
37
37
  demoOptionKeyPressed demoShiftKeyPressed demoShow demoWaitForInput
38
38
  demoWindowTitle demoX demoY differenceLimensToPhon do editor endPause
39
39
  endSendPraat endsWith erb erbToHertz erf erfc exitScript exp
40
- extractNumber fileReadable fisherP fisherQ floor gaussP gaussQ
40
+ extractNumber fileReadable fisherP fisherQ floor gaussP gaussQ hash
41
41
  hertzToBark hertzToErb hertzToMel hertzToSemitones imax imin
42
42
  incompleteBeta incompleteGammaP index index_regex integer invBinomialP
43
43
  invBinomialQ invChiSquareQ invFisherQ invGaussQ invSigmoid invStudentQ
@@ -104,12 +104,21 @@ module Rouge
104
104
  groups Text, Comment::Single
105
105
  end
106
106
 
107
- rule /^#.*?$/, Comment::Single
108
- rule /;[^\n]*/, Comment::Single
109
- rule /\s+/, Text
110
- rule /\bprocedure\b/, Keyword, :procedure_definition
111
- rule /\bcall\b/, Keyword, :procedure_call
112
- rule /@/, Name::Function, :procedure_call
107
+ rule /^#.*?$/, Comment::Single
108
+ rule /;[^\n]*/, Comment::Single
109
+ rule /\s+/, Text
110
+
111
+ rule /(\bprocedure)(\s+)/ do
112
+ groups Keyword, Text
113
+ push :procedure_definition
114
+ end
115
+
116
+ rule /(\bcall)(\s+)/ do
117
+ groups Keyword, Text
118
+ push :procedure_call
119
+ end
120
+
121
+ rule /@/, Name::Function, :procedure_call
113
122
 
114
123
  mixin :function_call
115
124
 
@@ -142,7 +151,7 @@ module Rouge
142
151
  end
143
152
 
144
153
  state :command do
145
- rule /( ?[\w()-]+ ?)/, Keyword
154
+ rule /( ?([^\s:\.'])+ ?)/, Keyword
146
155
  mixin :string_interpolated
147
156
 
148
157
  rule /\.{3}/ do
@@ -161,32 +170,26 @@ module Rouge
161
170
  end
162
171
 
163
172
  state :procedure_call do
164
- rule /\s+/, Text
173
+ mixin :string_interpolated
165
174
 
166
- rule /([\w.]+)(:|\s*\()/ do
167
- groups Name::Function, Punctuation
168
- pop!
169
- end
175
+ rule /(:|\s*\()/, Punctuation, :pop!
170
176
 
171
- rule /([\w.]+)/ do
172
- token Name::Function
177
+ rule /'/, Name::Function
178
+ rule /[^:\('\n\s]+/, Name::Function
179
+
180
+ rule /(?=\s+)/ do
181
+ token Text
173
182
  pop!
174
183
  push :old_arguments
175
184
  end
176
185
  end
177
186
 
178
187
  state :procedure_definition do
179
- rule /\s/, Text
188
+ rule /(:|\s*\()/, Punctuation, :pop!
180
189
 
181
- rule /([\w.]+)(\s*?[(:])/ do
182
- groups Name::Function, Text
183
- pop!
184
- end
190
+ rule /[^:\(\n\s]+/, Name::Function
185
191
 
186
- rule /([\w.]+)([^\n]*)/ do
187
- groups Name::Function, Text
188
- pop!
189
- end
192
+ rule /(\s+)/, Text, :pop!
190
193
  end
191
194
 
192
195
  state :function_call do
@@ -202,14 +202,6 @@ module Rouge
202
202
  rule /(?<!\.)(?:#{builtins_g.join('|')})\b/,
203
203
  Name::Builtin, :method_call
204
204
 
205
- # char operator. ?x evaulates to "x", unless there's a digit
206
- # beforehand like x>=0?n[x]:""
207
- rule %r(
208
- [?](\\[MC]-)* # modifiers
209
- (\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
210
- (?!\w)
211
- )x, Str::Char
212
-
213
205
  mixin :has_heredocs
214
206
 
215
207
  rule /[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
@@ -223,7 +215,8 @@ module Rouge
223
215
  rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\.{1,3}/,
224
216
  Operator, :expr_start
225
217
  rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
226
- rule %r<[\[({,?:\\;/]>, Punctuation, :expr_start
218
+ rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
219
+ rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
227
220
  rule %r<[\])}]>, Punctuation
228
221
  end
229
222
 
@@ -313,6 +306,12 @@ module Rouge
313
306
  rule(//) { pop! }
314
307
  end
315
308
 
309
+ state :ternary do
310
+ rule(/:(?!:)/) { token Punctuation; goto :expr_start }
311
+
312
+ mixin :root
313
+ end
314
+
316
315
  state :defexpr do
317
316
  rule /(\))(\.|::)?/ do
318
317
  groups Punctuation, Operator
@@ -350,6 +349,8 @@ module Rouge
350
349
  goto :expr_start
351
350
  end
352
351
 
352
+ rule(/(?=\n)/) { pop! }
353
+
353
354
  rule(//) { goto :method_call_spaced }
354
355
  end
355
356
 
@@ -382,6 +383,14 @@ module Rouge
382
383
  goto :slash_regex
383
384
  end
384
385
 
386
+ # char operator. ?x evaulates to "x", unless there's a digit
387
+ # beforehand like x>=0?n[x]:""
388
+ rule %r(
389
+ [?](\\[MC]-)* # modifiers
390
+ (\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
391
+ (?!\w)
392
+ )x, Str::Char, :pop!
393
+
385
394
  # special case for using a single space. Ruby demands that
386
395
  # these be in a single line, otherwise it would make no sense.
387
396
  rule /(\s*)(%[rqswQWxiI]? \S* )/ do
@@ -1,73 +1,75 @@
1
1
  module Rouge
2
2
  module Lexers
3
3
  class Tulip < RegexLexer
4
+ desc 'the tulip programming language (twitter.com/tuliplang)'
4
5
  tag 'tulip'
5
- aliases 'tlp'
6
+ aliases 'tulip'
7
+
6
8
  filenames '*.tlp'
7
- desc 'The tulip programming language http://github.com/jneen/tulip'
8
9
 
9
- id = /\w[\w-]*/
10
+ mimetypes 'text/x-tulip', 'application/x-tulip'
10
11
 
11
12
  def self.analyze_text(text)
12
- return 1 if text.shebang?('tulip')
13
+ return 1 if text.shebang? 'tulip'
14
+ return 0
13
15
  end
14
16
 
15
- state :root do
17
+ id = /[a-z][\w-]*/i
18
+ upper_id = /[A-Z][\w-]*/
19
+
20
+ state :comments_and_whitespace do
16
21
  rule /\s+/, Text
17
- rule /#.*?\n/, Comment
18
- rule /%#{id}/, Keyword::Type
22
+ rule /#.*?$/, Comment
23
+ end
24
+
25
+ state :root do
26
+ mixin :comments_and_whitespace
27
+
19
28
  rule /@#{id}/, Keyword
20
- rule /[.][.]?#{id}/, Name::Label
21
- rule /-#{id}[?]?/, Str::Symbol
22
- rule /\d+/, Num
23
- rule %r(/#{id}?), Name::Decorator
24
- rule %r((#{id}/)(#{id})) do
25
- groups Name::Namespace, Name::Variable
29
+
30
+
31
+ rule /[>,!\[\]:{}()=;\/]/, Punctuation
32
+
33
+ rule /(\\#{id})([{])/ do
34
+ groups Name::Variable, Str
35
+ push :nested_string
26
36
  end
27
37
 
28
- rule /"{/, Str, :string_interp
29
- rule /'?{/, Str, :string
30
- rule /['"][^\s)\]]+/, Str
38
+ rule /\\#{id}/, Name::Function
31
39
 
32
- rule /[$]/, Name::Variable
40
+ rule /"/, Str, :dq
33
41
 
34
- rule /[-+:;~!()\[\]=?>|_%,]/, Punctuation
35
- rule /[.][.][.]/, Punctuation
36
- rule id, Name
37
- end
42
+ rule /'{/, Str, :nested_string
38
43
 
39
- state :string_base do
40
- rule /{/ do
41
- token Str; push
42
- end
44
+ rule /[.]#{id}/, Name::Tag
45
+ rule /[$]#{id}/, Name::Variable
43
46
 
44
- rule /}/, Str, :pop!
45
- rule /[$]/, Str
46
- rule /[^${}\\]+/, Str
47
- end
47
+ rule /[0-9]+([.][0-9]+)?/, Num
48
48
 
49
- state :string do
50
- mixin :string_base
51
- rule /\\/, Str
52
- end
49
+ rule /#{id}/, Name
53
50
 
54
- state :interp do
55
- rule(/[(]/) { token Punctuation; push }
56
- rule /[)]/, Punctuation, :pop!
57
- mixin :root
51
+ rule /</, Comment::Preproc, :angle_brackets
58
52
  end
59
53
 
60
- state :interp_root do
61
- rule /[(]/, Str::Interpol, :interp
62
- rule /[)]/, Str::Interpol, :pop!
63
- mixin :root
54
+ state :dq do
55
+ rule /[^\\"]+/, Str
56
+ rule /"/, Str, :pop!
57
+ rule /\\./, Str::Escape
64
58
  end
65
59
 
66
- state :string_interp do
60
+ state :nested_string do
67
61
  rule /\\./, Str::Escape
68
- rule /[$][(]/, Str::Interpol, :interp_root
69
- rule /[$]#{id}?/, Name::Variable
70
- mixin :string_base
62
+ rule(/{/) { token Str; push :nested_string }
63
+ rule(/}/) { token Str; pop! }
64
+ rule(/[^{}\\]+/) { token Str }
65
+ end
66
+
67
+ state :angle_brackets do
68
+ mixin :comments_and_whitespace
69
+ rule />/, Comment::Preproc, :pop!
70
+ rule /[*:]/, Punctuation
71
+ rule /#{upper_id}/, Keyword::Type
72
+ rule /#{id}/, Name::Variable
71
73
  end
72
74
  end
73
75
  end
@@ -109,7 +109,7 @@ module Rouge
109
109
  proc do |stream|
110
110
  puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
111
111
  @output_stream.call(tok, stream[0])
112
- puts " pushing #{@stack.last.name}" if @debug
112
+ puts " pushing :#{@stack.last.name}" if @debug
113
113
  @stack.push(@stack.last)
114
114
  end
115
115
  when Symbol
@@ -117,7 +117,7 @@ module Rouge
117
117
  puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
118
118
  @output_stream.call(tok, stream[0])
119
119
  state = @states[next_state] || self.class.get_state(next_state)
120
- puts " pushing #{state.name}" if @debug
120
+ puts " pushing :#{state.name}" if @debug
121
121
  @stack.push(state)
122
122
  end
123
123
  when nil
@@ -261,7 +261,7 @@ module Rouge
261
261
  until stream.eos?
262
262
  if @debug
263
263
  puts "lexer: #{self.class.tag}"
264
- puts "stack: #{stack.map(&:name).inspect}"
264
+ puts "stack: #{stack.map(&:name).map(&:to_sym).inspect}"
265
265
  puts "stream: #{stream.peek(20).inspect}"
266
266
  end
267
267
 
@@ -385,7 +385,7 @@ module Rouge
385
385
  self.state
386
386
  end
387
387
 
388
- puts " pushing #{push_state.name}" if @debug
388
+ puts " pushing :#{push_state.name}" if @debug
389
389
  stack.push(push_state)
390
390
  end
391
391
 
@@ -405,7 +405,7 @@ module Rouge
405
405
  def goto(state_name)
406
406
  raise 'empty stack!' if stack.empty?
407
407
 
408
- puts " going to state #{state_name} " if @debug
408
+ puts " going to state :#{state_name} " if @debug
409
409
  stack[-1] = get_state(state_name)
410
410
  end
411
411
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rouge
4
4
  def self.version
5
- "2.0.2"
5
+ "2.0.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
14
14
  email: