rouge 0.2.15 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ gem 'redcarpet', :platforms => :ruby
12
12
 
13
13
  # for visual tests
14
14
  gem 'sinatra'
15
+ gem 'shotgun'
15
16
 
16
17
  # docs
17
18
  gem 'yard'
@@ -0,0 +1,17 @@
1
+ # language: en
2
+ Feature: Addition
3
+ In order to avoid silly mistakes
4
+ As a math idiot
5
+ I want to be told the sum of two numbers
6
+
7
+ Scenario Outline: Add two numbers
8
+ Given I have entered <input_1> into the calculator
9
+ And I have entered <input_2> into the calculator
10
+ When I press <button>
11
+ Then the result should be <output> on the screen
12
+
13
+ Examples:
14
+ | input_1 | input_2 | button | output |
15
+ | 20 | 30 | add | 50 |
16
+ | 2 | 5 | add | 7 |
17
+ | 0 | 40 | add | 40 |
@@ -0,0 +1,20 @@
1
+ ; copied from http://llvm.org/docs/LangRef.html#module-structure
2
+ ; Declare the string constant as a global constant.
3
+ @.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
4
+
5
+ ; External declaration of the puts function
6
+ declare i32 @puts(i8* nocapture) nounwind
7
+
8
+ ; Definition of main function
9
+ define i32 @main() { ; i32()*
10
+ ; Convert [13 x i8]* to i8 *...
11
+ %cast210 = getelementptr [13 x i8]* @.str, i64 0, i64 0
12
+
13
+ ; Call puts function to write out the string to stdout.
14
+ call i32 @puts(i8* %cast210)
15
+ ret i32 0
16
+ }
17
+
18
+ ; Named metadata
19
+ !1 = metadata !{i32 42}
20
+ !foo = !{!1, null}
@@ -0,0 +1,9 @@
1
+ diff(plus(A,B), X, plus(DA, DB))
2
+ <= diff(A, X, DA) and diff(B, X, DB).
3
+
4
+ diff(times(A,B), X, plus(times(A, DB), times(DA, B)))
5
+ <= diff(A, X, DA) and diff(B, X, DB).
6
+
7
+ equal(X, X).
8
+ diff(X, X, 1).
9
+ diff(Y, X, 0) <= not equal(Y, X).
@@ -89,6 +89,42 @@ module Rouge
89
89
  registry.values.uniq
90
90
  end
91
91
 
92
+ # Guess which lexer to use based on a hash of info.
93
+ #
94
+ # This accepts the same arguments as Lexer.guess, but will never throw
95
+ # an error. It will return a (possibly empty) list of potential lexers
96
+ # to use.
97
+ def guesses(info={})
98
+ mimetype, filename, source = info.values_at(:mimetype, :filename, :source)
99
+ lexers = registry.values.uniq
100
+ total_size = lexers.size
101
+
102
+ lexers = filter_by_mimetype(lexers, mimetype) if mimetype
103
+ return lexers if lexers.size == 1
104
+
105
+ lexers = filter_by_filename(lexers, filename) if filename
106
+ return lexers if lexers.size == 1
107
+
108
+ if source
109
+ # If we're filtering against *all* lexers, we only use confident return
110
+ # values from analyze_text. But if we've filtered down already, we can trust
111
+ # the analysis more.
112
+ source_threshold = lexers.size < total_size ? 0 : 0.5
113
+ return [best_by_source(lexers, source, source_threshold)].compact
114
+ end
115
+
116
+ []
117
+ end
118
+
119
+ class AmbiguousGuess < StandardError
120
+ attr_reader :alternatives
121
+ def initialize(alternatives); @alternatives = alternatives; end
122
+
123
+ def message
124
+ "Ambiguous guess: can't decide between #{alternatives.map(&:tag).inspect}"
125
+ end
126
+ end
127
+
92
128
  # Guess which lexer to use based on a hash of info.
93
129
  #
94
130
  # @option info :mimetype
@@ -101,41 +137,71 @@ module Rouge
101
137
  # other hints.
102
138
  #
103
139
  # @see Lexer.analyze_text
140
+ # @see Lexer.multi_guess
104
141
  def guess(info={})
105
- by_mimetype = guess_by_mimetype(info[:mimetype]) if info[:mimetype]
106
- return by_mimetype if by_mimetype
107
-
108
- by_filename = guess_by_filename(info[:filename]) if info[:filename]
109
- return by_filename if by_filename
142
+ lexers = guesses(info)
110
143
 
