Skip to content

Commit f06e0e3

Browse files
committed
Add C++11 keywords
* lib/coderay/scanners/cpp.rb:
1 parent 0abcb3d commit f06e0e3

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/coderay/scanners/cpp.rb

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ module CodeRay
22
module Scanners
33

44
# Scanner for C++.
5-
#
5+
#
66
# Aliases: +cplusplus+, c++
77
class CPlusPlus < Scanner
88

99
register_for :cpp
1010
file_extension 'cpp'
1111
title 'C++'
12-
12+
1313
#-- http://www.cppreference.com/wiki/keywords/start
1414
KEYWORDS = [
1515
'and', 'and_eq', 'asm', 'bitand', 'bitor', 'break',
1616
'case', 'catch', 'class', 'compl', 'const_cast',
1717
'continue', 'default', 'delete', 'do', 'dynamic_cast', 'else',
1818
'enum', 'export', 'for', 'goto', 'if', 'namespace', 'new',
1919
'not', 'not_eq', 'or', 'or_eq', 'reinterpret_cast', 'return',
20-
'sizeof', 'static_cast', 'struct', 'switch', 'template',
21-
'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
20+
'sizeof', 'static_assert', 'static_cast', 'struct', 'switch',
21+
'template', 'throw', 'try', 'typedef', 'typeid', 'typename', 'union',
2222
'while', 'xor', 'xor_eq',
2323
] # :nodoc:
24-
24+
2525
PREDEFINED_TYPES = [
26-
'bool', 'char', 'double', 'float', 'int', 'long',
27-
'short', 'signed', 'unsigned', 'wchar_t', 'string',
26+
'bool', 'char', 'char16_t', 'char32_t', 'double', 'float',
27+
'int', 'long', 'nullptr' 'short', 'signed', 'unsigned',
28+
'wchar_t', 'string',
2829
] # :nodoc:
2930
PREDEFINED_CONSTANTS = [
3031
'false', 'true',
@@ -34,11 +35,12 @@ class CPlusPlus < Scanner
3435
'this',
3536
] # :nodoc:
3637
DIRECTIVES = [
37-
'auto', 'const', 'explicit', 'extern', 'friend', 'inline', 'mutable', 'operator',
38-
'private', 'protected', 'public', 'register', 'static', 'using', 'virtual', 'void',
39-
'volatile',
38+
'alignas', 'alignof', 'auto', 'const', 'constexpr', 'decltype', 'explicit',
39+
'extern', 'final', 'friend', 'inline', 'mutable', 'noexcept', 'operator',
40+
'override', 'private', 'protected', 'public', 'register', 'static',
41+
'thread_local', 'using', 'virtual', 'void', 'volatile',
4042
] # :nodoc:
41-
43+
4244
IDENT_KIND = WordList.new(:ident).
4345
add(KEYWORDS, :keyword).
4446
add(PREDEFINED_TYPES, :predefined_type).
@@ -48,9 +50,9 @@ class CPlusPlus < Scanner
4850

4951
ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
5052
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x # :nodoc:
51-
53+
5254
protected
53-
55+
5456
def scan_tokens encoder, options
5557

5658
state = :initial
@@ -107,7 +109,7 @@ def scan_tokens encoder, options
107109

108110
elsif match = scan(/\$/)
109111
encoder.text_token match, :ident
110-
112+
111113
elsif match = scan(/L?"/)
112114
encoder.begin_group :string
113115
if match[0] == ?L
@@ -180,7 +182,7 @@ def scan_tokens encoder, options
180182
state = :initial
181183

182184
end
183-
185+
184186
when :class_name_expected
185187
if match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
186188
encoder.text_token match, :class
@@ -194,7 +196,7 @@ def scan_tokens encoder, options
194196
state = :initial
195197

196198
end
197-
199+
198200
else
199201
raise_inspect 'Unknown state', encoder
200202

0 commit comments

Comments
 (0)