@@ -243,6 +243,18 @@ Inside a complex rule's block, it's possible to call {Rouge::RegexLexer#push},
243243{Rouge::RegexLexer#pop!}, {Rouge::RegexLexer#token} and
244244{Rouge::RegexLexer#delegate}.
245245
246+ One common use case of the block syntax is to use {Rouge::RegexLexer#groups}
247+ to easily assign token types to various capture groups of the regex. For
248+ example, in Java, we might detect attribute accessors with:
249+
250+ ``` rb
251+ rule /([.] )(\w +) / do
252+ groups Operator , Name ::Attribute
253+ end
254+ ```
255+
256+ Make sure you don't forget to include * all* of the matched text in the output!
257+
246258You can see an example of these more complex rules in [ the Ruby lexer] [ ruby-lexer ] .
247259
248260### Additional Features
@@ -283,10 +295,10 @@ Filename Globs][conflict-globs] below.
283295
284296#### Special Words
285297
286- Every programming language reserves certain words for use as identifiers that
298+ Most programming languages reserve certain words for use as identifiers that
287299have a special meaning in the language. To make regular expressions that search
288- for these words easier, many lexers will put the applicable keywords in an
289- array and make them available in a particular way (be it as a local variable,
300+ for these words easier, many lexers will put the applicable keywords in a
301+ set and make them available in a particular way (be it as a local variable,
290302an instance variable or what have you).
291303
292304For performance and safety, we strongly recommend lexers use a class method:
@@ -295,13 +307,14 @@ For performance and safety, we strongly recommend lexers use a class method:
295307module Rouge
296308 module Lexers
297309 class YetAnotherLanguage < RegexLexer
298- ...
310+ ...
299311
300- def self .keywords
301- @keywords ||= Set .new %w(key words used in this language)
302- end
312+ def self .keywords
313+ @keywords ||= Set .new %w(key words used in this language)
314+ end
303315
304- ...
316+ ...
317+ end
305318 end
306319end
307320```
@@ -495,10 +508,8 @@ The spec and the demo can be run using the `rake` command. You can run this by
495508typing ` bundle exec rake ` at the command line. If everything works, you should
496509see a series of dots. If you have an error, this will appear here, too.
497510
498- You can also run ` bundle exec rake VERBOSE=1 ` to see all warnings.
499-
500511To see your visual sample, launch Rouge's visual test app by running
501- ` bundle exec rackup ` . You can choose your sample from the complete list by going
512+ ` bundle exec puma ` . You can choose your sample from the complete list by going
502513to < http://localhost:9292 > .
503514
504515## How to Submit
0 commit comments