111
- by_source = guess_by_source(info[:source]) if info[:source]
112
- return by_source if by_source
144
+ return Lexers::Text if lexers.empty?
145
+ return lexers[0] if lexers.size == 1
113
146
 
114
- # guessing failed, just parse it as text
115
- return Lexers::Text
147
+ raise AmbiguousGuess.new(lexers)
116
148
  end
117
149
 
118
150
  def guess_by_mimetype(mt)
119
- registry.values.detect do |lexer|
120
- lexer.mimetypes.include? mt
121
- end
151
+ guess :mimetype => mt
122
152
  end
123
153
 
124
154
  def guess_by_filename(fname)
155
+ guess :filename => fname
156
+ end
157
+
158
+ def guess_by_source(source)
159
+ guess :source => source
160
+ end
161
+
162
+ private
163
+ def filter_by_mimetype(lexers, mt)
164
+ lexers.select { |lexer| lexer.mimetypes.include? mt }
165
+ end
166
+
167
+ # returns a list of lexers that match the given filename with
168
+ # equal specificity (i.e. number of wildcards in the pattern).
169
+ # This helps disambiguate between, e.g. the Nginx lexer, which
170
+ # matches `nginx.conf`, and the Conf lexer, which matches `*.conf`.
171
+ # In this case, nginx will win because the pattern has no wildcards,
172
+ # while `*.conf` has one.
173
+ def filter_by_filename(lexers, fname)
125
174
  fname = File.basename(fname)
126
- registry.values.detect do |lexer|
127
- lexer.filenames.any? do |pattern|
128
- File.fnmatch?(pattern, fname, File::FNM_DOTMATCH)
175
+
176
+ out = []
177
+ best_seen = nil
178
+ lexers.each do |lexer|
179
+ score = lexer.filenames.map do |pattern|
180
+ if File.fnmatch?(pattern, fname, File::FNM_DOTMATCH)
181
+ # specificity is better the fewer wildcards there are
182
+ pattern.scan(/[*?\[]/).size
183
+ end
184
+ end.compact.min
185
+
186
+ next unless score
187
+
188
+ if best_seen.nil? || score < best_seen
189
+ best_seen = score
190
+ out = [lexer]
191
+ elsif score == best_seen
192
+ out << lexer
129
193
  end
130
194
  end
195
+
196
+ out
131
197
  end
132
198
 
133
- def guess_by_source(source)
199
+ def best_by_source(lexers, source, threshold=0)
134
200
  assert_utf8!(source)
135
201
 
136
202
  source = TextAnalyzer.new(source)
137
203
 
138
- best_result = 0
204
+ best_result = threshold
139
205
  best_match = nil
140
206
  registry.values.each do |lexer|
141
207
  result = lexer.analyze_text(source) || 0
@@ -150,11 +216,13 @@ module Rouge
150
216
  best_match
151
217
  end
152
218
 
219
+ protected
153
220
  # @private
154
221
  def register(name, lexer)
155
222
  registry[name.to_s] = lexer
156
223
  end
157
224
 
225
+ public
158
226
  # Used to specify or get the canonical name of this lexer class.
159
227
  #
160
228
  # @example
@@ -332,7 +400,8 @@ module Rouge
332
400
  #
333
401
  # Return a number between 0 and 1 indicating the likelihood that
334
402
  # the text given should be lexed with this lexer. The default
335
- # implementation returns 0.
403
+ # implementation returns 0. Values under 0.5 will only be used
404
+ # to disambiguate filename or mimetype matches.
336
405
  #
337
406
  # @param [TextAnalyzer] text
338
407
  # the text to be analyzed, with a couple of handy methods on it,
@@ -50,13 +50,13 @@ module Rouge
50
50
  rule /@"(\\.|.)*?"/, 'Literal.String'
51
51
  rule /"(\\.|.)*?["\n]/, 'Literal.String'
52
52
  rule /'(\\.|.)'/, 'Literal.String.Char'
53
+ rule /0x[0-9a-f]+[lu]?/i, 'Literal.Number'
53
54
  rule %r(
54
55
  [0-9]
55
56
  ([.][0-9]*)? # decimal
56
57
  (e[+-][0-9]+)? # exponent
57
- [fld]? # type
58
+ [fldu]? # type
58
59
  )ix, 'Literal.Number'
