Arduino IDE 1.x used a syntax highlighting system where arbitrary keywords could be defined, globally, by the boards platform authors, and by library authors:
https://arduino.github.io/arduino-cli/latest/library-specification/#keywords
https://arduino.github.io/arduino-cli/latest/platform-specification/#keywordstxt
You can see the definition of the boolean
and byte
keywords here:
https://github.com/arduino/Arduino/blob/1.8.19/build/shared/lib/keywords.txt#L59-L60
boolean LITERAL1 BooleanVariables RESERVED_WORD_2
byte LITERAL1 Byte RESERVED_WORD_2
The good thing about this system is that it makes the syntax highlighting system accessible to the library and boards platform authors and also adapts the highlighting to the platforms and libraries each user had installed.
However, the system is incredibly crude. All occurrences of all keywords of all installed libraries are highlighted, regardless of whether the occurrence was actually a use of the object from that library. This means that you could end up with quite a strange sprinkling of coloration across your sketch after you accumulate a significant number of libraries.
The keywords system is also not used very effectively. The library developers really struggle to get the tab separated data format of the file correct so that it will actually be recognized by Arduino IDE 1.x. Some library authors define keywords inconsistently, forgetting to add new keywords while adding new API components. Some library authors don't bother adding keywords at all.
So you end up with some things in Arduino IDE 1.x being highlighted that shouldn't be and also some things not being highlighted that should be.
Arduino IDE 2.x does not have any support for the keywords.txt
system of Arduino IDE 1.x. Instead it uses the VS Code built-in "cpp" C++ extension:
This provides the IDE with a general understanding of the C++ syntax.
I believe the relevant line is here:
https://github.com/microsoft/vscode/blob/1.53.2/extensions/cpp/syntaxes/cpp.tmLanguage.json#L576
"builtin_storage_type_initilizer": {
"begin": "(?:\\s)*+(?<!\\w)(?:(?:(?:((?:(?:unsigned)|(?:wchar_t)|(?:double)|(?:signed)|(?:short)|(?:float)|(?:auto)|(?:void)|(?:long)|(?:char)|(?:bool)|(?:int)))|((?:(?:uint_least32_t)|(?:uint_least64_t)|(?:uint_least16_t)|(?:uint_fast64_t)|(?:uint_least8_t)|(?:int_least64_t)|(?:int_least32_t)|(?:int_least16_t)|(?:uint_fast16_t)|(?:uint_fast32_t)|(?:int_least8_t)|(?:int_fast16_t)|(?:int_fast32_t)|(?:int_fast64_t)|(?:uint_fast8_t)|(?:int_fast8_t)|(?:suseconds_t)|(?:useconds_t)|(?:uintmax_t)|(?:uintmax_t)|(?:in_port_t)|(?:uintmax_t)|(?:in_addr_t)|(?:blksize_t)|(?:uintptr_t)|(?:intmax_t)|(?:intptr_t)|(?:blkcnt_t)|(?:intmax_t)|(?:u_quad_t)|(?:uint16_t)|(?:uint32_t)|(?:uint64_t)|(?:ssize_t)|(?:fixpt_t)|(?:qaddr_t)|(?:u_short)|(?:int16_t)|(?:int32_t)|(?:int64_t)|(?:uint8_t)|(?:daddr_t)|(?:caddr_t)|(?:swblk_t)|(?:clock_t)|(?:segsz_t)|(?:nlink_t)|(?:time_t)|(?:u_long)|(?:ushort)|(?:quad_t)|(?:mode_t)|(?:size_t)|(?:u_char)|(?:int8_t)|(?:u_int)|(?:uid_t)|(?:off_t)|(?:pid_t)|(?:gid_t)|(?:dev_t)|(?:div_t)|(?:key_t)|(?:ino_t)|(?:id_t)|(?:id_t)|(?:uint))))|((?:(?:pthread_rwlockattr_t)|(?:pthread_mutexattr_t)|(?:pthread_condattr_t)|(?:pthread_rwlock_t)|(?:pthread_mutex_t)|(?:pthread_cond_t)|(?:pthread_attr_t)|(?:pthread_once_t)|(?:pthread_key_t)|(?:pthread_t))))|([a-zA-Z_](?:\\w)*_t))(?!\\w)(?:\\s)*+(?<!\\w)(\\()",
"end": "\\)",
There is information about how the syntax highlighting system works here:
It would be interesting to see whether it would be possible to extend the syntax via a custom VS Code extension. It looks to be very easy to get started with experimenting with this system.