Skip to content

Commit 4623028

Browse files
committed
cleanup Tokens documentation
1 parent cb41b00 commit 4623028

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

lib/coderay/tokens.rb

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@ module CodeRay
33
# GZip library for writing and reading token dumps.
44
autoload :GZip, coderay_path('helpers', 'gzip')
55

6-
# = Tokens TODO: Rewrite!
6+
# The Tokens class represents a list of tokens returned from
7+
# a Scanner. It's actually just an Array with a few helper methods.
78
#
8-
# The Tokens class represents a list of tokens returnd from
9-
# a Scanner.
10-
#
11-
# A token is not a special object, just a two-element Array
9+
# A token itself is not a special object, just a two-element Array
1210
# consisting of
1311
# * the _token_ _text_ (the original source of the token in a String) or
1412
# a _token_ _action_ (begin_group, end_group, begin_line, end_line)
1513
# * the _token_ _kind_ (a Symbol representing the type of the token)
1614
#
17-
# A token looks like this:
15+
# It looks like this:
1816
#
1917
# ['# It looks like this', :comment]
2018
# ['3.1415926', :float]
2119
# ['$^', :error]
2220
#
2321
# Some scanners also yield sub-tokens, represented by special
24-
# token actions, namely begin_group and end_group.
22+
# token actions, for example :begin_group and :end_group.
2523
#
2624
# The Ruby scanner, for example, splits "a string" into:
2725
#
@@ -33,23 +31,17 @@ module CodeRay
3331
# [:end_group, :string]
3432
# ]
3533
#
36-
# Tokens is the interface between Scanners and Encoders:
37-
# The input is split and saved into a Tokens object. The Encoder
38-
# then builds the output from this object.
39-
#
40-
# Thus, the syntax below becomes clear:
41-
#
42-
# CodeRay.scan('price = 2.59', :ruby).html
43-
# # the Tokens object is here -------^
34+
# Tokens can be used to save the output of a Scanners in a simple
35+
# Ruby object that can be send to an Encoder later:
4436
#
45-
# See how small it is? ;)
37+
# tokens = CodeRay.scan('price = 2.59', :ruby).tokens
38+
# tokens.encode(:html)
39+
# tokens.html
40+
# CodeRay.encoder(:html).encode_tokens(tokens)
4641
#
4742
# Tokens gives you the power to handle pre-scanned code very easily:
48-
# You can convert it to a webpage, a YAML file, or dump it into a gzip'ed string
49-
# that you put in your DB.
50-
#
51-
# It also allows you to generate tokens directly (without using a scanner),
52-
# to load them from a file, and still use any Encoder that CodeRay provides.
43+
# You can serialize it to a JSON string and store it in a database, pass it
44+
# around to encode it more than once, send it to other algorithms...
5345
class Tokens < Array
5446

5547
# The Scanner instance that created the tokens.
@@ -58,8 +50,7 @@ class Tokens < Array
5850
# Encode the tokens using encoder.
5951
#
6052
# encoder can be
61-
# * a symbol like :html oder :statistic
62-
# * an Encoder class
53+
# * a plugin name like :html oder 'statistic'
6354
# * an Encoder object
6455
#
6556
# options are passed to the encoder.

0 commit comments

Comments
 (0)