59
- rule /0x[0-9a-f]+l?/i, 'Literal.Number'
60
60
  rule /^#[ \t]*(#{cpp_keywords.join('|')})\b.*?\n/,
61
61
  'Comment.Preproc'
62
62
  rule /\b(#{keywords.join('|')})\b/, 'Keyword'
@@ -0,0 +1,130 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Gherkin < RegexLexer
6
+ tag 'gherkin'
7
+ aliases 'cucumber'
8
+
9
+ filenames '*.feature'
10
+ mimetypes 'text/x-gherkin'
11
+
12
+ def self.analyze_text(text)
13
+ return 1 if text.shebang? 'cucumber'
14
+ end
15
+
16
+ # self-modifying method that loads the keywords file
17
+ def self.keywords
18
+ load Pathname.new(__FILE__).dirname.join('gherkin/keywords.rb')
19
+ keywords
20
+ end
21
+
22
+ def self.step_regex
23
+ # in Gherkin's config, keywords that end in < don't
24
+ # need word boundaries at the ends - all others do.
25
+ @step_regex ||= Regexp.new(
26
+ keywords[:step].map do |w|
27
+ if w.end_with? '<'
28
+ Regexp.escape(w.chop)
29
+ else
30
+ "#{Regexp.escape(w)}\\b"
31
+ end
32
+ end.join('|')
33
+ )
34
+ end
35
+
36
+ rest_of_line = /.*?(?=[#\n])/
37
+
38
+ state :basic do
39
+ rule %r(#.*$), 'Comment'
40
+ rule /[ \r\t]+/, 'Text'
41
+ end
42
+
43
+ state :root do
44
+ mixin :basic
45
+ rule %r(\n), 'Text'
46
+ rule %r(""".*?""")m, 'Literal.String'
47
+ rule %r(@[^\s@]+), 'Name.Tag'
48
+ mixin :has_table
49
+ mixin :has_examples
50
+ end
51
+
52
+ state :has_scenarios do
53
+ rule %r((.*?)(:)) do |m|
54
+ reset_stack
55
+
56
+ keyword = m[1]
57
+ if self.class.keywords[:element].include? keyword
58
+ group 'Keyword.Namespace'; push :description
59
+ elsif self.class.keywords[:feature].include? keyword
60
+ group 'Keyword.Declaration'; push :feature_description
61
+ elsif self.class.keywords[:examples].include? keyword
62
+ group 'Name.Namespace'; push :example_description
63
+ else
64
+ group 'Error'
65
+ end
66
+
67
+ group 'Punctuation'
68
+ end
69
+ end
70
+
71
+ state :has_examples do
72
+ mixin :has_scenarios
73
+ rule Gherkin.step_regex, 'Name.Function' do
74
+ token 'Name.Function'
75
+ reset_stack; push :step
76
+ end
77
+ end
78
+
79
+ state :has_table do
80
+ rule(/(?=[|])/) { push :table_header }
81
+ end
82
+
83
+ state :table_header do
84
+ rule /[^|\s]+/, 'Name.Variable'
85
+ rule /\n/ do
86
+ token 'Text'
87
+ pop!; push :table
88
+ end
89
+ mixin :table
90
+ end
91
+
92
+ state :table do
93
+ rule(/^(?=\s*[^\s|])/) { reset_stack }
94
+ mixin :basic
95
+ rule /[|]/, 'Punctuation'
96
+ rule /[^|\s]+/, 'Name'
97
+ end
98
+
99
+ state :description do
100
+ mixin :basic
101
+ mixin :has_examples
102
+ rule /\n/, 'Text'
103
+ rule rest_of_line, 'Text'
104
+ end
105
+
106
+ state :feature_description do
107
+ mixin :basic
108
+ mixin :has_scenarios
109
+ rule /\n/, 'Text'
110
+ rule rest_of_line, 'Text'
111
+ end
112
+
113
+ state :example_description do
114
+ mixin :basic
115
+ mixin :has_table
116
+ rule /\n/, 'Text'
117
+ rule rest_of_line, 'Text'
118
+ end
119
+
120
+ state :step do
121
+ mixin :basic
122
+ rule /<.*?>/, 'Name.Variable'
123
+ rule /".*?"/, 'Literal.String'
124
+ rule /\S+/, 'Text'
125
+ rule rest_of_line, 'Text', :pop!
126
+ end
127
+ end
128
+ end
129
+ end
130
+
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # automatically generated by `rake builtins:gherkin`
3
+ module Rouge
4
+ module Lexers
5
+ def Gherkin.keywords
6
+ @keywords ||= {}.tap do |k|
7
+ k[:feature] = Set.new ["Ability", "Ahoy matey!", "Arwedd", "Aspekt", "Business Need", "Caracteristica", "Característica", "Egenskab", "Egenskap", "Eiginleiki", "Feature", "Fitur", "Fonctionnalité", "Funcionalidade", "Funcionalitat", "Functionalitate", "Functionaliteit", "Funcţionalitate", "Funcționalitate", "Fungsi", "Funkcia", "Funkcionalitāte", "Funkcionalnost", "Funkcja", "Funktionalität", "Funktionalitéit", "Funzionalità", "Fīča", "Jellemző", "Mogucnost", "Mogućnost", "OH HAI", "Omadus", "Ominaisuus", "Osobina", "Potrzeba biznesowa", "Požadavek", "Požiadavka", "Pretty much", "Savybė", "Trajto", "Tính năng", "Vlastnosť", "Właściwość", "Özellik", "Могућност", "Мөмкинлек", "Особина", "Свойство", "Функционал", "Функционалност", "Функция", "Функціонал", "Үзенчәлеклелек", "תכונה", "خاصية", "وِیژگی", "रूप लेख", "గుణము", "フィーチャ", "功能", "機能", "기능"]
8
+ k[:element] = Set.new ["Abstract Scenario", "Abstrakt Scenario", "Achtergrond", "All y'all", "Antecedentes", "Antecedents", "Atburðarás", "Awww, look mate", "B4", "Background", "Baggrund", "Bakgrund", "Bakgrunn", "Bakgrunnur", "Bối cảnh", "Cefndir", "Cenario", "Cenario de Fundo", "Cenário", "Cenário de Fundo", "Contesto", "Context", "Contexte", "Contexto", "Dasar", "Delineacao do Cenario", "Delineação do Cenário", "Dis is what went down", "Escenari", "Escenario", "Esquema de l'escenari", "Esquema del escenario", "Esquema do Cenario", "Esquema do Cenário", "First off", "Fono", "Forgatókönyv", "Forgatókönyv vázlat", "Fundo", "Geçmiş", "Grundlage", "Hannergrond", "Heave to", "Háttér", "Khung kịch bản", "Khung tình huống", "Koncept", "Kontekst", "Kontekstas", "Konteksts", "Kontext", "Konturo de la scenaro", "Kịch bản", "Latar Belakang", "Lýsing Atburðarásar", "Lýsing Dæma", "MISHUN", "MISHUN SRSLY", "Menggariskan Senario ", "Náčrt Scenára", "Náčrt Scenáru", "Náčrt Scénáře", "Osnova", "Osnova Scenára", "Osnova scénáře", "Plan du Scénario", "Plan du scénario", "Plang vum Szenario", "Pozadie", "Pozadina", "Pozadí", "Primer", "Raamstsenaarium", "Reckon it's like", "Rerefons", "Scenarie", "Scenarij", "Scenarijaus šablonas", "Scenarijus", "Scenario", "Scenario Amlinellol", "Scenario Outline", "Scenario Template", "Scenariomal", "Scenariomall", "Scenariu", "Scenariusz", "Scenaro", "Scenár", "Scenārijs", "Scenārijs pēc parauga", "Schema dello scenario", "Scénario", "Scénář", "Senario", "Senaryo", "Senaryo taslağı", "Shiver me timbers", "Situācija", "Skenario", "Skenario konsep", "Skica", "Structura scenariu", "Structură scenariu", "Struktura scenarija", "Stsenaarium", "Szablon scenariusza", "Szenario", "Szenariogrundriss", "Tapaus", "Tapausaihio", "Taust", "Tausta", "The thing of it is", "Tình huống", "Wharrimean is", "Yo-ho-ho", "Założenia", "Кереш", "Контекст", "Концепт", "Основа", "Передумова", "Позадина", "Предистория", "Предыстория", "Пример", "Рамка на сценарий", "Скица", "Структура сценария", "Структура сценарија", "Структура сценарію", "Сценарий", "Сценарий структураси", "Сценарийның төзелеше", "Сценарио", "Сценарій", "Тарих", "רקע", "תבנית תרחיש", "תרחיש", "الخلفية", "الگوی سناریو", "زمینه", "سناریو", "سيناريو", "سيناريو مخطط", "परिदृश्य", "परिदृश्य रूपरेखा", "पृष्ठभूमि", "కథనం", "నేపథ్యం", "సన్నివేశం", "シナリオ", "シナリオアウトライン", "シナリオテンプレ", "シナリオテンプレート", "テンプレ", "剧本", "剧本大纲", "劇本", "劇本大綱", "场景", "场景大纲", "場景", "場景大綱", "背景", "배경", "시나리오", "시나리오 개요"]
9
+ k[:examples] = Set.new ["Atburðarásir", "Beispiele", "Beispiller", "Cenarios", "Cenários", "Contoh", "Contoh ", "Dead men tell no tales", "Dæmi", "Dữ liệu", "EXAMPLZ", "Ejemplos", "Eksempler", "Ekzemploj", "Enghreifftiau", "Esempi", "Examples", "Exempel", "Exemple", "Exemples", "Exemplos", "Juhtumid", "Paraugs", "Pavyzdžiai", "Piemēri", "Primeri", "Primjeri", "Przykłady", "Príklady", "Példák", "Příklady", "Scenarijai", "Scenariji", "Scenarios", "Tapaukset", "Variantai", "Voorbeelden", "You'll wanna", "Örnekler", "Мисаллар", "Мисоллар", "Приклади", "Примери", "Примеры", "Сценарији", "Үрнәкләр", "דוגמאות", "امثلة", "نمونه ها", "उदाहरण", "ఉదాహరణలు", "サンプル", "例", "例子", "예"]
10
+ k[:step] = Set.new ["*", "A", "A taktiež", "A také", "A tiež", "A zároveň", "AN", "Aber", "Adott", "Ak", "Akkor", "Ale", "Aleshores", "Ali", "Allora", "Alors", "Als", "Ama", "Amennyiben", "Amikor", "An", "And", "And y'all", "Angenommen", "Anrhegedig a", "Apabila", "Atesa", "Atunci", "Atès", "Avast!", "Aye", "BUT", "Bagi", "Bet", "Biết", "Blimey!", "Buh", "But", "But at the end of the day I reckon", "But y'all", "Cal", "Cand", "Cho", "Cuando", "Când", "DEN", "Dada", "Dadas", "Dado", "Dados", "Dan", "Dann", "Dar", "Dat fiind", "Data", "Date", "Date fiind", "Dati", "Dati fiind", "Dato", "Daţi fiind", "Dați fiind", "De", "Den youse gotta", "Dengan", "Diyelim ki", "Do", "Donada", "Donat", "Donitaĵo", "Dun", "Duota", "E", "Eeldades", "Ef", "En", "Entao", "Entonces", "Então", "Et", "Etant donné", "Etant donnée", "Etant données", "Etant donnés", "Eğer ki", "Fakat", "Gangway!", "Gdy", "Gegeben sei", "Gegeven", "Gitt", "Given", "Given y'all", "Givet", "Givun", "Ha", "I", "I CAN HAZ", "Ir", "It's just unbelievable", "Ja", "Jeśli", "Jeżeli", "Kad", "Kada", "Kai", "Kaj", "Když", "Kemudian", "Ketika", "Keď", "Khi", "Kiedy", "Kui", "Kuid", "Kun", "Let go and haul", "Lorsqu'<", "Lorsque", "Ma", "Maar", "Mais", "Majd", "Mając", "Maka", "Mas", "Men", "Mutta", "Nhưng", "Niin", "När", "Når", "O zaman", "Och", "Og", "Oletetaan", "Ond", "Onda", "Oraz", "Pak", "Pero", "Però", "Pokiaľ", "Pokud", "Potom", "Pryd", "Quan", "Quand", "Quando", "Se", "Sed", "Si", "Siis", "Soit", "Stel", "Så", "Tad", "Tada", "Tak", "Tapi", "Tetapi", "Then", "Then y'all", "Thì", "Too right", "Un", "Und", "Ve", "Và", "WEN", "Wenn", "When", "When y'all", "Wtedy", "Wun", "Y", "Y'know", "Yeah nah", "Yna", "Youse know like when", "Youse know when youse got", "Za predpokladu", "Za předpokladu", "Zadan", "Zadani", "Zadano", "Zadate", "Zadato", "Zakładając", "Zatati", "a", "an", "awer", "dann", "mä", "ugeholl", "wann", "És", "Étant donné", "Étant donnée", "Étant données", "Étant donnés", "Þegar", "Þá", "Şi", "Și", "І", "А", "А також", "Агар", "Але", "Али", "Аммо", "Бирок", "Ва", "Вә", "Дадено", "Дано", "Допустим", "Если", "Задате", "Задати", "Задато", "И", "К тому же", "Кад", "Када", "Когато", "Когда", "Коли", "Лекин", "Ләкин", "Нехай", "Но", "Нәтиҗәдә", "Онда", "Припустимо", "Припустимо, що", "Пусть", "Та", "Также", "То", "Тогда", "Тоді", "Унда", "Якщо", "Һәм", "Әгәр", "Әйтик", "Әмма", "אבל", "אז", "אזי", "בהינתן", "וגם", "כאשר", "آنگاه", "اذاً", "اما", "با فرض", "بفرض", "ثم", "عندما", "لكن", "متى", "هنگامی", "و", "अगर", "और", "चूंकि", "जब", "तथा", "तब", "पर", "यदि", "అప్పుడు", "ఈ పరిస్థితిలో", "కాని", "చెప్పబడినది", "మరియు", "かつ<", "しかし<", "ただし<", "ならば<", "もし<", "並且<", "但し<", "但是<", "假如<", "假定<", "假設<", "假设<", "前提<", "同时<", "同時<", "并且<", "当<", "當<", "而且<", "那么<", "那麼<", "그러면<", "그리고<", "단<", "만약<", "만일<", "먼저<", "조건<", "하지만<"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -3,7 +3,7 @@ module Rouge
3
3
  class HTML < RegexLexer
4
4
  desc "HTML, the markup language of the web"
5
5
  tag 'html'
6
- filenames '*.htm', '*.html', '*.xhtml', '*.xslt'
6
+ filenames '*.htm', '*.html', '*.xhtml'
7
7
  mimetypes 'text/html', 'application/xhtml+xml'
8
8
 
9
9
  def self.analyze_text(text)
@@ -0,0 +1,81 @@
1
+ module Rouge
2
+ module Lexers
3
+ class LLVM < RegexLexer
4
+ desc 'The LLVM Compiler Infrastructure (http://llvm.org/)'
5
+ tag 'llvm'
6
+
7
+ filenames '*.ll'
8
+ mimetypes 'text/x-llvm'
9
+
10
+ def self.analyze_text(text)
11
+ return 0.1 if text =~ /\A%\w+\s=\s/
12
+ end
13
+
14
+ string = /"[^"]*?"/
15
+ identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/
16
+
17
+ state :basic do
18
+ rule /;.*?$/, 'Comment.Single'
19
+ rule /\s+/, 'Text'
20
+
21
+ rule /#{identifier}\s*:/, 'Literal.Name.Label'
22
+
23
+ rule /@(#{identifier}|\d+)/, 'Name.Variable.Global'
24
+ rule /(%|!)#{identifier}/, 'Name.Variable'
25
+ rule /(%|!)\d+/, 'Name.Variable.Anonymous'
26
+
27
+ rule /c?#{string}/, 'Literal.String'
28
+
29
+ rule /0[xX][a-fA-F0-9]+/, 'Literal.Number'
30
+ rule /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, 'Literal.Number'
31
+
32
+ rule /[=<>{}\[\]()*.,!]|x/, 'Punctuation'
33
+ end
34
+
35
+ builtin_types = %w(
36
+ void float double half x86_fp80 x86mmx fp128 ppc_fp128 label metadata
37
+ )
38
+
39
+ state :types do
40
+ rule /i[1-9]\d*/, 'Keyword.Type'
41
+ rule /#{builtin_types.join('|')}/, 'Keyword.Type'
42
+ end
43
+
44
+ builtin_keywords = %w(
45
+ begin end true false declare define global constant personality private
46
+ landingpad linker_private internal available_externally linkonce_odr
47
+ linkonce weak weak_odr appending dllimport dllexport common default
48
+ hidden protected extern_weak external thread_local zeroinitializer
49
+ undef null to tail target triple datalayout volatile nuw nsw nnan ninf
50
+ nsz arcp fast exact inbounds align addrspace section alias module asm
51
+ sideeffect gc dbg ccc fastcc coldcc x86_stdcallcc x86_fastcallcc
52
+ arm_apcscc arm_aapcscc arm_aapcs_vfpcc ptx_device ptx_kernel cc
53
+ c signext zeroext inreg sret nounwind noreturn noalias nocapture byval
54
+ nest readnone readonly inlinehint noinline alwaysinline optsize ssp
55
+ sspreq noredzone noimplicitfloat naked type opaque eq ne slt sgt sle
56
+ sge ult ugt ule uge oeq one olt ogt ole oge ord uno unnamed_addr ueq
57
+ une uwtable x
58
+ )
59
+
60
+ builtin_instructions = %w(
61
+ add fadd sub fsub mul fmul udiv sdiv fdiv urem srem frem shl lshr ashr
62
+ and or xor icmp fcmp phi call catch trunc zext sext fptrunc fpext
63
+ uitofp sitofp fptoui fptosi inttoptr ptrtoint bitcast select va_arg ret
64
+ br switch invoke unwind unreachable malloc alloca free load store
65
+ getelementptr extractelement insertelement shufflevector getresult
66
+ extractvalue insertvalue cleanup resume
67
+ )
68
+
69
+ state :keywords do
70
+ rule /#{builtin_instructions.join('|')}/, 'Keyword'
71
+ rule /#{builtin_keywords.join('|')}/, 'Keyword'
72
+ end
73
+
74
+ state :root do
75
+ mixin :basic
76
+ mixin :keywords
77
+ mixin :types
78
+ end
79
+ end
80
+ end
81
+ end
@@ -8,7 +8,7 @@ module Rouge
8
8
  mimetypes 'text/x-makefile'
9
9
 
10
10
  def self.analyze_text(text)
11
- return 0.2 if text =~ /^\.PHONY:/
11
+ return 0.6 if text =~ /^\.PHONY:/
12
12
  end
13
13
 
14
14
  bsd_special = %w(
@@ -1,6 +1,7 @@
1
1
  module Rouge
2
2
  module Lexers
3
3
  class Nginx < RegexLexer
4
+ desc 'configuration files for the nginx web server (nginx.org)'
4
5
  tag 'nginx'
5
6
  mimetypes 'text/x-nginx-conf'
6
7
  filenames 'nginx.conf'
@@ -11,7 +11,7 @@ module Rouge
11
11
 
12
12
  def self.analyze_text(text)
13
13
  return 1 if text.shebang? 'perl'
14
- return 0.9 if text.include? 'my $'
14
+ return 0.4 if text.include? 'my $'
15
15
  end
16
16
 
17
17
  keywords = %w(
@@ -0,0 +1,61 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Prolog < RegexLexer
4
+ desc "The Prolog programming language (http://en.wikipedia.org/wiki/Prolog)"
5
+ tag 'prolog'
6
+ aliases 'prolog'
7
+ filenames '*.pro', '*.P', '*.prolog', '*.pl'
8
+ mimetypes 'text/x-prolog'
9
+
10
+ def self.analyze_text(text)
11
+ return 0.1 if text =~ /\A\w+(\(\w+\,\s*\w+\))*\./
12
+ return 0.1 if text.include? ':-'
13
+ end
14
+
15
+ state :basic do
16
+ rule /\s+/, 'Text'
17
+ rule /^#.*/, 'Comment.Single'
18
+ rule /\/\*/, 'Comment.Multiline', :nested_comment
19
+
20
+ rule /[\[\](){}|.,;!]/, 'Punctuation'
21
+ rule /:-|-->/, 'Punctuation'
22
+
23
+ rule /"[^"]*"/, 'Literal.String.Double'
24
+
25
+ rule /\d+\.\d+/, 'Literal.Number.Float'
26
+ rule /\d+/, 'Literal.Number'
27
+ end
28
+
29
+ state :atoms do
30
+ rule /[[:lower:]]([_[:lower:][:digit:]])*/, 'Literal.String.Symbol'
31
+ rule /'[^']*'/, 'Literal.String.Symbol'
32
+ end
33
+
34
+ state :operators do
35
+ rule /(<|>|=<|>=|==|=:=|=|\/|\/\/|\*|\+|-)(?=\s|[a-zA-Z0-9\[])/,
36
+ 'Operator'
37
+ rule /is/, 'Operator'
38
+ rule /(mod|div|not)/, 'Operator'
39
+ rule /[#&*+-.\/:<=>?@^~]+/, 'Operator'
40
+ end
41
+
42
+ state :variables do
43
+ rule /[A-Z]+\w*/, 'Name.Variable'
44
+ rule /_[[:word:]]*/, 'Name.Variable'
45
+ end
46
+
47
+ state :root do
48
+ mixin :basic
49
+ mixin :atoms
50
+ mixin :variables
51
+ mixin :operators
52
+ end
53
+
54
+ state :nested_comment do
55
+ rule /\/\*/, 'Comment.Multiline', :push
56
+ rule /\s*\*[^*\/]+/, 'Comment.Multiline'
57
+ rule /\*\//, 'Comment.Multiline', :pop!
58
+ end
59
+ end
60
+ end
61
+ end
@@ -13,9 +13,11 @@ module Rouge
13
13
  )
14
14
 
15
15
  def self.analyze_text(text)
16
- return 0.5 if text.doctype?
17
- return 0.5 if text[0..1000] =~ %r(<.+?>.*?</.+?>)m
16
+ return 0.9 if text.doctype?
18
17
  return 0.8 if text =~ /\A<\?xml\b/
18
+ start = text[0..1000]
19
+ return 0.6 if start =~ %r(<xml\b)
20
+ return 0.3 if start =~ %r(<.+?>.*?</.+?>)m
19
21
  end
20
22
 
21
23
  state :root do
@@ -1,5 +1,5 @@
1
1
  module Rouge
2
2
  def self.version
3
- "0.2.15"
3
+ "0.3.0"
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.15
4
+ version: 0.3.0
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: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  type: :runtime
@@ -61,6 +61,7 @@ files:
61
61
  - lib/rouge/lexers/csharp.rb
62
62
  - lib/rouge/lexers/php/builtins.rb
63
63
  - lib/rouge/lexers/nginx.rb
64
+ - lib/rouge/lexers/llvm.rb
64
65
  - lib/rouge/lexers/perl.rb
65
66
  - lib/rouge/lexers/groovy.rb
66
67
  - lib/rouge/lexers/sed.rb
@@ -78,6 +79,7 @@ files:
78
79
  - lib/rouge/lexers/php.rb
79
80
  - lib/rouge/lexers/tcl.rb
80
81
  - lib/rouge/lexers/tex.rb
82
+ - lib/rouge/lexers/gherkin.rb
81
83
  - lib/rouge/lexers/rust.rb
82
84
  - lib/rouge/lexers/ini.rb
83
85
  - lib/rouge/lexers/scss.rb
@@ -94,6 +96,7 @@ files:
94
96
  - lib/rouge/lexers/erb.rb
95
97
  - lib/rouge/lexers/literate_haskell.rb
96
98
  - lib/rouge/lexers/c.rb
99
+ - lib/rouge/lexers/gherkin/keywords.rb
97
100
  - lib/rouge/lexers/io.rb
98
101
  - lib/rouge/lexers/lua/builtins.rb
99
102
  - lib/rouge/lexers/python.rb
@@ -101,6 +104,7 @@ files:
101
104
  - lib/rouge/lexers/sql.rb
102
105
  - lib/rouge/lexers/haskell.rb
103
106
  - lib/rouge/lexers/markdown.rb
107
+ - lib/rouge/lexers/prolog.rb
104
108
  - lib/rouge/lexers/conf.rb
105
109
  - lib/rouge.rb
106
110
  - bin/rougify
@@ -117,6 +121,7 @@ files:
117
121
  - lib/rouge/demos/shell
118
122
  - lib/rouge/demos/perl
119
123
  - lib/rouge/demos/text
124
+ - lib/rouge/demos/prolog
120
125
  - lib/rouge/demos/viml
121
126
  - lib/rouge/demos/haskell
122
127
  - lib/rouge/demos/css
@@ -126,6 +131,7 @@ files:
126
131
  - lib/rouge/demos/io
127
132
  - lib/rouge/demos/c
128
133
  - lib/rouge/demos/scss
134
+ - lib/rouge/demos/llvm
129
135
  - lib/rouge/demos/literate_coffeescript
130
136
  - lib/rouge/demos/python
131
137
  - lib/rouge/demos/make
@@ -138,6 +144,7 @@ files:
138
144
  - lib/rouge/demos/groovy
139
145
  - lib/rouge/demos/nginx
140
146
  - lib/rouge/demos/toml
147
+ - lib/rouge/demos/gherkin
141
148
  - lib/rouge/demos/rust
142
149
  - lib/rouge/demos/json
143
150
  - lib/rouge/demos/markdown