lib/rouge/lexers/cpp.rb in rouge-0.2.6 vs lib/rouge/lexers/cpp.rb in rouge-0.2.7
- old
+ new
@@ -10,30 +10,41 @@
'*.c++', '*.h++',
'*.cc', '*.hh',
'*.cxx', '*.hxx'
mimetypes 'text/x-c++hdr', 'text/x-c++src'
- keywords = %w(
- asm auto break case catch const const_cast continue
- default delete do dynamic_cast else enum explicit export
- extern for friend goto if mutable namespace new operator
- private protected public register reinterpret_cast return
- restrict sizeof static static_cast struct switch template
- this throw throws try typedef typeid typename union using
- volatile virtual while
- )
+ def self.keywords
+ @keywords ||= Set.new %w(
+ asm auto break case catch const const_cast continue
+ default delete do dynamic_cast else enum explicit export
+ extern for friend goto if mutable namespace new operator
+ private protected public register reinterpret_cast return
+ restrict sizeof static static_cast struct switch template
+ this throw throws try typedef typeid typename union using
+ volatile virtual while
+ )
+ end
- keywords_type = %w(
- bool int long float short double char unsigned signed void wchar_t
- )
+ def self.keywords_type
+ @keywords_type ||= Set.new %w(
+ bool int long float short double char unsigned signed void wchar_t
+ )
+ end
- __reserved = %w(
- asm int8 based except int16 stdcall cdecl fastcall int32 declspec
- finally int64 try leave wchar_t w64 virtual_inheritance uuidof
- unaligned super single_inheritance raise noop multiple_inheritance
- m128i m128d m128 m64 interface identifier forceinline event assume
- )
+ def self.reserved
+ @reserved ||= Set.new %w(
+ __asm __int8 __based __except __int16 __stdcall __cdecl
+ __fastcall __int32 __declspec __finally __int64 __try
+ __leave __wchar_t __w64 __virtual_inheritance __uuidof
+ __unaligned __super __single_inheritance __raise __noop
+ __multiple_inheritance __m128i __m128d __m128 __m64 __interface
+ __identifier __forceinline __event __assume
+ inline _inline __inline
+ naked _naked __naked
+ thread _thread __thread
+ )
+ end
# optional comments or whitespace
ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
id = /[a-zA-Z_][a-zA-Z0-9]*/
@@ -59,21 +70,30 @@
rule /\d+[lu]*/i, 'Literal.Number.Integer'
rule %r(\*/), 'Error'
rule %r([~!%^&*+=\|?:<>/-]), 'Operator'
rule /[()\[\],.;{}]/, 'Punctuation'
- rule /(?:#{keywords.join('|')})\b/, 'Keyword'
rule /class\b/, 'Keyword', :classname
- rule /(?:#{keywords_type.join('|')})\b/, 'Keyword.Type'
- rule /(?:_{0,2}inline|naked|thread)\b/, 'Keyword.Reserved'
- rule /__(?:#{__reserved.join('|')})\b/, 'Keyoword.Reserved'
+
# Offload C++ extensions, http://offload.codeplay.com/
rule /(?:__offload|__blockingoffload|__outer)\b/, 'Keyword.Pseudo'
rule /(true|false)\b/, 'Keyword.Constant'
rule /NULL\b/, 'Name.Builtin'
rule /#{id}:(?!:)/, 'Name.Label'
- rule id, 'Name'
+ rule id do |m|
+ name = m[0]
+
+ if self.class.keywords.include? name
+ token 'Keyword'
+ elsif self.class.keywords_type.include? name
+ token 'Keyword.Type'
+ elsif self.class.reserved.include? name
+ token 'Keyword.Reserved'
+ else
+ token 'Name'
+ end
+ end
end
state :classname do
rule id, 'Name.Class', :pop!