summaryrefslogtreecommitdiff
path: root/lib/coderay/encoder.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2005-10-04 04:04:07 +0000
committermurphy <murphy@rubychan.de>2005-10-04 04:04:07 +0000
commit48e144a20829faaeca9a7db8fbc6128f1f5d7297 (patch)
tree24326041ae8a5cc12a87ab96b8cdc67dba1e585e /lib/coderay/encoder.rb
parent0ae9f844faf25d3be9f6fe5f8157f6bfebb30942 (diff)
downloadcoderay-48e144a20829faaeca9a7db8fbc6128f1f5d7297.tar.gz
Two new encoders: debug and xml.
encoder.rb: new token handling encoders/statistic.rb: using new handling ruby_helper.rb: small improvements ruby.rb: - escapes in subtoken - Float detection changed - some multi-char operators are now scanned as one token - def and module definition handling changed bin/coderay: improved, new interface (still in progress) plugin.rb: more expressive load error message
Diffstat (limited to 'lib/coderay/encoder.rb')
-rw-r--r--lib/coderay/encoder.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb
index 74e1582..448a45b 100644
--- a/lib/coderay/encoder.rb
+++ b/lib/coderay/encoder.rb
@@ -122,11 +122,28 @@ module CodeRay
# Called with +text+ and +kind+ of the currently scanned token.
# For simple scanners, it's enougth to implement this method.
#
- # Raises a NotImplementedError exception if it is not overwritten
- # in subclass.
+ # By default, it calls text_token or block_token, depending on
+ # whether +text+ is a String.
def token text, kind
- raise NotImplementedError,
- "#{self.class}#token not implemented."
+ if text.is_a? String
+ text_token text, kind
+ else
+ block_token text, kind
+ end
+ end
+
+ def text_token text, kind
+ end
+
+ def block_token action, kind
+ case action
+ when :open
+ open_token kind
+ when :close
+ close_token kind
+ else
+ raise 'unknown block action: %p' % action
+ end
end
# Called with merged options after encoding starts.