summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/tokens.rb
diff options
context:
space:
mode:
authorno author <noone@nowhere>2005-09-26 02:58:54 +0000
committerno author <noone@nowhere>2005-09-26 02:58:54 +0000
commit84b8431608174e74a4c0d2394eb330a6621bc74b (patch)
treeffc2bd7ce21708a9147247c80b0e7fc7728ea063 /lib/coderay/encoders/tokens.rb
downloadcoderay-84b8431608174e74a4c0d2394eb330a6621bc74b.tar.gz
New Repository, initial import
Diffstat (limited to 'lib/coderay/encoders/tokens.rb')
-rw-r--r--lib/coderay/encoders/tokens.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/coderay/encoders/tokens.rb b/lib/coderay/encoders/tokens.rb
new file mode 100644
index 0000000..4573307
--- /dev/null
+++ b/lib/coderay/encoders/tokens.rb
@@ -0,0 +1,44 @@
+module CodeRay
+ module Encoders
+
+ # The Tokens encoder converts the tokens to a simple
+ # readable format. It doesn't use colors and is mainly
+ # intended for console output.
+ #
+ # The tokens are converted with Tokens.write_token.
+ #
+ # The format is:
+ #
+ # <token-kind> \t <escaped token-text> \n
+ #
+ # Example:
+ #
+ # require 'coderay'
+ # puts CodeRay.scan("puts 3 + 4", :ruby).tokens
+ #
+ # prints:
+ #
+ # ident puts
+ # space
+ # integer 3
+ # space
+ # operator +
+ # space
+ # integer 4
+ #
+ class Tokens < Encoder
+
+ include Streamable
+ register_for :tokens
+
+ FILE_EXTENSION = 'tok'
+
+ protected
+ def token *args
+ @out << CodeRay::Tokens.write_token(*args)
+ end
+
+ end
+
+ end
+end