diff --git a/CHANGES.md b/CHANGES.md index 08c0a5a19a..2dd028f9c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -96,6 +96,9 @@ Grammars: - enh(haskell) add support for HexFloatLiterals (#3150) [Martijn Bastiaan][] - fix(c,cpp) allow declaring multiple functions and (for C++) parenthetical initializers (#3155) [Erik Demaine][] - enh(rust) highlight raw byte string literals correctly (#3173) [Nico Abram][] +- fix(cpp) fix detection of common functions that are function templates (#3178) [Kris van Rens][] +- enh(cpp) add various keywords and commonly used types for hinting (#3178) [Kris van Rens][] +- enh(cpp) cleanup reserved keywords and type lists (#3178) [Kris van Rens][] New Languages: @@ -139,6 +142,7 @@ Dev Improvements: [Nico Abram]: https://github.com/nico-abram [James Edington]: http://www.ishygddt.xyz/ [Jan Pilzer]: https://github.com/Hirse +[Kris van Rens]: https://github.com/krisvanrens ## Version 10.7.1 diff --git a/src/languages/arduino.js b/src/languages/arduino.js index 872991ab09..1c09b1bbc2 100644 --- a/src/languages/arduino.js +++ b/src/languages/arduino.js @@ -10,100 +10,380 @@ import cPlusPlus from './cpp.js'; /** @type LanguageFn */ export default function(hljs) { const ARDUINO_KW = { - keyword: - 'boolean byte word String', - built_in: - 'KeyboardController MouseController SoftwareSerial ' + - 'EthernetServer EthernetClient LiquidCrystal ' + - 'RobotControl GSMVoiceCall EthernetUDP EsploraTFT ' + - 'HttpClient RobotMotor WiFiClient GSMScanner ' + - 'FileSystem Scheduler GSMServer YunClient YunServer ' + - 'IPAddress GSMClient GSMModem Keyboard Ethernet ' + - 'Console GSMBand Esplora Stepper Process ' + - 'WiFiUDP GSM_SMS Mailbox USBHost Firmata PImage ' + - 'Client Server GSMPIN FileIO Bridge Serial ' + - 'EEPROM Stream Mouse Audio Servo File Task ' + - 'GPRS WiFi Wire TFT GSM SPI SD ', - _: - 'setup loop ' + - 'runShellCommandAsynchronously analogWriteResolution ' + - 'retrieveCallingNumber printFirmwareVersion ' + - 'analogReadResolution sendDigitalPortPair ' + - 'noListenOnLocalhost readJoystickButton setFirmwareVersion ' + - 'readJoystickSwitch scrollDisplayRight getVoiceCallStatus ' + - 'scrollDisplayLeft writeMicroseconds delayMicroseconds ' + - 'beginTransmission getSignalStrength runAsynchronously ' + - 'getAsynchronously listenOnLocalhost getCurrentCarrier ' + - 'readAccelerometer messageAvailable sendDigitalPorts ' + - 'lineFollowConfig countryNameWrite runShellCommand ' + - 'readStringUntil rewindDirectory readTemperature ' + - 'setClockDivider readLightSensor endTransmission ' + - 'analogReference detachInterrupt countryNameRead ' + - 'attachInterrupt encryptionType readBytesUntil ' + - 'robotNameWrite readMicrophone robotNameRead cityNameWrite ' + - 'userNameWrite readJoystickY readJoystickX mouseReleased ' + - 'openNextFile scanNetworks noInterrupts digitalWrite ' + - 'beginSpeaker mousePressed isActionDone mouseDragged ' + - 'displayLogos noAutoscroll addParameter remoteNumber ' + - 'getModifiers keyboardRead userNameRead waitContinue ' + - 'processInput parseCommand printVersion readNetworks ' + - 'writeMessage blinkVersion cityNameRead readMessage ' + - 'setDataMode parsePacket isListening setBitOrder ' + - 'beginPacket isDirectory motorsWrite drawCompass ' + - 'digitalRead clearScreen serialEvent rightToLeft ' + - 'setTextSize leftToRight requestFrom keyReleased ' + - 'compassRead analogWrite interrupts WiFiServer ' + - 'disconnect playMelody parseFloat autoscroll ' + - 'getPINUsed setPINUsed setTimeout sendAnalog ' + - 'readSlider analogRead beginWrite createChar ' + - 'motorsStop keyPressed tempoWrite readButton ' + - 'subnetMask debugPrint macAddress writeGreen ' + - 'randomSeed attachGPRS readString sendString ' + - 'remotePort releaseAll mouseMoved background ' + - 'getXChange getYChange answerCall getResult ' + - 'voiceCall endPacket constrain getSocket writeJSON ' + - 'getButton available connected findUntil readBytes ' + - 'exitValue readGreen writeBlue startLoop IPAddress ' + - 'isPressed sendSysex pauseMode gatewayIP setCursor ' + - 'getOemKey tuneWrite noDisplay loadImage switchPIN ' + - 'onRequest onReceive changePIN playFile noBuffer ' + - 'parseInt overflow checkPIN knobRead beginTFT ' + - 'bitClear updateIR bitWrite position writeRGB ' + - 'highByte writeRed setSpeed readBlue noStroke ' + - 'remoteIP transfer shutdown hangCall beginSMS ' + - 'endWrite attached maintain noCursor checkReg ' + - 'checkPUK shiftOut isValid shiftIn pulseIn ' + - 'connect println localIP pinMode getIMEI ' + - 'display noBlink process getBand running beginSD ' + - 'drawBMP lowByte setBand release bitRead prepare ' + - 'pointTo readRed setMode noFill remove listen ' + - 'stroke detach attach noTone exists buffer ' + - 'height bitSet circle config cursor random ' + - 'IRread setDNS endSMS getKey micros ' + - 'millis begin print write ready flush width ' + - 'isPIN blink clear press mkdir rmdir close ' + - 'point yield image BSSID click delay ' + - 'read text move peek beep rect line open ' + - 'seek fill size turn stop home find ' + - 'step tone sqrt RSSI SSID ' + - 'end bit tan cos sin pow map abs max ' + - 'min get run put', - literal: - 'DIGITAL_MESSAGE FIRMATA_STRING ANALOG_MESSAGE ' + - 'REPORT_DIGITAL REPORT_ANALOG INPUT_PULLUP ' + - 'SET_PIN_MODE INTERNAL2V56 SYSTEM_RESET LED_BUILTIN ' + - 'INTERNAL1V1 SYSEX_START INTERNAL EXTERNAL ' + - 'DEFAULT OUTPUT INPUT HIGH LOW' + type: [ + "boolean", + "byte", + "word", + "String" + ], + built_in: [ + "KeyboardController", + "MouseController", + "SoftwareSerial", + "EthernetServer", + "EthernetClient", + "LiquidCrystal", + "RobotControl", + "GSMVoiceCall", + "EthernetUDP", + "EsploraTFT", + "HttpClient", + "RobotMotor", + "WiFiClient", + "GSMScanner", + "FileSystem", + "Scheduler", + "GSMServer", + "YunClient", + "YunServer", + "IPAddress", + "GSMClient", + "GSMModem", + "Keyboard", + "Ethernet", + "Console", + "GSMBand", + "Esplora", + "Stepper", + "Process", + "WiFiUDP", + "GSM_SMS", + "Mailbox", + "USBHost", + "Firmata", + "PImage", + "Client", + "Server", + "GSMPIN", + "FileIO", + "Bridge", + "Serial", + "EEPROM", + "Stream", + "Mouse", + "Audio", + "Servo", + "File", + "Task", + "GPRS", + "WiFi", + "Wire", + "TFT", + "GSM", + "SPI", + "SD" + ], + _hints: [ + "setup", + "loop", + "runShellCommandAsynchronously", + "analogWriteResolution", + "retrieveCallingNumber", + "printFirmwareVersion", + "analogReadResolution", + "sendDigitalPortPair", + "noListenOnLocalhost", + "readJoystickButton", + "setFirmwareVersion", + "readJoystickSwitch", + "scrollDisplayRight", + "getVoiceCallStatus", + "scrollDisplayLeft", + "writeMicroseconds", + "delayMicroseconds", + "beginTransmission", + "getSignalStrength", + "runAsynchronously", + "getAsynchronously", + "listenOnLocalhost", + "getCurrentCarrier", + "readAccelerometer", + "messageAvailable", + "sendDigitalPorts", + "lineFollowConfig", + "countryNameWrite", + "runShellCommand", + "readStringUntil", + "rewindDirectory", + "readTemperature", + "setClockDivider", + "readLightSensor", + "endTransmission", + "analogReference", + "detachInterrupt", + "countryNameRead", + "attachInterrupt", + "encryptionType", + "readBytesUntil", + "robotNameWrite", + "readMicrophone", + "robotNameRead", + "cityNameWrite", + "userNameWrite", + "readJoystickY", + "readJoystickX", + "mouseReleased", + "openNextFile", + "scanNetworks", + "noInterrupts", + "digitalWrite", + "beginSpeaker", + "mousePressed", + "isActionDone", + "mouseDragged", + "displayLogos", + "noAutoscroll", + "addParameter", + "remoteNumber", + "getModifiers", + "keyboardRead", + "userNameRead", + "waitContinue", + "processInput", + "parseCommand", + "printVersion", + "readNetworks", + "writeMessage", + "blinkVersion", + "cityNameRead", + "readMessage", + "setDataMode", + "parsePacket", + "isListening", + "setBitOrder", + "beginPacket", + "isDirectory", + "motorsWrite", + "drawCompass", + "digitalRead", + "clearScreen", + "serialEvent", + "rightToLeft", + "setTextSize", + "leftToRight", + "requestFrom", + "keyReleased", + "compassRead", + "analogWrite", + "interrupts", + "WiFiServer", + "disconnect", + "playMelody", + "parseFloat", + "autoscroll", + "getPINUsed", + "setPINUsed", + "setTimeout", + "sendAnalog", + "readSlider", + "analogRead", + "beginWrite", + "createChar", + "motorsStop", + "keyPressed", + "tempoWrite", + "readButton", + "subnetMask", + "debugPrint", + "macAddress", + "writeGreen", + "randomSeed", + "attachGPRS", + "readString", + "sendString", + "remotePort", + "releaseAll", + "mouseMoved", + "background", + "getXChange", + "getYChange", + "answerCall", + "getResult", + "voiceCall", + "endPacket", + "constrain", + "getSocket", + "writeJSON", + "getButton", + "available", + "connected", + "findUntil", + "readBytes", + "exitValue", + "readGreen", + "writeBlue", + "startLoop", + "IPAddress", + "isPressed", + "sendSysex", + "pauseMode", + "gatewayIP", + "setCursor", + "getOemKey", + "tuneWrite", + "noDisplay", + "loadImage", + "switchPIN", + "onRequest", + "onReceive", + "changePIN", + "playFile", + "noBuffer", + "parseInt", + "overflow", + "checkPIN", + "knobRead", + "beginTFT", + "bitClear", + "updateIR", + "bitWrite", + "position", + "writeRGB", + "highByte", + "writeRed", + "setSpeed", + "readBlue", + "noStroke", + "remoteIP", + "transfer", + "shutdown", + "hangCall", + "beginSMS", + "endWrite", + "attached", + "maintain", + "noCursor", + "checkReg", + "checkPUK", + "shiftOut", + "isValid", + "shiftIn", + "pulseIn", + "connect", + "println", + "localIP", + "pinMode", + "getIMEI", + "display", + "noBlink", + "process", + "getBand", + "running", + "beginSD", + "drawBMP", + "lowByte", + "setBand", + "release", + "bitRead", + "prepare", + "pointTo", + "readRed", + "setMode", + "noFill", + "remove", + "listen", + "stroke", + "detach", + "attach", + "noTone", + "exists", + "buffer", + "height", + "bitSet", + "circle", + "config", + "cursor", + "random", + "IRread", + "setDNS", + "endSMS", + "getKey", + "micros", + "millis", + "begin", + "print", + "write", + "ready", + "flush", + "width", + "isPIN", + "blink", + "clear", + "press", + "mkdir", + "rmdir", + "close", + "point", + "yield", + "image", + "BSSID", + "click", + "delay", + "read", + "text", + "move", + "peek", + "beep", + "rect", + "line", + "open", + "seek", + "fill", + "size", + "turn", + "stop", + "home", + "find", + "step", + "tone", + "sqrt", + "RSSI", + "SSID", + "end", + "bit", + "tan", + "cos", + "sin", + "pow", + "map", + "abs", + "max", + "min", + "get", + "run", + "put" + ], + literal: [ + "DIGITAL_MESSAGE", + "FIRMATA_STRING", + "ANALOG_MESSAGE", + "REPORT_DIGITAL", + "REPORT_ANALOG", + "INPUT_PULLUP", + "SET_PIN_MODE", + "INTERNAL2V56", + "SYSTEM_RESET", + "LED_BUILTIN", + "INTERNAL1V1", + "SYSEX_START", + "INTERNAL", + "EXTERNAL", + "DEFAULT", + "OUTPUT", + "INPUT", + "HIGH", + "LOW" + ] }; const ARDUINO = cPlusPlus(hljs); const kws = /** @type {Record} */ (ARDUINO.keywords); - kws.keyword += ' ' + ARDUINO_KW.keyword; - kws.literal += ' ' + ARDUINO_KW.literal; - kws.built_in += ' ' + ARDUINO_KW.built_in; - kws._ += ' ' + ARDUINO_KW._; + kws.type = [ ...kws.type, ...ARDUINO_KW.type ]; + kws.literal = [ ...kws.literal, ...ARDUINO_KW.literal ]; + kws.built_in = [ ...kws.built_in, ...ARDUINO_KW.built_in ]; + kws._hints = ARDUINO_KW._hints; ARDUINO.name = 'Arduino'; ARDUINO.aliases = ['ino']; diff --git a/src/languages/cpp.js b/src/languages/cpp.js index 3862004f2d..e0d10e6a50 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -26,8 +26,9 @@ export default function(hljs) { regex.optional(NAMESPACE_RE) + '[a-zA-Z_]\\w*' + regex.optional(TEMPLATE_ARGUMENT_RE) + ')'; + const CPP_PRIMITIVE_TYPES = { - className: 'keyword', + className: 'type', begin: '\\b[a-z\\d_]*_t\\b' }; @@ -44,7 +45,7 @@ export default function(hljs) { contains: [ hljs.BACKSLASH_ESCAPE ] }, { - begin: '(u8?|U|L)?\'(' + CHARACTER_ESCAPES + "|.)", + begin: '(u8?|U|L)?\'(' + CHARACTER_ESCAPES + '|.)', end: '\'', illegal: '.' }, @@ -105,38 +106,208 @@ export default function(hljs) { const FUNCTION_TITLE = regex.optional(NAMESPACE_RE) + hljs.IDENT_RE + '\\s*\\('; - const COMMON_CPP_HINTS = [ + // https://en.cppreference.com/w/cpp/keyword + const RESERVED_KEYWORDS = [ + 'alignas', + 'alignof', + 'and', + 'and_eq', + 'asm', + 'atomic_cancel', + 'atomic_commit', + 'atomic_noexcept', + 'auto', + 'bitand', + 'bitor', + 'break', + 'case', + 'catch', + 'class', + 'co_await', + 'co_return', + 'co_yield', + 'compl', + 'concept', + 'const', + 'const_cast|10', + 'consteval', + 'constexpr', + 'constinit', + 'continue', + 'decltype', + 'default', + 'delete', + 'do', + 'dynamic_cast|10', + 'else', + 'enum', + 'explicit', + 'export', + 'extern', + 'false', + 'final', + 'for', + 'friend', + 'goto', + 'if', + 'import', + 'inline', + 'module', + 'mutable', + 'namespace', + 'new', + 'noexcept', + 'not', + 'not_eq', + 'nullptr', + 'operator', + 'or', + 'or_eq', + 'override', + 'private', + 'protected', + 'public', + 'reflexpr', + 'register', + 'reinterpret_cast|10', + 'requires', + 'return', + 'signed', + 'sizeof', + 'static', + 'static_assert', + 'static_cast|10', + 'struct', + 'switch', + 'synchronized', + 'template', + 'this', + 'thread_local', + 'throw', + 'transaction_safe', + 'transaction_safe_dynamic', + 'true', + 'try', + 'typedef', + 'typeid', + 'typename', + 'union', + 'unsigned', + 'using', + 'virtual', + 'volatile', + 'while', + 'xor', + 'xor_eq,' + ]; + + // https://en.cppreference.com/w/cpp/keyword + const RESERVED_TYPES = [ + 'bool', + 'char', + 'char16_t', + 'char32_t', + 'char8_t', + 'double', + 'float', + 'int', + 'long', + 'short', + 'void', + 'wchar_t' + ]; + + const TYPE_HINTS = [ + 'any', + 'auto_ptr', + 'barrier', + 'binary_semaphore', + 'bitset', + 'complex', + 'condition_variable', + 'condition_variable_any', + 'counting_semaphore', + 'deque', + 'false_type', + 'future', + 'imaginary', + 'initializer_list', + 'istringstream', + 'jthread', + 'latch', + 'lock_guard', + 'multimap', + 'multiset', + 'mutex', + 'optional', + 'ostringstream', + 'packaged_task', + 'pair', + 'promise', + 'priority_queue', + 'queue', + 'recursive_mutex', + 'recursive_timed_mutex', + 'scoped_lock', + 'set', + 'shared_future', + 'shared_lock', + 'shared_mutex', + 'shared_timed_mutex', + 'shared_ptr', + 'stack', + 'string_view', + 'stringstream', + 'timed_mutex', + 'thread', + 'true_type', + 'tuple', + 'unique_lock', + 'unique_ptr', + 'unordered_map', + 'unordered_multimap', + 'unordered_multiset', + 'unordered_set', + 'variant', + 'vector', + 'weak_ptr', + 'wstring', + 'wstring_view' + ]; + + const FUNCTION_HINTS = [ + 'abort', + 'abs', + 'acos', + 'apply', + 'as_const', 'asin', - 'atan2', 'atan', + 'atan2', 'calloc', 'ceil', - 'cosh', + 'cerr', + 'cin', + 'clog', 'cos', + 'cosh', + 'cout', + 'declval', + 'endl', + 'exchange', 'exit', 'exp', 'fabs', 'floor', 'fmod', + 'forward', 'fprintf', 'fputs', 'free', 'frexp', - 'auto_ptr', - 'deque', - 'list', - 'queue', - 'stack', - 'vector', - 'map', - 'set', - 'pair', - 'bitset', - 'multiset', - 'multimap', - 'unordered_set', 'fscanf', 'future', + 'invoke', 'isalnum', 'isalpha', 'iscntrl', @@ -148,30 +319,39 @@ export default function(hljs) { 'isspace', 'isupper', 'isxdigit', - 'tolower', - 'toupper', 'labs', + 'launder', 'ldexp', - 'log10', 'log', + 'log10', + 'make_pair', + 'make_shared', + 'make_shared_for_overwrite', + 'make_tuple', + 'make_unique', 'malloc', - 'realloc', 'memchr', 'memcmp', 'memcpy', 'memset', 'modf', + 'move', 'pow', 'printf', 'putchar', 'puts', + 'realloc', 'scanf', - 'sinh', 'sin', + 'sinh', 'snprintf', 'sprintf', 'sqrt', 'sscanf', + 'std', + 'stderr', + 'stdin', + 'stdout', 'strcat', 'strchr', 'strcmp', @@ -185,64 +365,47 @@ export default function(hljs) { 'strrchr', 'strspn', 'strstr', - 'tanh', + 'swap', 'tan', - 'unordered_map', - 'unordered_multiset', - 'unordered_multimap', - 'priority_queue', - 'make_pair', - 'array', - 'shared_ptr', - 'abort', + 'tanh', 'terminate', - 'abs', - 'acos', + 'to_underlying', + 'tolower', + 'toupper', 'vfprintf', + 'visit', 'vprintf', - 'vsprintf', - 'endl', - 'initializer_list', - 'unique_ptr', - 'complex', - 'imaginary', - 'std', - 'string', - 'wstring', - 'cin', - 'cout', - 'cerr', - 'clog', - 'stdin', - 'stdout', - 'stderr', - 'stringstream', - 'istringstream', - 'ostringstream' + 'vsprintf' + ]; + + const LITERALS = [ + 'NULL', + 'false', + 'nullopt', + 'nullptr', + 'true' + ]; + + // https://en.cppreference.com/w/cpp/keyword + const BUILT_IN = [ + '_Pragma' ]; const CPP_KEYWORDS = { - keyword: 'int float while private char char8_t char16_t char32_t catch import module export virtual operator sizeof ' + - 'dynamic_cast|10 typedef const_cast|10 const for static_cast|10 union namespace ' + - 'unsigned long volatile static protected bool template mutable if public friend ' + - 'do goto auto void enum else break extern using asm case typeid wchar_t ' + - 'short reinterpret_cast|10 default double register explicit signed typename try this ' + - 'switch continue inline delete alignas alignof constexpr consteval constinit decltype ' + - 'concept co_await co_return co_yield requires ' + - 'noexcept static_assert thread_local restrict final override ' + - 'atomic_bool atomic_char atomic_schar ' + - 'atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong ' + - 'atomic_ullong new throw return ' + - 'and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq struct', - built_in: '_Bool _Complex _Imaginary', - _relevance_hints: COMMON_CPP_HINTS, - literal: 'true false nullptr NULL' + type: RESERVED_TYPES, + keyword: RESERVED_KEYWORDS, + literal: LITERALS, + built_in: BUILT_IN, + _type_hints: TYPE_HINTS }; const FUNCTION_DISPATCH = { - className: "function.dispatch", + className: 'function.dispatch', relevance: 0, - keywords: CPP_KEYWORDS, + keywords: { + // Only for relevance, not highlighting. + _hint: FUNCTION_HINTS + }, begin: regex.concat( /\b/, /(?!decltype)/, @@ -250,7 +413,7 @@ export default function(hljs) { /(?!for)/, /(?!while)/, hljs.IDENT_RE, - regex.lookahead(/\s*\(/)) + regex.lookahead(/(<[^<>]+>|)\s*\(/)) }; const EXPRESSION_CONTAINS = [ @@ -263,7 +426,6 @@ export default function(hljs) { STRINGS ]; - const EXPRESSION_CONTEXT = { // This mode covers expression context where we can't expect a function // definition and shouldn't highlight anything that looks like one: @@ -386,7 +548,7 @@ export default function(hljs) { keywords: CPP_KEYWORDS, illegal: ' rooms (9);` - begin: '\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<', + begin: '\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function)\\s*<', end: '>', keywords: CPP_KEYWORDS, contains: [ @@ -416,8 +578,8 @@ export default function(hljs) { /\w+/ ], className: { - 1: "keyword", - 3: "title.class" + 1: 'keyword', + 3: 'title.class' } } ]) diff --git a/test/detect/cpp/comment.txt b/test/detect/cpp/comment.txt deleted file mode 100644 index d4e02f35c3..0000000000 --- a/test/detect/cpp/comment.txt +++ /dev/null @@ -1,16 +0,0 @@ -/* -To use this program, compile it -- if you can -- and then type something like: - -chan -n 5000 -d 2 < input.txt - -In this case, it will produce 5000 words of output, checking two-word groups. -(The explanation above describes two-word generation. If you type "-d 3", -the program will find three-word groups, and so on. Greater depths make more -sense, but they require more input text and take more time to process.) - -http://www.eblong.com/zarf/markov/ -*/ - - -/* make cpp win deterministically over others with C block comments */ -cout << endl; diff --git a/test/markup/arduino/default.expect.txt b/test/markup/arduino/default.expect.txt index 1e6a196047..c15d85d651 100644 --- a/test/markup/arduino/default.expect.txt +++ b/test/markup/arduino/default.expect.txt @@ -7,19 +7,18 @@ // Pin 13 has an LED connected on most Arduino boards. // give it a name: -int led = 13; +int led = 13; // the setup routine runs once when you press reset: -void setup() { +void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: -void loop() { +void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } - diff --git a/test/markup/arduino/default.txt b/test/markup/arduino/default.txt index d9652dbf6f..e83815c605 100644 --- a/test/markup/arduino/default.txt +++ b/test/markup/arduino/default.txt @@ -22,4 +22,3 @@ void loop() { digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } - diff --git a/test/markup/cpp/expression-keywords.expect.txt b/test/markup/cpp/expression-keywords.expect.txt index 4fb7c52717..e3ca0f31af 100644 --- a/test/markup/cpp/expression-keywords.expect.txt +++ b/test/markup/cpp/expression-keywords.expect.txt @@ -1,2 +1,2 @@ -double x = exp(log(2)); // recognize built-ins +double x = exp(log(2)); // recognize built-ins return 0; // recognize keyword that started the expression diff --git a/test/markup/cpp/function-declarations.expect.txt b/test/markup/cpp/function-declarations.expect.txt index b04c01e87f..5279754667 100644 --- a/test/markup/cpp/function-declarations.expect.txt +++ b/test/markup/cpp/function-declarations.expect.txt @@ -1,12 +1,12 @@ decltype(auto) look_up_a_string_1() { return lookup1(); } -void look_up_a_string_2() { return lookup2(); } -friend void A::showB(B x) {} -friend void showB(B x) {} -friend void showB(B::SomeType x) {} -inline int add(int a, int b) {} +void look_up_a_string_2() { return lookup2(); } +friend void A::showB(B x) {} +friend void showB(B x) {} +friend void showB(B::SomeType x) {} +inline int add(int a, int b) {} int8t Get_Tile_Value() {} -int8_t Get_Tile_Value() {} +int8_t Get_Tile_Value() {} B::type test() {}; @@ -15,11 +15,11 @@ // pack expansion in function arguments template<typename T...> -void foo(T... args) {} +void foo(T... args) {} test(); -void A(): a(10) {} +void A(): a(10) {} explicit A(): a(10) {} -extern void f(int), g(char); +extern void f(int), g(char); diff --git a/test/markup/cpp/function-params.expect.txt b/test/markup/cpp/function-params.expect.txt index b974a634a7..d84aafe1ad 100644 --- a/test/markup/cpp/function-params.expect.txt +++ b/test/markup/cpp/function-params.expect.txt @@ -1,7 +1,7 @@ -int f( - int a = 1, - char* b = "2", // Line comment - double c = 3.0, /* Block comment */ - ARRAY(int, 5) d, - void* e __attribute__((unused)) +int f( + int a = 1, + char* b = "2", // Line comment + double c = 3.0, /* Block comment */ + ARRAY(int, 5) d, + void* e __attribute__((unused)) ); diff --git a/test/markup/cpp/function-title.expect.txt b/test/markup/cpp/function-title.expect.txt index e94c2295e9..ae36b17620 100644 --- a/test/markup/cpp/function-title.expect.txt +++ b/test/markup/cpp/function-title.expect.txt @@ -1,6 +1,7 @@ -int main() { - A a = new A(); - int b = b * sum(1, 2); +int main(int argc, char** argv) { + auto a = std::make_unique<A>(); + B *b = new B(); + int c = c * sum(1, 2); if (a->check1()) return 3; else if (a->check2()) diff --git a/test/markup/cpp/function-title.txt b/test/markup/cpp/function-title.txt index 74c810a6c7..e7de41d78d 100644 --- a/test/markup/cpp/function-title.txt +++ b/test/markup/cpp/function-title.txt @@ -1,6 +1,7 @@ -int main() { - A a = new A(); - int b = b * sum(1, 2); +int main(int argc, char** argv) { + auto a = std::make_unique(); + B *b = new B(); + int c = c * sum(1, 2); if (a->check1()) return 3; else if (a->check2()) diff --git a/test/markup/cpp/initializers.expect.txt b/test/markup/cpp/initializers.expect.txt index cefb410b93..7bbbec1f75 100644 --- a/test/markup/cpp/initializers.expect.txt +++ b/test/markup/cpp/initializers.expect.txt @@ -1,2 +1,2 @@ string a("hello"), b("world"); -vector<int> u(1), v(2); +vector<int> u(1), v(2); diff --git a/test/markup/cpp/number-literals.expect.txt b/test/markup/cpp/number-literals.expect.txt index 466fc96d59..ea9ef3fddd 100644 --- a/test/markup/cpp/number-literals.expect.txt +++ b/test/markup/cpp/number-literals.expect.txt @@ -1,9 +1,9 @@ /* digit separators */ -int number = 2'555'555'555; // digit separators -float exponentFloat = .123'456e3'000; // digit separators in floats -float suffixed = 3.000'001'234f // digit separators in suffixed numbers -char word[] = { '3', '\0' }; // make sure digit separators don't mess up chars -float negative = -123.0f; // negative floating point numbers +int number = 2'555'555'555; // digit separators +float exponentFloat = .123'456e3'000; // digit separators in floats +float suffixed = 3.000'001'234f // digit separators in suffixed numbers +char word[] = { '3', '\0' }; // make sure digit separators don't mess up chars +float negative = -123.0f; // negative floating point numbers /* literal suffixes: these are to be highlighted as numbers */ 90ll 90LL 90u 90U 90l 90L diff --git a/test/markup/cpp/pointers-returns.expect.txt b/test/markup/cpp/pointers-returns.expect.txt index a2333fe3b6..616530bacd 100644 --- a/test/markup/cpp/pointers-returns.expect.txt +++ b/test/markup/cpp/pointers-returns.expect.txt @@ -1,4 +1,4 @@ // These will all work: -char** foo_bar(); -char ** foo_bar(); -char **foo_bar(); +char** foo_bar(); +char ** foo_bar(); +char **foo_bar(); diff --git a/test/markup/cpp/preprocessor.expect.txt b/test/markup/cpp/preprocessor.expect.txt index 5f47f55b8c..4178795541 100644 --- a/test/markup/cpp/preprocessor.expect.txt +++ b/test/markup/cpp/preprocessor.expect.txt @@ -2,9 +2,9 @@ #define foo 1<<16 #ifdef DEBUG -TYPE1 foo(void) +TYPE1 foo(void) #else -int foo(void) +int foo(void) #endif { } @@ -15,7 +15,7 @@ #if MACRO_WITH_STRING_ARG("hello \"world\"") #elif MULTI_LINE /* comment */ < \ EXPRESSION -int bar; +int bar; #endif // comment if (p) { diff --git a/test/markup/cpp/primitive-types.expect.txt b/test/markup/cpp/primitive-types.expect.txt index cbe8d7a6cf..89ca29f064 100644 --- a/test/markup/cpp/primitive-types.expect.txt +++ b/test/markup/cpp/primitive-types.expect.txt @@ -1,3 +1,57 @@ -const uint64_t MAX_INT_64; - +// Primitive types: +char8_t test; +char16_t test; +char32_t test; +char8_t test; +int8_t test; +int16_t test; +int32_t test; +int64_t test; +int_fast8_t test; +int_fast16_t test; +int_fast32_t test; +int_fast64_t test; +int_least8_t test; +int_least16_t test; +int_least32_t test; +int_least64_t test; +intmax_t test; +intptr_t test; +uint8_t test; +uint16_t test; +uint32_t test; +uint64_t test; +uint_fast8_t test; +uint_fast16_t test; +uint_fast32_t test; +uint_fast64_t test; +uint_least8_t test; +uint_least16_t test; +uint_least32_t test; +uint_least64_t test; +uintmax_t test; +uintptr_t test; +max_align_t test; +mbstate_t test; +nullptr_t test; +ptrdiff_t test; +size_t test; +wchar_t test; +wctrans_t test; +wctype_t test; +wint_t test; + +// Non-primitive type with '_t': struct position_tag; +class _thread; + +// Type traits and helpers types: +template<class T> +using decay_t = typename decay<T>::type; + +template<typename T> +struct X { + using decayed_t = typename std::decay_t<X<T>>; +}; + +X<int&>::decayed_t x; \ No newline at end of file diff --git a/test/markup/cpp/primitive-types.txt b/test/markup/cpp/primitive-types.txt index 86f1167840..1b7738fc5c 100644 --- a/test/markup/cpp/primitive-types.txt +++ b/test/markup/cpp/primitive-types.txt @@ -1,3 +1,57 @@ -const uint64_t MAX_INT_64; - +// Primitive types: +char8_t test; +char16_t test; +char32_t test; +char8_t test; +int8_t test; +int16_t test; +int32_t test; +int64_t test; +int_fast8_t test; +int_fast16_t test; +int_fast32_t test; +int_fast64_t test; +int_least8_t test; +int_least16_t test; +int_least32_t test; +int_least64_t test; +intmax_t test; +intptr_t test; +uint8_t test; +uint16_t test; +uint32_t test; +uint64_t test; +uint_fast8_t test; +uint_fast16_t test; +uint_fast32_t test; +uint_fast64_t test; +uint_least8_t test; +uint_least16_t test; +uint_least32_t test; +uint_least64_t test; +uintmax_t test; +uintptr_t test; +max_align_t test; +mbstate_t test; +nullptr_t test; +ptrdiff_t test; +size_t test; +wchar_t test; +wctrans_t test; +wctype_t test; +wint_t test; + +// Non-primitive type with '_t': struct position_tag; +class _thread; + +// Type traits and helpers types: +template +using decay_t = typename decay::type; + +template +struct X { + using decayed_t = typename std::decay_t>; +}; + +X::decayed_t x; \ No newline at end of file diff --git a/test/markup/cpp/template_complexity.expect.txt b/test/markup/cpp/template-complexity.expect.txt similarity index 65% rename from test/markup/cpp/template_complexity.expect.txt rename to test/markup/cpp/template-complexity.expect.txt index 1241d0c762..9e004abdb7 100644 --- a/test/markup/cpp/template_complexity.expect.txt +++ b/test/markup/cpp/template-complexity.expect.txt @@ -3,19 +3,19 @@ namespace impl { template<typename T> - struct is_streamable<T, std::void_t<decltype(std::declval<std::wostream &>() << std::declval<T>())>> : std::true_type { }; + struct is_streamable<T, std::void_t<decltype(std::declval<std::wostream &>() << std::declval<T>())>> : std::true_type { }; } // Disable overload for already valid operands. -template<class T, class = std::enable_if_t<!impl::is_streamable_v<const T &> && std::is_convertible_v<const T &, std::wstring_view>>> +template<class T, class = std::enable_if_t<!impl::is_streamable_v<const T &> && std::is_convertible_v<const T &, std::wstring_view>>> std::wostream &operator <<(std::wostream &stream, const T &thing) { - return stream << static_cast<std::wstring_view>(thing); + return stream << static_cast<std::wstring_view>(thing); } enum struct DataHolder { }; enum class DataThingy { }; -enum class Boolean : char { +enum class Boolean : char { True, False, FileNotFound }; diff --git a/test/markup/cpp/template_complexity.txt b/test/markup/cpp/template-complexity.txt similarity index 100% rename from test/markup/cpp/template_complexity.txt rename to test/markup/cpp/template-complexity.txt