summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-06-04 13:59:09 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2016-06-04 13:59:09 +0200
commit3e10d565f99025bdca003cc8fbd98d3260ae451a (patch)
tree85cd39a0101139a193b4d98ba8d0129a83884302
parent0b19ccfa96e1c7e4999e6e2619ae0b266b54402a (diff)
parent4c7bedc3bf2392444f62e90b7b8dc91d1a2effbb (diff)
downloadcoderay-3e10d565f99025bdca003cc8fbd98d3260ae451a.tar.gz
Merge branch 'master' into possible-speedups
-rw-r--r--.travis.yml11
-rw-r--r--Changes.textile5
-rw-r--r--FOLDERS96
-rw-r--r--Gemfile2
-rw-r--r--README.markdown6
-rw-r--r--lib/coderay.rb18
-rw-r--r--lib/coderay/encoders.rb18
-rw-r--r--lib/coderay/encoders/encoder.rb (renamed from lib/coderay/encoder.rb)11
-rw-r--r--lib/coderay/helpers/plugin.rb219
-rw-r--r--lib/coderay/helpers/plugin_host.rb221
-rw-r--r--lib/coderay/scanners.rb27
-rw-r--r--lib/coderay/scanners/cpp.rb36
-rw-r--r--lib/coderay/scanners/java.rb2
-rw-r--r--lib/coderay/scanners/scanner.rb (renamed from lib/coderay/scanner.rb)18
-rw-r--r--lib/coderay/styles.rb15
-rw-r--r--lib/coderay/styles/style.rb (renamed from lib/coderay/style.rb)7
16 files changed, 375 insertions, 337 deletions
diff --git a/.travis.yml b/.travis.yml
index f815698..a8080ce 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,6 @@
+env:
+ global:
+ - "JRUBY_OPTS=-Xcext.enabled=true"
rvm:
- 1.8.7
- ree
@@ -10,16 +13,16 @@ rvm:
- jruby-18mode
- jruby-19mode
- jruby-head
- - rbx-18mode
- - rbx-19mode
+ - rbx-2
branches:
only:
- master
matrix:
allow_failures:
- rvm: ruby-head
+ - rvm: jruby-18mode
+ - rvm: jruby-19mode
- rvm: jruby-head
- - rvm: rbx-18mode
- - rvm: rbx-19mode
+ - rvm: rbx-2
script: "rake test" # test:scanners"
sudo: false
diff --git a/Changes.textile b/Changes.textile
index 50da5c7..d77cff2 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -2,6 +2,10 @@ h1=. CodeRay Version History
p=. _This files lists all changes in the CodeRay library since the 0.9.8 release._
+h2. Changes in 1.1.2
+
+* C++ scanner: Added C++11 keywords. [#195, thanks to Johnny Willemsen]
+
h2. Changes in 1.1.1
* SQL scanner: Allow @$@ signs in SQL identifiers [#164, thanks to jasir and Ben Basson]
@@ -13,6 +17,7 @@ h2. Changes in 1.1.1
* Diff scanner: Prevent running out of regexp stack.
* HTML encoder: You can keep tabs intact now by setting @tab_width: false@.
* Alpha style: Tweaked colors for @:function@ group with @:content@.
+* File structure: One module per file, autoload CodeRay::Version, paths follow namespace hierarchy.
h2. Changes in 1.1
diff --git a/FOLDERS b/FOLDERS
index f29255a..1709d08 100644
--- a/FOLDERS
+++ b/FOLDERS
@@ -1,48 +1,48 @@
-= CodeRay - folder structure
-
-== bench - Benchmarking system
-
-All benchmarking stuff goes here.
-
-Test inputs are stored in files named <code>example.<lang></code>.
-Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
-
-Run <code>bench/bench.rb</code> to get a usage description.
-
-Run <code>rake bench</code> to perform an example benchmark.
-
-
-== bin - Scripts
-
-Executional files for CodeRay.
-
-coderay:: The CodeRay executable.
-
-== demo - Demos and functional tests
-
-Demonstrational scripts to show of CodeRay's features.
-
-Run them as functional tests with <code>rake test:demos</code>.
-
-
-== etc - Lots of stuff
-
-Some addidtional files for CodeRay, mainly graphics and Vim scripts.
-
-
-== lib - CodeRay library code
-
-This is the base directory for the CodeRay library.
-
-
-== rake_helpers - Rake helper libraries
-
-Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
-
-
-== test - Tests
-
-In the subfolder scanners/ are the scanners tests.
-Each language has its own subfolder and sub-suite.
-
-Run with <code>rake test</code>.
+= CodeRay - folder structure
+
+== bench - Benchmarking system
+
+All benchmarking stuff goes here.
+
+Test inputs are stored in files named <code>example.<lang></code>.
+Test outputs go to <code>bench/test.<encoder-default-file-extension></code>.
+
+Run <code>bench/bench.rb</code> to get a usage description.
+
+Run <code>rake bench</code> to perform an example benchmark.
+
+
+== bin - Scripts
+
+Executional files for CodeRay.
+
+coderay:: The CodeRay executable.
+
+== demo - Demos and functional tests
+
+Demonstrational scripts to show of CodeRay's features.
+
+Run them as functional tests with <code>rake test:demos</code>.
+
+
+== etc - Lots of stuff
+
+Some additional files for CodeRay, mainly graphics and Vim scripts.
+
+
+== lib - CodeRay library code
+
+This is the base directory for the CodeRay library.
+
+
+== rake_helpers - Rake helper libraries
+
+Some files to enhance Rake, including the Autumnal Rdoc template and some scripts.
+
+
+== test - Tests
+
+In the subfolder scanners/ are the scanners tests.
+Each language has its own subfolder and sub-suite.
+
+Run with <code>rake test</code>.
diff --git a/Gemfile b/Gemfile
index 6d3a176..592b79f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,7 +7,7 @@ gemspec
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "bundler"
- gem "rake"
+ gem "rake", "~> 10.5"
gem "RedCloth", RUBY_PLATFORM == 'java' ? ">= 4.2.7" : ">= 4.0.3"
gem "term-ansicolor"
gem 'tins', '~> 1.6.0'
diff --git a/README.markdown b/README.markdown
index 15b3447..c3f7106 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,8 +1,8 @@
# CodeRay
-[![Build Status](https://travis-ci.org/rubychan/coderay.png)](https://travis-ci.org/rubychan/coderay)
-[![Gem Version](https://badge.fury.io/rb/coderay.png)](http://badge.fury.io/rb/coderay)
-[![Dependency Status](https://gemnasium.com/rubychan/coderay.png)](https://gemnasium.com/rubychan/coderay)
+[![Build Status](https://travis-ci.org/rubychan/coderay.svg?branch=master)](https://travis-ci.org/rubychan/coderay)
+[![Gem Version](https://badge.fury.io/rb/coderay.svg)](https://badge.fury.io/rb/coderay)
+[![Dependency Status](https://gemnasium.com/rubychan/coderay.svg)](https://gemnasium.com/rubychan/coderay)
## About
diff --git a/lib/coderay.rb b/lib/coderay.rb
index f759ed6..c3de20b 100644
--- a/lib/coderay.rb
+++ b/lib/coderay.rb
@@ -134,7 +134,7 @@ module CodeRay
File.join CODERAY_PATH, *path
end
- require 'coderay/version'
+ autoload :VERSION, 'coderay/version'
# helpers
autoload :FileType, coderay_path('helpers', 'file_type')
@@ -145,13 +145,13 @@ module CodeRay
autoload :TokenKinds, coderay_path('token_kinds')
# Plugin system
- autoload :PluginHost, coderay_path('helpers', 'plugin')
+ autoload :PluginHost, coderay_path('helpers', 'plugin_host')
autoload :Plugin, coderay_path('helpers', 'plugin')
# Plugins
- autoload :Scanners, coderay_path('scanner')
- autoload :Encoders, coderay_path('encoder')
- autoload :Styles, coderay_path('style')
+ autoload :Scanners, coderay_path('scanners')
+ autoload :Encoders, coderay_path('encoders')
+ autoload :Styles, coderay_path('styles')
# convenience access and reusable Encoder/Scanner pair
autoload :Duo, coderay_path('duo')
@@ -166,7 +166,7 @@ module CodeRay
#
# See also demo/demo_simple.
def scan code, lang, options = {}, &block
- TokensProxy.new code, lang, options, block
+ CodeRay::TokensProxy.new code, lang, options, block
end
# Scans +filename+ (a path to a code file) with the Scanner for +lang+.
@@ -181,7 +181,7 @@ module CodeRay
# require 'coderay'
# page = CodeRay.scan_file('some_c_code.c').html
def scan_file filename, lang = :auto, options = {}, &block
- lang = FileType.fetch filename, :text, true if lang == :auto
+ lang = CodeRay::FileType.fetch filename, :text, true if lang == :auto
code = File.read filename
scan code, lang, options, &block
end
@@ -258,7 +258,7 @@ module CodeRay
# ]
# #-> 2 out of 4 tokens have the kind :integer.
def encoder format, options = {}
- Encoders[format].new options
+ CodeRay::Encoders[format].new options
end
# Finds the Scanner class for +lang+ and creates an instance, passing
@@ -266,7 +266,7 @@ module CodeRay
#
# See Scanner.new.
def scanner lang, options = {}, &block
- Scanners[lang].new '', options, &block
+ CodeRay::Scanners[lang].new '', options, &block
end
# Extract the options for the scanner from the +options+ hash.
diff --git a/lib/coderay/encoders.rb b/lib/coderay/encoders.rb
new file mode 100644
index 0000000..6599186
--- /dev/null
+++ b/lib/coderay/encoders.rb
@@ -0,0 +1,18 @@
+module CodeRay
+
+ # This module holds the Encoder class and its subclasses.
+ # For example, the HTML encoder is named CodeRay::Encoders::HTML
+ # can be found in coderay/encoders/html.
+ #
+ # Encoders also provides methods and constants for the register
+ # mechanism and the [] method that returns the Encoder class
+ # belonging to the given format.
+ module Encoders
+
+ extend PluginHost
+ plugin_path File.dirname(__FILE__), 'encoders'
+
+ autoload :Encoder, CodeRay.coderay_path('encoders', 'encoder')
+
+ end
+end
diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoders/encoder.rb
index d2d6c7e..fa5695d 100644
--- a/lib/coderay/encoder.rb
+++ b/lib/coderay/encoders/encoder.rb
@@ -1,17 +1,6 @@
module CodeRay
-
- # This module holds the Encoder class and its subclasses.
- # For example, the HTML encoder is named CodeRay::Encoders::HTML
- # can be found in coderay/encoders/html.
- #
- # Encoders also provides methods and constants for the register
- # mechanism and the [] method that returns the Encoder class
- # belonging to the given format.
module Encoders
- extend PluginHost
- plugin_path File.dirname(__FILE__), 'encoders'
-
# = Encoder
#
# The Encoder base class. Together with Scanner and
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb
index 9a724ff..4567943 100644
--- a/lib/coderay/helpers/plugin.rb
+++ b/lib/coderay/helpers/plugin.rb
@@ -1,224 +1,5 @@
module CodeRay
- # = PluginHost
- #
- # A simple subclass/subfolder plugin system.
- #
- # Example:
- # class Generators
- # extend PluginHost
- # plugin_path 'app/generators'
- # end
- #
- # class Generator
- # extend Plugin
- # PLUGIN_HOST = Generators
- # end
- #
- # class FancyGenerator < Generator
- # register_for :fancy
- # end
- #
- # Generators[:fancy] #-> FancyGenerator
- # # or
- # CodeRay.require_plugin 'Generators/fancy'
- # # or
- # Generators::Fancy
- module PluginHost
-
- # Raised if Encoders::[] fails because:
- # * a file could not be found
- # * the requested Plugin is not registered
- PluginNotFound = Class.new LoadError
- HostNotFound = Class.new LoadError
-
- PLUGIN_HOSTS = []
- PLUGIN_HOSTS_BY_ID = {} # dummy hash
-
- # Loads all plugins using list and load.
- def load_all
- for plugin in list
- load plugin
- end
- end
-
- # Returns the Plugin for +id+.
- #
- # Example:
- # yaml_plugin = MyPluginHost[:yaml]
- def [] id, *args, &blk
- plugin = validate_id(id)
- begin
- plugin = plugin_hash.[](plugin, *args, &blk)
- end while plugin.is_a? String
- plugin
- end
-
- alias load []
-
- # Tries to +load+ the missing plugin by translating +const+ to the
- # underscore form (eg. LinesOfCode becomes lines_of_code).
- def const_missing const
- id = const.to_s.
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
- downcase
- load id
- end
-
- class << self
-
- # Adds the module/class to the PLUGIN_HOSTS list.
- def extended mod
- PLUGIN_HOSTS << mod
- end
-
- end
-
- # The path where the plugins can be found.
- def plugin_path *args
- unless args.empty?
- @plugin_path = File.expand_path File.join(*args)
- end
- @plugin_path ||= ''
- end
-
- # Map a plugin_id to another.
- #
- # Usage: Put this in a file plugin_path/_map.rb.
- #
- # class MyColorHost < PluginHost
- # map :navy => :dark_blue,
- # :maroon => :brown,
- # :luna => :moon
- # end
- def map hash
- for from, to in hash
- from = validate_id from
- to = validate_id to
- plugin_hash[from] = to unless plugin_hash.has_key? from
- end
- end
-
- # Define the default plugin to use when no plugin is found
- # for a given id, or return the default plugin.
- #
- # See also map.
- #
- # class MyColorHost < PluginHost
- # map :navy => :dark_blue
- # default :gray
- # end
- #
- # MyColorHost.default # loads and returns the Gray plugin
- def default id = nil
- if id
- id = validate_id id
- raise "The default plugin can't be named \"default\"." if id == :default
- plugin_hash[:default] = id
- else
- load :default
- end
- end
-
- # Every plugin must register itself for +id+ by calling register_for,
- # which calls this method.
- #
- # See Plugin#register_for.
- def register plugin, id
- plugin_hash[validate_id(id)] = plugin
- end
-
- # A Hash of plugion_id => Plugin pairs.
- def plugin_hash
- @plugin_hash ||= (@plugin_hash = make_plugin_hash).tap { load_plugin_map }
- end
-
- # Returns an array of all .rb files in the plugin path.
- #
- # The extension .rb is not included.
- def list
- Dir[path_to('*')].select do |file|
- File.basename(file)[/^(?!_)\w+\.rb$/]
- end.map do |file|
- File.basename(file, '.rb').to_sym
- end
- end
-
- # Returns an array of all Plugins.
- #
- # Note: This loads all plugins using load_all.
- def all_plugins
- load_all
- plugin_hash.values.grep(Class)
- end
-
- # Loads the map file (see map).
- #
- # This is done automatically when plugin_path is called.
- def load_plugin_map
- mapfile = path_to '_map'
- if File.exist? mapfile
- require mapfile
- true
- else
- false
- end
- end
-
- protected
-
- # Return a plugin hash that automatically loads plugins.
- def make_plugin_hash
- Hash.new do |h, plugin_id|
- id = validate_id(plugin_id)
- path = path_to id
- begin
- require path
- rescue LoadError => boom
- if h.has_key?(:default)
- h[:default]
- else
- raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]
- end
- else
- # Plugin should have registered by now
- if h.has_key? id
- h[id]
- else
- raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}."
- end
- end
- end
- end
-
- # Returns the expected path to the plugin file for the given id.
- def path_to plugin_id
- File.join plugin_path, "#{plugin_id}.rb"
- end
-
- # Converts +id+ to a valid plugin ID String, or returns +nil+.
- #
- # Raises +ArgumentError+ for all other objects, or if the
- # given String includes non-alphanumeric characters (\W).
- def validate_id id
- case id
- when Symbol
- id.to_s
- when String
- if id[/\w+/] == id
- id.downcase
- else
- raise ArgumentError, "Invalid id given: #{id}"
- end
- else
- raise ArgumentError, "Symbol or String expected, but #{id.class} given."
- end
- end
-
- end
-
-
# = Plugin
#
# Plugins have to include this module.
diff --git a/lib/coderay/helpers/plugin_host.rb b/lib/coderay/helpers/plugin_host.rb
new file mode 100644
index 0000000..e9bc17c
--- /dev/null
+++ b/lib/coderay/helpers/plugin_host.rb
@@ -0,0 +1,221 @@
+module CodeRay
+
+ # = PluginHost
+ #
+ # A simple subclass/subfolder plugin system.
+ #
+ # Example:
+ # class Generators
+ # extend PluginHost
+ # plugin_path 'app/generators'
+ # end
+ #
+ # class Generator
+ # extend Plugin
+ # PLUGIN_HOST = Generators
+ # end
+ #
+ # class FancyGenerator < Generator
+ # register_for :fancy
+ # end
+ #
+ # Generators[:fancy] #-> FancyGenerator
+ # # or
+ # CodeRay.require_plugin 'Generators/fancy'
+ # # or
+ # Generators::Fancy
+ module PluginHost
+
+ # Raised if Encoders::[] fails because:
+ # * a file could not be found
+ # * the requested Plugin is not registered
+ PluginNotFound = Class.new LoadError
+ HostNotFound = Class.new LoadError
+
+ PLUGIN_HOSTS = []
+ PLUGIN_HOSTS_BY_ID = {} # dummy hash
+
+ # Loads all plugins using list and load.
+ def load_all
+ for plugin in list
+ load plugin
+ end
+ end
+
+ # Returns the Plugin for +id+.
+ #
+ # Example:
+ # yaml_plugin = MyPluginHost[:yaml]
+ def [] id, *args, &blk
+ plugin = validate_id(id)
+ begin
+ plugin = plugin_hash.[](plugin, *args, &blk)
+ end while plugin.is_a? String
+ plugin
+ end
+
+ alias load []
+
+ # Tries to +load+ the missing plugin by translating +const+ to the
+ # underscore form (eg. LinesOfCode becomes lines_of_code).
+ def const_missing const
+ id = const.to_s.
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ downcase
+ load id
+ end
+
+ class << self
+
+ # Adds the module/class to the PLUGIN_HOSTS list.
+ def extended mod
+ PLUGIN_HOSTS << mod
+ end
+
+ end
+
+ # The path where the plugins can be found.
+ def plugin_path *args
+ unless args.empty?
+ @plugin_path = File.expand_path File.join(*args)
+ end
+ @plugin_path ||= ''
+ end
+
+ # Map a plugin_id to another.
+ #
+ # Usage: Put this in a file plugin_path/_map.rb.
+ #
+ # class MyColorHost < PluginHost
+ # map :navy => :dark_blue,
+ # :maroon => :brown,
+ # :luna => :moon
+ # end
+ def map hash
+ for from, to in hash
+ from = validate_id from
+ to = validate_id to
+ plugin_hash[from] = to unless plugin_hash.has_key? from
+ end
+ end
+
+ # Define the default plugin to use when no plugin is found
+ # for a given id, or return the default plugin.
+ #
+ # See also map.
+ #
+ # class MyColorHost < PluginHost
+ # map :navy => :dark_blue
+ # default :gray
+ # end
+ #
+ # MyColorHost.default # loads and returns the Gray plugin
+ def default id = nil
+ if id
+ id = validate_id id
+ raise "The default plugin can't be named \"default\"." if id == :default
+ plugin_hash[:default] = id
+ else
+ load :default
+ end
+ end
+
+ # Every plugin must register itself for +id+ by calling register_for,
+ # which calls this method.
+ #
+ # See Plugin#register_for.
+ def register plugin, id
+ plugin_hash[validate_id(id)] = plugin
+ end
+
+ # A Hash of plugion_id => Plugin pairs.
+ def plugin_hash
+ @plugin_hash ||= (@plugin_hash = make_plugin_hash).tap { load_plugin_map }
+ end
+
+ # Returns an array of all .rb files in the plugin path.
+ #
+ # The extension .rb is not included.
+ def list
+ Dir[path_to('*')].select do |file|
+ File.basename(file)[/^(?!_)\w+\.rb$/]
+ end.map do |file|
+ File.basename(file, '.rb').to_sym
+ end
+ end
+
+ # Returns an array of all Plugins.
+ #
+ # Note: This loads all plugins using load_all.
+ def all_plugins
+ load_all
+ plugin_hash.values.grep(Class)
+ end
+
+ # Loads the map file (see map).
+ #
+ # This is done automatically when plugin_path is called.
+ def load_plugin_map
+ mapfile = path_to '_map'
+ if File.exist? mapfile
+ require mapfile
+ true
+ else
+ false
+ end
+ end
+
+ protected
+
+ # Return a plugin hash that automatically loads plugins.
+ def make_plugin_hash
+ Hash.new do |h, plugin_id|
+ id = validate_id(plugin_id)
+ path = path_to id
+ begin
+ require path
+ rescue LoadError => boom
+ if h.has_key?(:default)
+ h[:default]
+ else
+ raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom]
+ end
+ else
+ # Plugin should have registered by now
+ if h.has_key? id
+ h[id]
+ else
+ raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}."
+ end
+ end
+ end
+ end
+
+ # Returns the expected path to the plugin file for the given id.
+ def path_to plugin_id
+ File.join plugin_path, "#{plugin_id}.rb"
+ end
+
+ # Converts +id+ to a valid plugin ID String, or returns +nil+.
+ #
+ # Raises +ArgumentError+ for all other objects, or if the
+ # given String includes non-alphanumeric characters (\W).
+ def validate_id id
+ case id
+ when Symbol
+ id.to_s
+ when String
+ if id[/\w+/] == id
+ id.downcase
+ else
+ raise ArgumentError, "Invalid id given: #{id}"
+ end
+ else
+ raise ArgumentError, "Symbol or String expected, but #{id.class} given."
+ end
+ end
+
+ end
+
+end
diff --git a/lib/coderay/scanners.rb b/lib/coderay/scanners.rb
new file mode 100644
index 0000000..3c7e594
--- /dev/null
+++ b/lib/coderay/scanners.rb
@@ -0,0 +1,27 @@
+require 'strscan'
+
+module CodeRay
+
+ autoload :WordList, coderay_path('helpers', 'word_list')
+
+ # = Scanners
+ #
+ # This module holds the Scanner class and its subclasses.
+ # For example, the Ruby scanner is named CodeRay::Scanners::Ruby
+ # can be found in coderay/scanners/ruby.
+ #
+ # Scanner also provides methods and constants for the register
+ # mechanism and the [] method that returns the Scanner class
+ # belonging to the given lang.
+ #
+ # See PluginHost.
+ module Scanners
+
+ extend PluginHost
+ plugin_path File.dirname(__FILE__), 'scanners'
+
+ autoload :Scanner, CodeRay.coderay_path('scanners', 'scanner')
+
+ end
+
+end
diff --git a/lib/coderay/scanners/cpp.rb b/lib/coderay/scanners/cpp.rb
index e61f56f..40aeb42 100644
--- a/lib/coderay/scanners/cpp.rb
+++ b/lib/coderay/scanners/cpp.rb
@@ -2,14 +2,14 @@ module CodeRay
module Scanners
# Scanner for C++.
- #
+ #
# Aliases: +cplusplus+, c++
class CPlusPlus < Scanner
register_for :cpp
file_extension 'cpp'
title 'C++'
-
+
#-- http://www.cppreference.com/wiki/keywords/start
KEYWORDS = [
'and', 'and_eq', 'asm', 'bitand', 'bitor', 'break',
@@ -17,28 +17,30 @@ module Scanners
'continue', 'default', 'delete', 'do', 'dynamic_cast', 'else',
'enum', 'export', 'for', 'goto', 'if', 'namespace', 'new',
'not', 'not_eq', 'or', 'or_eq', 'reinterpret_cast', 'return',
- 'sizeof', 'static_cast', 'struct', 'switch', 'template',
- 'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
+ 'sizeof', 'static_assert', 'static_cast', 'struct', 'switch',
+ 'template', 'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
'while', 'xor', 'xor_eq',
] # :nodoc:
-
+
PREDEFINED_TYPES = [
- 'bool', 'char', 'double', 'float', 'int', 'long',
- 'short', 'signed', 'unsigned', 'wchar_t', 'string',
+ 'bool', 'char', 'char16_t', 'char32_t', 'double', 'float',
+ 'int', 'long', 'short', 'signed', 'unsigned',
+ 'wchar_t', 'string',
] # :nodoc:
PREDEFINED_CONSTANTS = [
'false', 'true',
- 'EOF', 'NULL',
+ 'EOF', 'NULL', 'nullptr'
] # :nodoc:
PREDEFINED_VARIABLES = [
'this',
] # :nodoc:
DIRECTIVES = [
- 'auto', 'const', 'explicit', 'extern', 'friend', 'inline', 'mutable', 'operator',
- 'private', 'protected', 'public', 'register', 'static', 'using', 'virtual', 'void',
- 'volatile',
+ 'alignas', 'alignof', 'auto', 'const', 'constexpr', 'decltype', 'explicit',
+ 'extern', 'final', 'friend', 'inline', 'mutable', 'noexcept', 'operator',
+ 'override', 'private', 'protected', 'public', 'register', 'static',
+ 'thread_local', 'using', 'virtual', 'void', 'volatile',
] # :nodoc:
-
+
IDENT_KIND = WordList.new(:ident).
add(KEYWORDS, :keyword).
add(PREDEFINED_TYPES, :predefined_type).
@@ -48,9 +50,9 @@ module Scanners
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
-
+
protected
-
+
def scan_tokens encoder, options
state = :initial
@@ -107,7 +109,7 @@ module Scanners
elsif match = scan(/\$/)
encoder.text_token match, :ident
-
+
elsif match = scan(/L?"/)
encoder.begin_group :string
if match[0] == ?L
@@ -180,7 +182,7 @@ module Scanners
state = :initial
end
-
+
when :class_name_expected
if match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
encoder.text_token match, :class
@@ -194,7 +196,7 @@ module Scanners
state = :initial
end
-
+
else
raise_inspect 'Unknown state', encoder
diff --git a/lib/coderay/scanners/java.rb b/lib/coderay/scanners/java.rb
index b282864..962154e 100644
--- a/lib/coderay/scanners/java.rb
+++ b/lib/coderay/scanners/java.rb
@@ -36,7 +36,7 @@ module Scanners
add(BuiltinTypes::List, :predefined_type).
add(BuiltinTypes::List.select { |builtin| builtin[/(Error|Exception)$/] }, :exception).
add(DIRECTIVES, :directive) # :nodoc:
-
+
ESCAPE = / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
STRING_CONTENT_PATTERN = {
diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanners/scanner.rb
index b3f7e17..efa710d 100644
--- a/lib/coderay/scanner.rb
+++ b/lib/coderay/scanners/scanner.rb
@@ -1,25 +1,7 @@
# encoding: utf-8
-require 'strscan'
module CodeRay
-
- autoload :WordList, coderay_path('helpers', 'word_list')
-
- # = Scanners
- #
- # This module holds the Scanner class and its subclasses.
- # For example, the Ruby scanner is named CodeRay::Scanners::Ruby
- # can be found in coderay/scanners/ruby.
- #
- # Scanner also provides methods and constants for the register
- # mechanism and the [] method that returns the Scanner class
- # belonging to the given lang.
- #
- # See PluginHost.
module Scanners
- extend PluginHost
- plugin_path File.dirname(__FILE__), 'scanners'
-
# = Scanner
#
diff --git a/lib/coderay/styles.rb b/lib/coderay/styles.rb
new file mode 100644
index 0000000..d8fa8aa
--- /dev/null
+++ b/lib/coderay/styles.rb
@@ -0,0 +1,15 @@
+module CodeRay
+
+ # This module holds the Style class and its subclasses.
+ #
+ # See Plugin.
+ module Styles
+
+ extend PluginHost
+ plugin_path File.dirname(__FILE__), 'styles'
+
+ autoload :Style, CodeRay.coderay_path('styles', 'style')
+
+ end
+
+end
diff --git a/lib/coderay/style.rb b/lib/coderay/styles/style.rb
index df4704f..a335386 100644
--- a/lib/coderay/style.rb
+++ b/lib/coderay/styles/style.rb
@@ -1,11 +1,6 @@
module CodeRay
-
- # This module holds the Style class and its subclasses.
- #
- # See Plugin.
+
module Styles
- extend PluginHost
- plugin_path File.dirname(__FILE__), 'styles'
# Base class for styles.
#