C++.sublime-syntax 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  1. %YAML 1.2
  2. ---
  3. # http://www.sublimetext.com/docs/3/syntax.html
  4. name: C++ (fmt)
  5. comment: I don't think anyone uses .hp. .cp tends to be paired with .h. (I could be wrong. :) -- chris
  6. file_extensions:
  7. - cpp
  8. - cc
  9. - cp
  10. - cxx
  11. - c++
  12. - C
  13. - h
  14. - hh
  15. - hpp
  16. - hxx
  17. - h++
  18. - inl
  19. - ipp
  20. first_line_match: '-\*- C\+\+ -\*-'
  21. scope: source.c++
  22. variables:
  23. identifier: \b[[:alpha:]_][[:alnum:]_]*\b # upper and lowercase
  24. macro_identifier: \b[[:upper:]_][[:upper:][:digit:]_]{2,}\b # only uppercase, at least 3 chars
  25. path_lookahead: '(?:::\s*)?(?:{{identifier}}\s*::\s*)*(?:template\s+)?{{identifier}}'
  26. operator_method_name: '\boperator\s*(?:[-+*/%^&|~!=<>]|[-+*/%^&|=!<>]=|<<=?|>>=?|&&|\|\||\+\+|--|,|->\*?|\(\)|\[\]|""\s*{{identifier}})'
  27. casts: 'const_cast|dynamic_cast|reinterpret_cast|static_cast'
  28. operator_keywords: 'and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq|noexcept'
  29. control_keywords: 'break|case|catch|continue|default|do|else|for|goto|if|_Pragma|return|switch|throw|try|while'
  30. memory_operators: 'new|delete'
  31. basic_types: 'asm|__asm__|auto|bool|_Bool|char|_Complex|double|float|_Imaginary|int|long|short|signed|unsigned|void'
  32. before_tag: 'struct|union|enum\s+class|enum\s+struct|enum|class'
  33. declspec: '__declspec\(\s*\w+(?:\([^)]+\))?\s*\)'
  34. storage_classes: 'static|export|extern|friend|explicit|virtual|register|thread_local'
  35. type_qualifier: 'const|constexpr|mutable|typename|volatile'
  36. compiler_directive: 'inline|restrict|__restrict__|__restrict'
  37. visibility_modifiers: 'private|protected|public'
  38. other_keywords: 'typedef|nullptr|{{visibility_modifiers}}|static_assert|sizeof|using|typeid|alignof|alignas|namespace|template'
  39. modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}'
  40. non_angle_brackets: '(?=<<|<=)'
  41. regular: '[^(){}&;*^%=<>-]*'
  42. paren_open: (?:\(
  43. paren_close: '\))?'
  44. generic_open: (?:<
  45. generic_close: '>)?'
  46. balance_parentheses: '{{regular}}{{paren_open}}{{regular}}{{paren_close}}{{regular}}'
  47. generic_lookahead: <{{regular}}{{generic_open}}{{regular}}{{generic_open}}{{regular}}{{generic_close}}\s*{{generic_close}}{{balance_parentheses}}>
  48. data_structures_forward_decl_lookahead: '(\s+{{macro_identifier}})*\s*(:\s*({{path_lookahead}}|{{visibility_modifiers}}|,|\s|<[^;]*>)+)?;'
  49. non_func_keywords: 'if|for|switch|while|decltype|sizeof|__declspec|__attribute__|typeid|alignof|alignas|static_assert'
  50. format_spec: |-
  51. (?x:
  52. (?:.? [<>=^])? # fill align
  53. [ +-]? # sign
  54. \#? # alternate form
  55. # technically, octal and hexadecimal integers are also supported as 'width', but rarely used
  56. \d* # width
  57. ,? # thousands separator
  58. (?:\.\d+)? # precision
  59. [bcdeEfFgGnosxX%]? # type
  60. )
  61. contexts:
  62. main:
  63. - include: preprocessor-global
  64. - include: global
  65. #############################################################################
  66. # Reusable contexts
  67. #
  68. # The follow contexts are currently constructed to be reused in the
  69. # Objetive-C++ syntax. They are specifically constructed to not push into
  70. # sub-contexts, which ensures that Objective-C++ code isn't accidentally
  71. # lexed as plain C++.
  72. #
  73. # The "unique-*" contexts are additions that C++ makes over C, and thus can
  74. # be directly reused in Objective-C++ along with contexts from Objective-C
  75. # and C.
  76. #############################################################################
  77. unique-late-expressions:
  78. # This is highlighted after all of the other control keywords
  79. # to allow operator overloading to be lexed properly
  80. - match: \boperator\b
  81. scope: keyword.control.c++
  82. unique-modifiers:
  83. - match: \b({{modifiers}})\b
  84. scope: storage.modifier.c++
  85. unique-variables:
  86. - match: \bthis\b
  87. scope: variable.language.c++
  88. # common C++ instance var naming idiom -- fMemberName
  89. - match: '\b(f|m)[[:upper:]]\w*\b'
  90. scope: variable.other.readwrite.member.c++
  91. # common C++ instance var naming idiom -- m_member_name
  92. - match: '\bm_[[:alnum:]_]+\b'
  93. scope: variable.other.readwrite.member.c++
  94. unique-constants:
  95. - match: \bnullptr\b
  96. scope: constant.language.c++
  97. unique-keywords:
  98. - match: \busing\b
  99. scope: keyword.control.c++
  100. - match: \bbreak\b
  101. scope: keyword.control.flow.break.c++
  102. - match: \bcontinue\b
  103. scope: keyword.control.flow.continue.c++
  104. - match: \bgoto\b
  105. scope: keyword.control.flow.goto.c++
  106. - match: \breturn\b
  107. scope: keyword.control.flow.return.c++
  108. - match: \bthrow\b
  109. scope: keyword.control.flow.throw.c++
  110. - match: \b({{control_keywords}})\b
  111. scope: keyword.control.c++
  112. - match: '\bdelete\b(\s*\[\])?|\bnew\b(?!])'
  113. scope: keyword.control.c++
  114. - match: \b({{operator_keywords}})\b
  115. scope: keyword.operator.word.c++
  116. unique-types:
  117. - match: \b(char16_t|char32_t|wchar_t|nullptr_t)\b
  118. scope: storage.type.c++
  119. - match: \bclass\b
  120. scope: storage.type.c++
  121. unique-strings:
  122. - match: '((?:L|u8|u|U)?R)("([^\(\)\\ ]{0,16})\()'
  123. captures:
  124. 1: storage.type.string.c++
  125. 2: punctuation.definition.string.begin.c++
  126. push:
  127. - meta_scope: string.quoted.double.c++
  128. - match: '\)\3"'
  129. scope: punctuation.definition.string.end.c++
  130. pop: true
  131. - match: '\{\{|\}\}'
  132. scope: constant.character.escape.c++
  133. - include: formatting-syntax
  134. unique-numbers:
  135. - match: |-
  136. (?x)
  137. (?:
  138. # floats
  139. (?:
  140. (?:\b\d(?:[\d']*\d)?\.\d(?:[\d']*\d)?|\B\.\d(?:[\d']*\d)?)(?:[Ee][+-]?\d(?:[\d']*\d)?)?(?:[fFlL]|(?:i[fl]?|h|min|[mun]?s|_\w*))?\b
  141. |
  142. (?:\b\d(?:[\d']*\d)?\.)(?:\B|(?:[fFlL]|(?:i[fl]?|h|min|[mun]?s|_\w*))\b|(?:[Ee][+-]?\d(?:[\d']*\d)?)(?:[fFlL]|(?:i[fl]?|h|min|[mun]?s|_\w*))?\b)
  143. |
  144. \b\d(?:[\d']*\d)?(?:[Ee][+-]?\d(?:[\d']*\d)?)(?:[fFlL]|(?:i[fl]?|h|min|[mun]?s|_\w*))?\b
  145. )
  146. |
  147. # ints
  148. \b(?:
  149. (?:
  150. # dec
  151. [1-9](?:[\d']*\d)?
  152. |
  153. # oct
  154. 0(?:[0-7']*[0-7])?
  155. |
  156. # hex
  157. 0[Xx][\da-fA-F](?:[\da-fA-F']*[\da-fA-F])?
  158. |
  159. # bin
  160. 0[Bb][01](?:[01']*[01])?
  161. )
  162. # int suffixes
  163. (?:(?:l{1,2}|L{1,2})[uU]?|[uU](?:l{0,2}|L{0,2})|(?:i[fl]?|h|min|[mun]?s|_\w*))?)\b
  164. )
  165. (?!\.) # Number must not be followed by a decimal point
  166. scope: constant.numeric.c++
  167. identifiers:
  168. - match: '{{identifier}}\s*(::)\s*'
  169. captures:
  170. 1: punctuation.accessor.c++
  171. - match: '(?:(::)\s*)?{{identifier}}'
  172. captures:
  173. 1: punctuation.accessor.c++
  174. function-specifiers:
  175. - match: \b(const|final|noexcept|override)\b
  176. scope: storage.modifier.c++
  177. #############################################################################
  178. # The following are C++-specific contexts that should not be reused. This is
  179. # because they push into subcontexts and use variables that are C++-specific.
  180. #############################################################################
  181. ## Common context layout
  182. global:
  183. - match: '(?=\btemplate\b)'
  184. push:
  185. - include: template
  186. - match: (?=\S)
  187. set: global-modifier
  188. - include: namespace
  189. - include: keywords-angle-brackets
  190. - match: '(?={{path_lookahead}}\s*<)'
  191. push: global-modifier
  192. # Take care of comments just before a function definition.
  193. - match: /\*
  194. scope: punctuation.definition.comment.c
  195. push:
  196. - - match: \s*(?=\w)
  197. set: global-modifier
  198. - match: ""
  199. pop: true
  200. - - meta_scope: comment.block.c
  201. - match: \*/
  202. scope: punctuation.definition.comment.c
  203. pop: true
  204. - include: early-expressions
  205. - match: ^\s*\b(extern)(?=\s+"C(\+\+)?")
  206. scope: storage.modifier.c++
  207. push:
  208. - include: comments
  209. - include: strings
  210. - match: '\{'
  211. scope: punctuation.section.block.begin.c++
  212. set:
  213. - meta_scope: meta.extern-c.c++
  214. - match: '^\s*(#\s*ifdef)\s*__cplusplus\s*'
  215. scope: meta.preprocessor.c++
  216. captures:
  217. 1: keyword.control.import.c++
  218. set:
  219. - match: '\}'
  220. scope: punctuation.section.block.end.c++
  221. pop: true
  222. - include: preprocessor-global
  223. - include: global
  224. - match: '\}'
  225. scope: punctuation.section.block.end.c++
  226. pop: true
  227. - include: preprocessor-global
  228. - include: global
  229. - match: (?=\S)
  230. set: global-modifier
  231. - match: ^\s*(?=\w)
  232. push: global-modifier
  233. - include: late-expressions
  234. statements:
  235. - include: preprocessor-statements
  236. - include: scope:source.c#label
  237. - include: expressions
  238. expressions:
  239. - include: early-expressions
  240. - include: late-expressions
  241. early-expressions:
  242. - include: early-expressions-before-generic-type
  243. - include: generic-type
  244. - include: early-expressions-after-generic-type
  245. early-expressions-before-generic-type:
  246. - include: preprocessor-expressions
  247. - include: comments
  248. - include: case-default
  249. - include: typedef
  250. - include: keywords-angle-brackets
  251. - include: keywords-parens
  252. - include: keywords
  253. - include: numbers
  254. # Prevent a '<' from getting scoped as the start of another template
  255. # parameter list, if in reality a less-than-or-equals sign is meant.
  256. - match: <=
  257. scope: keyword.operator.comparison.c
  258. early-expressions-after-generic-type:
  259. - include: members-arrow
  260. - include: operators
  261. - include: members-dot
  262. - include: strings
  263. - include: parens
  264. - include: brackets
  265. - include: block
  266. - include: variables
  267. - include: constants
  268. - match: ','
  269. scope: punctuation.separator.c++
  270. - match: '\)|\}'
  271. scope: invalid.illegal.stray-bracket-end.c++
  272. expressions-minus-generic-type:
  273. - include: early-expressions-before-generic-type
  274. - include: angle-brackets
  275. - include: early-expressions-after-generic-type
  276. - include: late-expressions
  277. expressions-minus-generic-type-function-call:
  278. - include: early-expressions-before-generic-type
  279. - include: angle-brackets
  280. - include: early-expressions-after-generic-type
  281. - include: late-expressions-before-function-call
  282. - include: identifiers
  283. - match: ';'
  284. scope: punctuation.terminator.c++
  285. late-expressions:
  286. - include: late-expressions-before-function-call
  287. - include: function-call
  288. - include: identifiers
  289. - match: ';'
  290. scope: punctuation.terminator.c++
  291. late-expressions-before-function-call:
  292. - include: unique-late-expressions
  293. - include: modifiers-parens
  294. - include: modifiers
  295. - include: types
  296. expressions-minus-function-call:
  297. - include: early-expressions
  298. - include: late-expressions-before-function-call
  299. - include: identifiers
  300. - match: ';'
  301. scope: punctuation.terminator.c++
  302. comments:
  303. - include: scope:source.c#comments
  304. operators:
  305. - include: scope:source.c#operators
  306. modifiers:
  307. - include: unique-modifiers
  308. - include: scope:source.c#modifiers
  309. variables:
  310. - include: unique-variables
  311. - include: scope:source.c#variables
  312. constants:
  313. - include: unique-constants
  314. - include: scope:source.c#constants
  315. keywords:
  316. - include: unique-keywords
  317. - include: scope:source.c#keywords
  318. types:
  319. - include: unique-types
  320. - include: types-parens
  321. - include: scope:source.c#types
  322. strings:
  323. - include: unique-strings
  324. - match: '(L|u8|u|U)?(")'
  325. captures:
  326. 1: storage.type.string.c++
  327. 2: punctuation.definition.string.begin.c++
  328. push:
  329. - meta_scope: string.quoted.double.c++
  330. - match: '"'
  331. scope: punctuation.definition.string.end.c++
  332. pop: true
  333. - include: scope:source.c#string_escaped_char
  334. - match: |-
  335. (?x)%
  336. (\d+\$)? # field (argument #)
  337. [#0\- +']* # flags
  338. [,;:_]? # separator character (AltiVec)
  339. ((-?\d+)|\*(-?\d+\$)?)? # minimum field width
  340. (\.((-?\d+)|\*(-?\d+\$)?)?)? # precision
  341. (hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier
  342. (\[[^\]]+\]|[am]s|[diouxXDOUeEfFgGaACcSspn%]) # conversion type
  343. scope: constant.other.placeholder.c++
  344. - match: '\{\{|\}\}'
  345. scope: constant.character.escape.c++
  346. - include: formatting-syntax
  347. - include: scope:source.c#strings
  348. formatting-syntax:
  349. # https://docs.python.org/3.6/library/string.html#formatstrings
  350. - match: |- # simple form
  351. (?x)
  352. (\{)
  353. (?: [\w.\[\]]+)? # field_name
  354. ( ! [ars])? # conversion
  355. ( : (?:{{format_spec}}| # format_spec OR
  356. [^}%]*%.[^}]*) # any format-like string
  357. )?
  358. (\})
  359. scope: constant.other.placeholder.c++
  360. captures:
  361. 1: punctuation.definition.placeholder.begin.c++
  362. 2: storage.modifier.c++onversion.c++
  363. 3: constant.other.format-spec.c++
  364. 4: punctuation.definition.placeholder.end.c++
  365. - match: \{(?=[^\}"']+\{[^"']*\}) # complex (nested) form
  366. scope: punctuation.definition.placeholder.begin.c++
  367. push:
  368. - meta_scope: constant.other.placeholder.c++
  369. - match: \}
  370. scope: punctuation.definition.placeholder.end.c++
  371. pop: true
  372. - match: '[\w.\[\]]+'
  373. - match: '![ars]'
  374. scope: storage.modifier.conversion.c++
  375. - match: ':'
  376. push:
  377. - meta_scope: meta.format-spec.c++ constant.other.format-spec.c++
  378. - match: (?=\})
  379. pop: true
  380. - include: formatting-syntax
  381. numbers:
  382. - include: unique-numbers
  383. - include: scope:source.c#numbers
  384. ## C++-specific contexts
  385. case-default:
  386. - match: '\b(default|case)\b'
  387. scope: keyword.control.c++
  388. push:
  389. - match: (?=[);,])
  390. pop: true
  391. - match: ':'
  392. scope: punctuation.separator.c++
  393. pop: true
  394. - include: expressions
  395. modifiers-parens:
  396. - match: '\b(alignas)\b\s*(\()'
  397. captures:
  398. 1: storage.modifier.c++
  399. 2: meta.group.c++ punctuation.section.group.begin.c++
  400. push:
  401. - meta_content_scope: meta.group.c++
  402. - match: '\)'
  403. scope: meta.group.c++ punctuation.section.group.end.c++
  404. pop: true
  405. - include: expressions
  406. - match: \b(__attribute__)\s*(\(\()
  407. captures:
  408. 1: storage.modifier.c++
  409. 2: meta.group.c++ punctuation.section.group.begin.c++
  410. push :
  411. - meta_scope: meta.attribute.c++
  412. - meta_content_scope: meta.group.c++
  413. - include: parens
  414. - include: strings
  415. - match: \)\)
  416. scope: meta.group.c++ punctuation.section.group.end.c++
  417. pop: true
  418. - match: \b(__declspec)(\()
  419. captures:
  420. 1: storage.modifier.c++
  421. 2: meta.group.c++ punctuation.section.group.begin.c++
  422. push:
  423. - meta_content_scope: meta.group.c++
  424. - match: '\)'
  425. scope: meta.group.c++ punctuation.section.group.end.c++
  426. pop: true
  427. - match: '\b(align|allocate|code_seg|deprecated|property|uuid)\b\s*(\()'
  428. captures:
  429. 1: storage.modifier.c++
  430. 2: meta.group.c++ punctuation.section.group.begin.c++
  431. push:
  432. - meta_content_scope: meta.group.c++
  433. - match: '\)'
  434. scope: meta.group.c++ punctuation.section.group.end.c++
  435. pop: true
  436. - include: numbers
  437. - include: strings
  438. - match: \b(get|put)\b
  439. scope: variable.parameter.c++
  440. - match: ','
  441. scope: punctuation.separator.c++
  442. - match: '='
  443. scope: keyword.operator.assignment.c++
  444. - match: '\b(appdomain|deprecated|dllimport|dllexport|jintrinsic|naked|noalias|noinline|noreturn|nothrow|novtable|process|restrict|safebuffers|selectany|thread)\b'
  445. scope: constant.other.c++
  446. types-parens:
  447. - match: '\b(decltype)\b\s*(\()'
  448. captures:
  449. 1: storage.type.c++
  450. 2: meta.group.c++ punctuation.section.group.begin.c++
  451. push:
  452. - meta_content_scope: meta.group.c++
  453. - match: '\)'
  454. scope: meta.group.c++ punctuation.section.group.end.c++
  455. pop: true
  456. - include: expressions
  457. keywords-angle-brackets:
  458. - match: \b({{casts}})\b\s*
  459. scope: keyword.operator.word.cast.c++
  460. push:
  461. - match: '>'
  462. scope: punctuation.section.generic.end.c++
  463. pop: true
  464. - match: '<'
  465. scope: punctuation.section.generic.begin.c++
  466. push:
  467. - match: '(?=>)'
  468. pop: true
  469. - include: expressions-minus-generic-type-function-call
  470. keywords-parens:
  471. - match: '\b(alignof|typeid|static_assert|sizeof)\b\s*(\()'
  472. captures:
  473. 1: keyword.operator.word.c++
  474. 2: meta.group.c++ punctuation.section.group.begin.c++
  475. push:
  476. - meta_content_scope: meta.group.c++
  477. - match: '\)'
  478. scope: meta.group.c++ punctuation.section.group.end.c++
  479. pop: true
  480. - include: expressions
  481. namespace:
  482. - match: '\b(using)\s+(namespace)\s+(?={{path_lookahead}})'
  483. captures:
  484. 1: keyword.control.c++
  485. 2: keyword.control.c++
  486. push:
  487. - include: identifiers
  488. - match: ''
  489. pop: true
  490. - match: '\b(namespace)\s+(?=({{path_lookahead}})?(?!\s*[;,]))'
  491. scope: meta.namespace.c++
  492. captures:
  493. 1: keyword.control.c++
  494. push:
  495. - meta_content_scope: meta.namespace.c++ entity.name.namespace.c++
  496. - include: identifiers
  497. - match: ''
  498. set:
  499. - meta_scope: meta.namespace.c++
  500. - include: comments
  501. - match: '='
  502. scope: keyword.operator.alias.c++
  503. - match: '(?=;)'
  504. pop: true
  505. - match: '\}'
  506. scope: meta.block.c++ punctuation.section.block.end.c++
  507. pop: true
  508. - match: '\{'
  509. scope: punctuation.section.block.begin.c++
  510. push:
  511. - meta_scope: meta.block.c++
  512. - match: '(?=\})'
  513. pop: true
  514. - include: preprocessor-global
  515. - include: global
  516. - include: expressions
  517. template-common:
  518. # Exit the template scope if we hit some basic invalid characters. This
  519. # helps when a user is in the middle of typing their template types and
  520. # prevents re-highlighting the whole file until the next > is found.
  521. - match: (?=[{};])
  522. pop: true
  523. - include: expressions
  524. template:
  525. - match: \btemplate\b
  526. scope: storage.type.template.c++
  527. push:
  528. - meta_scope: meta.template.c++
  529. # Explicitly include comments here at the top, in order to NOT match the
  530. # \S lookahead in the case of comments.
  531. - include: comments
  532. - match: <
  533. scope: punctuation.section.generic.begin.c++
  534. set:
  535. - meta_content_scope: meta.template.c++
  536. - match: '>'
  537. scope: meta.template.c++ punctuation.section.generic.end.c++
  538. pop: true
  539. - match: \.{3}
  540. scope: keyword.operator.variadic.c++
  541. - match: \b(typename|{{before_tag}})\b
  542. scope: storage.type.c++
  543. - include: template # include template here for nested templates
  544. - include: template-common
  545. - match: (?=\S)
  546. set:
  547. - meta_content_scope: meta.template.c++
  548. - match: \b({{before_tag}})\b
  549. scope: storage.type.c++
  550. - include: template-common
  551. generic-type:
  552. - match: '(?=(?!template){{path_lookahead}}\s*{{generic_lookahead}}\s*\()'
  553. push:
  554. - meta_scope: meta.function-call.c++
  555. - match: \btemplate\b
  556. scope: storage.type.template.c++
  557. - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*'
  558. captures:
  559. 1: punctuation.accessor.double-colon.c++
  560. 2: punctuation.accessor.double-colon.c++
  561. - match: (?:(::)\s*)?({{identifier}})\s*(<)
  562. captures:
  563. 1: punctuation.accessor.double-colon.c++
  564. 2: variable.function.c++
  565. 3: punctuation.section.generic.begin.c++
  566. push:
  567. - match: '>'
  568. scope: punctuation.section.generic.end.c++
  569. pop: true
  570. - include: expressions-minus-generic-type-function-call
  571. - match: (?:(::)\s*)?({{identifier}})\s*(\()
  572. captures:
  573. 1: punctuation.accessor.double-colon.c++
  574. 2: variable.function.c++
  575. 3: punctuation.section.group.begin.c++
  576. set:
  577. - meta_scope: meta.function-call.c++
  578. - meta_content_scope: meta.group.c++
  579. - match: '\)'
  580. scope: meta.group.c++ punctuation.section.group.end.c++
  581. pop: true
  582. - include: expressions
  583. - include: angle-brackets
  584. - match: '\('
  585. scope: meta.group.c++ punctuation.section.group.begin.c++
  586. set:
  587. - meta_scope: meta.function-call.c++
  588. - meta_content_scope: meta.group.c++
  589. - match: '\)'
  590. scope: meta.group.c++ punctuation.section.group.end.c++
  591. pop: true
  592. - include: expressions
  593. - match: '(?=(?!template){{path_lookahead}}\s*{{generic_lookahead}})'
  594. push:
  595. - include: identifiers
  596. - match: '<'
  597. scope: punctuation.section.generic.begin.c++
  598. set:
  599. - match: '>'
  600. scope: punctuation.section.generic.end.c++
  601. pop: true
  602. - include: expressions-minus-generic-type-function-call
  603. angle-brackets:
  604. - match: '<(?!<)'
  605. scope: punctuation.section.generic.begin.c++
  606. push:
  607. - match: '>'
  608. scope: punctuation.section.generic.end.c++
  609. pop: true
  610. - include: expressions-minus-generic-type-function-call
  611. block:
  612. - match: '\{'
  613. scope: punctuation.section.block.begin.c++
  614. push:
  615. - meta_scope: meta.block.c++
  616. - match: (?=^\s*#\s*(elif|else|endif)\b)
  617. pop: true
  618. - match: '\}'
  619. scope: punctuation.section.block.end.c++
  620. pop: true
  621. - include: statements
  622. function-call:
  623. - match: (?={{path_lookahead}}\s*\()
  624. push:
  625. - meta_scope: meta.function-call.c++
  626. - include: scope:source.c#c99
  627. - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*'
  628. scope: variable.function.c++
  629. captures:
  630. 1: punctuation.accessor.c++
  631. 2: punctuation.accessor.c++
  632. - match: '(?:(::)\s*)?{{identifier}}'
  633. scope: variable.function.c++
  634. captures:
  635. 1: punctuation.accessor.c++
  636. - match: '\('
  637. scope: meta.group.c++ punctuation.section.group.begin.c++
  638. set:
  639. - meta_content_scope: meta.function-call.c++ meta.group.c++
  640. - match: '\)'
  641. scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++
  642. pop: true
  643. - include: expressions
  644. members-inside-function-call:
  645. - meta_content_scope: meta.method-call.c++ meta.group.c++
  646. - match: \)
  647. scope: meta.method-call.c++ meta.group.c++ punctuation.section.group.end.c++
  648. pop: true
  649. - include: expressions
  650. members-after-accessor-junction:
  651. # After we've seen an accessor (dot or arrow), this context decides what
  652. # kind of entity we're accessing.
  653. - include: comments
  654. - match: \btemplate\b
  655. scope: meta.method-call.c++ storage.type.template.c++
  656. # Guaranteed to be a template member function call after we match this
  657. set:
  658. - meta_content_scope: meta.method-call.c++
  659. - include: comments
  660. - match: '{{identifier}}'
  661. scope: variable.function.member.c++
  662. set:
  663. - meta_content_scope: meta.method-call.c++
  664. - match: \(
  665. scope: meta.group.c++ punctuation.section.group.begin.c++
  666. set: members-inside-function-call
  667. - include: comments
  668. - include: angle-brackets
  669. - match: (?=\S) # safety pop
  670. pop: true
  671. - match: (?=\S) # safety pop
  672. pop: true
  673. # Operator overloading
  674. - match: '({{operator_method_name}})\s*(\()'
  675. captures:
  676. 0: meta.method-call.c++
  677. 1: variable.function.member.c++
  678. 2: meta.group.c++ punctuation.section.group.begin.c++
  679. set: members-inside-function-call
  680. # Non-templated member function call
  681. - match: (~?{{identifier}})\s*(\()
  682. captures:
  683. 0: meta.method-call.c++
  684. 1: variable.function.member.c++
  685. 2: meta.group.c++ punctuation.section.group.begin.c++
  686. set: members-inside-function-call
  687. # Templated member function call
  688. - match: (~?{{identifier}})\s*(?={{generic_lookahead}})
  689. captures:
  690. 1: variable.function.member.c++
  691. set:
  692. - meta_scope: meta.method-call.c++
  693. - match: <
  694. scope: punctuation.section.generic.begin.c++
  695. set:
  696. - meta_content_scope: meta.method-call.c++
  697. - match: '>'
  698. scope: punctuation.section.generic.end.c++
  699. set:
  700. - meta_content_scope: meta.method-call.c++
  701. - include: comments
  702. - match: \(
  703. scope: punctuation.section.group.begin.c++
  704. set: members-inside-function-call
  705. - match: (?=\S) # safety pop
  706. pop: true
  707. - include: expressions
  708. # Explicit base-class access
  709. - match: ({{identifier}})\s*(::)
  710. captures:
  711. 1: variable.other.base-class.c++
  712. 2: punctuation.accessor.double-colon.c++
  713. set: members-after-accessor-junction # reset
  714. # Just a regular member variable
  715. - match: '{{identifier}}'
  716. scope: variable.other.readwrite.member.c++
  717. pop: true
  718. members-dot:
  719. - include: scope:source.c#access-illegal
  720. # No lookahead required because members-dot goes after operators in the
  721. # early-expressions-after-generic-type context. This means triple dots
  722. # (i.e. "..." or "variadic") is attempted first.
  723. - match: \.
  724. scope: punctuation.accessor.dot.c++
  725. push: members-after-accessor-junction
  726. members-arrow:
  727. # This needs to be before operators in the
  728. # early-expressions-after-generic-type context because otherwise the "->"
  729. # from the C language will match.
  730. - match: ->
  731. scope: punctuation.accessor.arrow.c++
  732. push: members-after-accessor-junction
  733. typedef:
  734. - match: \btypedef\b
  735. scope: storage.type.c++
  736. push:
  737. - match: ({{identifier}})?\s*(?=;)
  738. captures:
  739. 1: entity.name.type.typedef.c++
  740. pop: true
  741. - match: \b(struct)\s+({{identifier}})\b
  742. captures:
  743. 1: storage.type.c++
  744. - include: expressions-minus-generic-type
  745. parens:
  746. - match: \(
  747. scope: punctuation.section.group.begin.c++
  748. push:
  749. - meta_scope: meta.group.c++
  750. - match: \)
  751. scope: punctuation.section.group.end.c++
  752. pop: true
  753. - include: expressions
  754. brackets:
  755. - match: \[
  756. scope: punctuation.section.brackets.begin.c++
  757. push:
  758. - meta_scope: meta.brackets.c++
  759. - match: \]
  760. scope: punctuation.section.brackets.end.c++
  761. pop: true
  762. - include: expressions
  763. function-trailing-return-type:
  764. - match: '{{non_angle_brackets}}'
  765. pop: true
  766. - include: angle-brackets
  767. - include: types
  768. - include: modifiers-parens
  769. - include: modifiers
  770. - include: identifiers
  771. - match: \*|&
  772. scope: keyword.operator.c++
  773. - include: function-trailing-return-type-parens
  774. - match: '(?=\S)'
  775. pop: true
  776. function-trailing-return-type-parens:
  777. - match: \(
  778. scope: punctuation.section.group.begin.c++
  779. push:
  780. - meta_scope: meta.group.c++
  781. - match: \)
  782. scope: punctuation.section.group.end.c++
  783. pop: true
  784. - include: function-trailing-return-type
  785. ## Detection of function and data structure definitions at the global level
  786. global-modifier:
  787. - include: comments
  788. - include: modifiers-parens
  789. - include: modifiers
  790. # Constructors and destructors don't have a type
  791. - match: '(?={{path_lookahead}}\s*::\s*{{identifier}}\s*(\(|$))'
  792. set:
  793. - meta_content_scope: meta.function.c++ entity.name.function.constructor.c++
  794. - include: identifiers
  795. - match: '(?=[^\w\s])'
  796. set: function-definition-params
  797. - match: '(?={{path_lookahead}}\s*::\s*~{{identifier}}\s*(\(|$))'
  798. set:
  799. - meta_content_scope: meta.function.c++ entity.name.function.destructor.c++
  800. - include: identifiers
  801. - match: '~{{identifier}}'
  802. - match: '(?=[^\w\s])'
  803. set: function-definition-params
  804. # If we see a path ending in :: before a newline, we don't know if it is
  805. # a constructor or destructor, or a long return type, so we are just going
  806. # to treat it like a regular function. Most likely it is a constructor,
  807. # since it doesn't seem most developers would create such a long typename.
  808. - match: '(?={{path_lookahead}}\s*::\s*$)'
  809. set:
  810. - meta_content_scope: meta.function.c++ entity.name.function.c++
  811. - include: identifiers
  812. - match: '~{{identifier}}'
  813. - match: '(?=[^\w\s])'
  814. set: function-definition-params
  815. - include: unique-strings
  816. - match: '(?=\S)'
  817. set: global-type
  818. global-type:
  819. - include: comments
  820. - match: \*|&
  821. scope: keyword.operator.c++
  822. - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}}|operator)\b)'
  823. pop: true
  824. - match: '(?=\s)'
  825. set: global-maybe-function
  826. # If a class/struct/enum followed by a name that is not a macro or declspec
  827. # then this is likely a return type of a function. This is uncommon.
  828. - match: |-
  829. (?x:
  830. ({{before_tag}})
  831. \s+
  832. (?=
  833. (?![[:upper:][:digit:]_]+\b|__declspec|{{before_tag}})
  834. {{path_lookahead}}
  835. (\s+{{identifier}}\s*\(|\s*[*&])
  836. )
  837. )
  838. captures:
  839. 1: storage.type.c++
  840. set:
  841. - include: identifiers
  842. - match: ''
  843. set: global-maybe-function
  844. # The previous match handles return types of struct/enum/etc from a func,
  845. # there this one exits the context to allow matching an actual struct/class
  846. - match: '(?=\b({{before_tag}})\b)'
  847. set: data-structures
  848. - match: '(?=\b({{casts}})\b\s*<)'
  849. pop: true
  850. - match: '{{non_angle_brackets}}'
  851. pop: true
  852. - include: angle-brackets
  853. - include: types
  854. # Allow a macro call
  855. - match: '({{identifier}})\s*(\()(?=[^\)]+\))'
  856. captures:
  857. 1: variable.function.c++
  858. 2: meta.group.c++ punctuation.section.group.begin.c++
  859. push:
  860. - meta_scope: meta.function-call.c++
  861. - meta_content_scope: meta.group.c++
  862. - match: '\)'
  863. scope: meta.group.c++ punctuation.section.group.end.c++
  864. pop: true
  865. - include: expressions
  866. - match: '(?={{path_lookahead}}\s*\()'
  867. set:
  868. - include: function-call
  869. - match: ''
  870. pop: true
  871. - include: variables
  872. - include: constants
  873. - include: identifiers
  874. - match: (?=\W)
  875. pop: true
  876. global-maybe-function:
  877. - include: comments
  878. # Consume pointer info, macros and any type info that was offset by macros
  879. - match: \*|&
  880. scope: keyword.operator.c++
  881. - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}})\b)'
  882. pop: true
  883. - match: '\b({{type_qualifier}})\b'
  884. scope: storage.modifier.c++
  885. - match: '{{non_angle_brackets}}'
  886. pop: true
  887. - include: angle-brackets
  888. - include: types
  889. - include: modifiers-parens
  890. - include: modifiers
  891. # All uppercase identifier just before a newline is most likely a macro
  892. - match: '[[:upper:][:digit:]_]+\s*$'
  893. # Operator overloading
  894. - match: '(?=({{path_lookahead}}\s*(?:{{generic_lookahead}})?::\s*)?{{operator_method_name}}\s*(\(|$))'
  895. set:
  896. - meta_content_scope: meta.function.c++ entity.name.function.c++
  897. - include: identifiers
  898. - match: '(?=\s*(\(|$))'
  899. set: function-definition-params
  900. # Identifier that is not the function name - likely a macro or type
  901. - match: '(?={{path_lookahead}}([ \t]+|[*&])(?!\s*(<|::|\(|$)))'
  902. push:
  903. - include: identifiers
  904. - match: ''
  905. pop: true
  906. # Real function definition
  907. - match: '(?={{path_lookahead}}({{generic_lookahead}}({{path_lookahead}})?)\s*(\(|$))'
  908. set: [function-definition-params, global-function-identifier-generic]
  909. - match: '(?={{path_lookahead}}\s*(\(|$))'
  910. set: [function-definition-params, global-function-identifier]
  911. - match: '(?={{path_lookahead}}\s*::\s*$)'
  912. set: [function-definition-params, global-function-identifier]
  913. - match: '(?=\S)'
  914. pop: true
  915. global-function-identifier-generic:
  916. - include: angle-brackets
  917. - match: '::'
  918. scope: punctuation.accessor.c++
  919. - match: '(?={{identifier}}<.*>\s*\()'
  920. push:
  921. - meta_content_scope: entity.name.function.c++
  922. - include: identifiers
  923. - match: '(?=<)'
  924. pop: true
  925. - match: '(?={{identifier}}\s*\()'
  926. push:
  927. - meta_content_scope: entity.name.function.c++
  928. - include: identifiers
  929. - match: ''
  930. pop: true
  931. - match: '(?=\()'
  932. pop: true
  933. global-function-identifier:
  934. - meta_content_scope: entity.name.function.c++
  935. - include: identifiers
  936. - match: '(?=\S)'
  937. pop: true
  938. function-definition-params:
  939. - meta_content_scope: meta.function.c++
  940. - include: comments
  941. - match: '(?=\()'
  942. set:
  943. - match: \(
  944. scope: meta.function.parameters.c++ meta.group.c++ punctuation.section.group.begin.c++
  945. set:
  946. - meta_content_scope: meta.function.parameters.c++ meta.group.c++
  947. - match : \)
  948. scope: punctuation.section.group.end.c++
  949. set: function-definition-continue
  950. - match: '\bvoid\b'
  951. scope: storage.type.c++
  952. - match: '{{identifier}}(?=\s*(\[|,|\)|=))'
  953. scope: variable.parameter.c++
  954. - match: '='
  955. scope: keyword.operator.assignment.c++
  956. push:
  957. - match: '(?=,|\))'
  958. pop: true
  959. - include: expressions-minus-generic-type
  960. - include: scope:source.c#preprocessor-line-continuation
  961. - include: expressions-minus-generic-type
  962. - include: scope:source.c#preprocessor-line-continuation
  963. - match: (?=\S)
  964. pop: true
  965. function-definition-continue:
  966. - meta_content_scope: meta.function.c++
  967. - include: comments
  968. - match: '(?=;)'
  969. pop: true
  970. - match: '->'
  971. scope: punctuation.separator.c++
  972. set: function-definition-trailing-return
  973. - include: function-specifiers
  974. - match: '='
  975. scope: keyword.operator.assignment.c++
  976. - match: '&'
  977. scope: keyword.operator.c++
  978. - match: \b0\b
  979. scope: constant.numeric.c++
  980. - match: \b(default|delete)\b
  981. scope: storage.modifier.c++
  982. - match: '(?=\{)'
  983. set: function-definition-body
  984. - match: '(?=\S)'
  985. pop: true
  986. function-definition-trailing-return:
  987. - include: comments
  988. - match: '(?=;)'
  989. pop: true
  990. - match: '(?=\{)'
  991. set: function-definition-body
  992. - include: function-specifiers
  993. - include: function-trailing-return-type
  994. function-definition-body:
  995. - meta_content_scope: meta.function.c++ meta.block.c++
  996. - match: '\{'
  997. scope: punctuation.section.block.begin.c++
  998. set:
  999. - meta_content_scope: meta.function.c++ meta.block.c++
  1000. - match: '\}'
  1001. scope: meta.function.c++ meta.block.c++ punctuation.section.block.end.c++
  1002. pop: true
  1003. - match: (?=^\s*#\s*(elif|else|endif)\b)
  1004. pop: true
  1005. - match: '(?=({{before_tag}})([^(;]+$|.*\{))'
  1006. push: data-structures
  1007. - include: statements
  1008. ## Data structures including classes, structs, unions and enums
  1009. data-structures:
  1010. - match: '\bclass\b'
  1011. scope: storage.type.c++
  1012. set: data-structures-class-definition
  1013. # Detect variable type definitions using struct/enum/union followed by a tag
  1014. - match: '\b({{before_tag}})(?=\s+{{path_lookahead}}\s+{{path_lookahead}}\s*[=;\[])'
  1015. scope: storage.type.c++
  1016. - match: '\bstruct\b'
  1017. scope: storage.type.c++
  1018. set: data-structures-struct-definition
  1019. - match: '\benum(\s+(class|struct))?\b'
  1020. scope: storage.type.c++
  1021. set: data-structures-enum-definition
  1022. - match: '\bunion\b'
  1023. scope: storage.type.c++
  1024. set: data-structures-union-definition
  1025. - match: '(?=\S)'
  1026. pop: true
  1027. preprocessor-workaround-eat-macro-before-identifier:
  1028. # Handle macros so they aren't matched as the class name
  1029. - match: ({{macro_identifier}})(?=\s+~?{{identifier}})
  1030. captures:
  1031. 1: meta.assumed-macro.c
  1032. data-structures-class-definition:
  1033. - meta_scope: meta.class.c++
  1034. - include: data-structures-definition-common-begin
  1035. - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})'
  1036. scope: entity.name.class.forward-decl.c++
  1037. set: data-structures-class-definition-after-identifier
  1038. - match: '{{identifier}}'
  1039. scope: entity.name.class.c++
  1040. set: data-structures-class-definition-after-identifier
  1041. - match: '(?=[:{])'
  1042. set: data-structures-class-definition-after-identifier
  1043. - match: '(?=;)'
  1044. pop: true
  1045. data-structures-class-definition-after-identifier:
  1046. - meta_content_scope: meta.class.c++
  1047. - include: data-structures-definition-common-begin
  1048. # No matching of identifiers since they should all be macros at this point
  1049. - include: data-structures-definition-common-end
  1050. - match: '\{'
  1051. scope: meta.block.c++ punctuation.section.block.begin.c++
  1052. set:
  1053. - meta_content_scope: meta.class.c++ meta.block.c++
  1054. - match: '\}'
  1055. scope: meta.class.c++ meta.block.c++ punctuation.section.block.end.c++
  1056. pop: true
  1057. - include: data-structures-body
  1058. data-structures-struct-definition:
  1059. - meta_scope: meta.struct.c++
  1060. - include: data-structures-definition-common-begin
  1061. - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})'
  1062. scope: entity.name.struct.forward-decl.c++
  1063. set: data-structures-struct-definition-after-identifier
  1064. - match: '{{identifier}}'
  1065. scope: entity.name.struct.c++
  1066. set: data-structures-struct-definition-after-identifier
  1067. - match: '(?=[:{])'
  1068. set: data-structures-struct-definition-after-identifier
  1069. - match: '(?=;)'
  1070. pop: true
  1071. data-structures-struct-definition-after-identifier:
  1072. - meta_content_scope: meta.struct.c++
  1073. - include: data-structures-definition-common-begin
  1074. # No matching of identifiers since they should all be macros at this point
  1075. - include: data-structures-definition-common-end
  1076. - match: '\{'
  1077. scope: meta.block.c++ punctuation.section.block.begin.c++
  1078. set:
  1079. - meta_content_scope: meta.struct.c++ meta.block.c++
  1080. - match: '\}'
  1081. scope: meta.struct.c++ meta.block.c++ punctuation.section.block.end.c++
  1082. pop: true
  1083. - include: data-structures-body
  1084. data-structures-enum-definition:
  1085. - meta_scope: meta.enum.c++
  1086. - include: data-structures-definition-common-begin
  1087. - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})'
  1088. scope: entity.name.enum.forward-decl.c++
  1089. set: data-structures-enum-definition-after-identifier
  1090. - match: '{{identifier}}'
  1091. scope: entity.name.enum.c++
  1092. set: data-structures-enum-definition-after-identifier
  1093. - match: '(?=[:{])'
  1094. set: data-structures-enum-definition-after-identifier
  1095. - match: '(?=;)'
  1096. pop: true
  1097. data-structures-enum-definition-after-identifier:
  1098. - meta_content_scope: meta.enum.c++
  1099. - include: data-structures-definition-common-begin
  1100. # No matching of identifiers since they should all be macros at this point
  1101. - include: data-structures-definition-common-end
  1102. - match: '\{'
  1103. scope: meta.block.c++ punctuation.section.block.begin.c++
  1104. set:
  1105. - meta_content_scope: meta.enum.c++ meta.block.c++
  1106. # Enums don't support methods so we have a simplified body
  1107. - match: '\}'
  1108. scope: meta.enum.c++ meta.block.c++ punctuation.section.block.end.c++
  1109. pop: true
  1110. - include: statements
  1111. data-structures-union-definition:
  1112. - meta_scope: meta.union.c++
  1113. - include: data-structures-definition-common-begin
  1114. - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})'
  1115. scope: entity.name.union.forward-decl.c++
  1116. set: data-structures-union-definition-after-identifier
  1117. - match: '{{identifier}}'
  1118. scope: entity.name.union.c++
  1119. set: data-structures-union-definition-after-identifier
  1120. - match: '(?=[{])'
  1121. set: data-structures-union-definition-after-identifier
  1122. - match: '(?=;)'
  1123. pop: true
  1124. data-structures-union-definition-after-identifier:
  1125. - meta_content_scope: meta.union.c++
  1126. - include: data-structures-definition-common-begin
  1127. # No matching of identifiers since they should all be macros at this point
  1128. # Unions don't support base classes
  1129. - include: angle-brackets
  1130. - match: '\{'
  1131. scope: meta.block.c++ punctuation.section.block.begin.c++
  1132. set:
  1133. - meta_content_scope: meta.union.c++ meta.block.c++
  1134. - match: '\}'
  1135. scope: meta.union.c++ meta.block.c++ punctuation.section.block.end.c++
  1136. pop: true
  1137. - include: data-structures-body
  1138. - match: '(?=;)'
  1139. pop: true
  1140. data-structures-definition-common-begin:
  1141. - include: comments
  1142. - match: '(?=\b(?:{{before_tag}}|{{control_keywords}})\b)'
  1143. pop: true
  1144. - include: preprocessor-other
  1145. - include: modifiers-parens
  1146. - include: modifiers
  1147. - include: preprocessor-workaround-eat-macro-before-identifier
  1148. data-structures-definition-common-end:
  1149. - include: angle-brackets
  1150. - match: \bfinal\b
  1151. scope: storage.modifier.c++
  1152. - match: ':'
  1153. scope: punctuation.separator.c++
  1154. push:
  1155. - include: comments
  1156. - include: preprocessor-other
  1157. - include: modifiers-parens
  1158. - include: modifiers
  1159. - match: '\b(virtual|{{visibility_modifiers}})\b'
  1160. scope: storage.modifier.c++
  1161. - match: (?={{path_lookahead}})
  1162. push:
  1163. - meta_scope: entity.other.inherited-class.c++
  1164. - include: identifiers
  1165. - match: ''
  1166. pop: true
  1167. - include: angle-brackets
  1168. - match: ','
  1169. scope: punctuation.separator.c++
  1170. - match: (?=\{|;)
  1171. pop: true
  1172. - match: '(?=;)'
  1173. pop: true
  1174. data-structures-body:
  1175. - include: preprocessor-data-structures
  1176. - match: '(?=\btemplate\b)'
  1177. push:
  1178. - include: template
  1179. - match: (?=\S)
  1180. set: data-structures-modifier
  1181. - include: typedef
  1182. - match: \b({{visibility_modifiers}})\s*(:)(?!:)
  1183. captures:
  1184. 1: storage.modifier.c++
  1185. 2: punctuation.section.class.c++
  1186. - match: '^\s*(?=(?:~?\w+|::))'
  1187. push: data-structures-modifier
  1188. - include: expressions-minus-generic-type
  1189. data-structures-modifier:
  1190. - match: '\bfriend\b'
  1191. scope: storage.modifier.c++
  1192. push:
  1193. - match: (?=;)
  1194. pop: true
  1195. - match: '\{'
  1196. scope: punctuation.section.block.begin.c++
  1197. set:
  1198. - meta_scope: meta.block.c++
  1199. - match: '\}'
  1200. scope: punctuation.section.block.end.c++
  1201. pop: true
  1202. - include: statements
  1203. - match: '\b({{before_tag}})\b'
  1204. scope: storage.type.c++
  1205. - include: expressions-minus-function-call
  1206. - include: comments
  1207. - include: modifiers-parens
  1208. - include: modifiers
  1209. - match: '\bstatic_assert(?=\s*\()'
  1210. scope: meta.static-assert.c++ keyword.operator.word.c++
  1211. push:
  1212. - match: '\('
  1213. scope: meta.group.c++ punctuation.section.group.begin.c++
  1214. set:
  1215. - meta_content_scope: meta.function-call.c++ meta.group.c++
  1216. - match: '\)'
  1217. scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++
  1218. pop: true
  1219. - include: expressions
  1220. # Destructor
  1221. - match: '(?:{{identifier}}\s*(::)\s*)?~{{identifier}}(?=\s*(\(|$))'
  1222. scope: meta.method.destructor.c++ entity.name.function.destructor.c++
  1223. captures:
  1224. 1: punctuation.accessor.c++
  1225. set: method-definition-params
  1226. # It's a macro, not a constructor if there is no type in the first param
  1227. - match: '({{identifier}})\s*(\()(?=\s*(?!void){{identifier}}\s*[),])'
  1228. captures:
  1229. 1: variable.function.c++
  1230. 2: meta.group.c++ punctuation.section.group.begin.c++
  1231. push:
  1232. - meta_scope: meta.function-call.c++
  1233. - meta_content_scope: meta.group.c++
  1234. - match: '\)'
  1235. scope: meta.group.c++ punctuation.section.group.end.c++
  1236. pop: true
  1237. - include: expressions
  1238. # Constructor
  1239. - include: preprocessor-workaround-eat-macro-before-identifier
  1240. - match: '((?!{{before_tag}}|template){{identifier}})(?=\s*\()'
  1241. scope: meta.method.constructor.c++ entity.name.function.constructor.c++
  1242. set: method-definition-params
  1243. # Long form constructor
  1244. - match: '({{identifier}}\s*(::)\s*{{identifier}})(?=\s*\()'
  1245. captures:
  1246. 1: meta.method.constructor.c++ entity.name.function.constructor.c++
  1247. 2: punctuation.accessor.c++
  1248. push: method-definition-params
  1249. - match: '(?=\S)'
  1250. set: data-structures-type
  1251. data-structures-type:
  1252. - include: comments
  1253. - match: \*|&
  1254. scope: keyword.operator.c++
  1255. # Cast methods
  1256. - match: '(operator)\s+({{identifier}})(?=\s*(\(|$))'
  1257. captures:
  1258. 1: keyword.control.c++
  1259. 2: meta.method.c++ entity.name.function.c++
  1260. set: method-definition-params
  1261. - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}}|operator)\b)'
  1262. pop: true
  1263. - match: '(?=\s)'
  1264. set: data-structures-maybe-method
  1265. # If a class/struct/enum followed by a name that is not a macro or declspec
  1266. # then this is likely a return type of a function. This is uncommon.
  1267. - match: |-
  1268. (?x:
  1269. ({{before_tag}})
  1270. \s+
  1271. (?=
  1272. (?![[:upper:][:digit:]_]+\b|__declspec|{{before_tag}})
  1273. {{path_lookahead}}
  1274. (\s+{{identifier}}\s*\(|\s*[*&])
  1275. )
  1276. )
  1277. captures:
  1278. 1: storage.type.c++
  1279. set:
  1280. - include: identifiers
  1281. - match: ''
  1282. set: data-structures-maybe-method
  1283. # The previous match handles return types of struct/enum/etc from a func,
  1284. # there this one exits the context to allow matching an actual struct/class
  1285. - match: '(?=\b({{before_tag}})\b)'
  1286. set: data-structures
  1287. - match: '(?=\b({{casts}})\b\s*<)'
  1288. pop: true
  1289. - match: '{{non_angle_brackets}}'
  1290. pop: true
  1291. - include: angle-brackets
  1292. - include: types
  1293. - include: variables
  1294. - include: constants
  1295. - include: identifiers
  1296. - match: (?=[&*])
  1297. set: data-structures-maybe-method
  1298. - match: (?=\W)
  1299. pop: true
  1300. data-structures-maybe-method:
  1301. - include: comments
  1302. # Consume pointer info, macros and any type info that was offset by macros
  1303. - match: \*|&
  1304. scope: keyword.operator.c++
  1305. - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}})\b)'
  1306. pop: true
  1307. - match: '\b({{type_qualifier}})\b'
  1308. scope: storage.modifier.c++
  1309. - match: '{{non_angle_brackets}}'
  1310. pop: true
  1311. - include: angle-brackets
  1312. - include: types
  1313. - include: modifiers-parens
  1314. - include: modifiers
  1315. # Operator overloading
  1316. - match: '{{operator_method_name}}(?=\s*(\(|$))'
  1317. scope: meta.method.c++ entity.name.function.c++
  1318. set: method-definition-params
  1319. # Identifier that is not the function name - likely a macro or type
  1320. - match: '(?={{path_lookahead}}([ \t]+|[*&])(?!\s*(<|::|\()))'
  1321. push:
  1322. - include: identifiers
  1323. - match: ''
  1324. pop: true
  1325. # Real function definition
  1326. - match: '(?={{path_lookahead}}({{generic_lookahead}})\s*(\())'
  1327. set: [method-definition-params, data-structures-function-identifier-generic]
  1328. - match: '(?={{path_lookahead}}\s*(\())'
  1329. set: [method-definition-params, data-structures-function-identifier]
  1330. - match: '(?={{path_lookahead}}\s*::\s*$)'
  1331. set: [method-definition-params, data-structures-function-identifier]
  1332. - match: '(?=\S)'
  1333. pop: true
  1334. data-structures-function-identifier-generic:
  1335. - include: angle-brackets
  1336. - match: '(?={{identifier}})'
  1337. push:
  1338. - meta_content_scope: entity.name.function.c++
  1339. - include: identifiers
  1340. - match: '(?=<)'
  1341. pop: true
  1342. - match: '(?=\()'
  1343. pop: true
  1344. data-structures-function-identifier:
  1345. - meta_content_scope: entity.name.function.c++
  1346. - include: identifiers
  1347. - match: '(?=\S)'
  1348. pop: true
  1349. method-definition-params:
  1350. - meta_content_scope: meta.method.c++
  1351. - include: comments
  1352. - match: '(?=\()'
  1353. set:
  1354. - match: \(
  1355. scope: meta.method.parameters.c++ meta.group.c++ punctuation.section.group.begin.c++
  1356. set:
  1357. - meta_content_scope: meta.method.parameters.c++ meta.group.c++
  1358. - match : \)
  1359. scope: punctuation.section.group.end.c++
  1360. set: method-definition-continue
  1361. - match: '\bvoid\b'
  1362. scope: storage.type.c++
  1363. - match: '{{identifier}}(?=\s*(\[|,|\)|=))'
  1364. scope: variable.parameter.c++
  1365. - match: '='
  1366. scope: keyword.operator.assignment.c++
  1367. push:
  1368. - match: '(?=,|\))'
  1369. pop: true
  1370. - include: expressions-minus-generic-type
  1371. - include: expressions-minus-generic-type
  1372. - match: '(?=\S)'
  1373. pop: true
  1374. method-definition-continue:
  1375. - meta_content_scope: meta.method.c++
  1376. - include: comments
  1377. - match: '(?=;)'
  1378. pop: true
  1379. - match: '->'
  1380. scope: punctuation.separator.c++
  1381. set: method-definition-trailing-return
  1382. - include: function-specifiers
  1383. - match: '='
  1384. scope: keyword.operator.assignment.c++
  1385. - match: '&'
  1386. scope: keyword.operator.c++
  1387. - match: \b0\b
  1388. scope: constant.numeric.c++
  1389. - match: \b(default|delete)\b
  1390. scope: storage.modifier.c++
  1391. - match: '(?=:)'
  1392. set:
  1393. - match: ':'
  1394. scope: punctuation.separator.initializer-list.c++
  1395. set:
  1396. - meta_scope: meta.method.constructor.initializer-list.c++
  1397. - match: '{{identifier}}'
  1398. scope: variable.other.readwrite.member.c++
  1399. push:
  1400. - match: \(
  1401. scope: meta.group.c++ punctuation.section.group.begin.c++
  1402. set:
  1403. - meta_content_scope: meta.group.c++
  1404. - match: \)
  1405. scope: meta.group.c++ punctuation.section.group.end.c++
  1406. pop: true
  1407. - include: expressions
  1408. - match: \{
  1409. scope: meta.group.c++ punctuation.section.group.begin.c++
  1410. set:
  1411. - meta_content_scope: meta.group.c++
  1412. - match: \}
  1413. scope: meta.group.c++ punctuation.section.group.end.c++
  1414. pop: true
  1415. - include: expressions
  1416. - include: comments
  1417. - match: (?=\{|;)
  1418. set: method-definition-continue
  1419. - include: expressions
  1420. - match: '(?=\{)'
  1421. set: method-definition-body
  1422. - match: '(?=\S)'
  1423. pop: true
  1424. method-definition-trailing-return:
  1425. - include: comments
  1426. - match: '(?=;)'
  1427. pop: true
  1428. - match: '(?=\{)'
  1429. set: method-definition-body
  1430. - include: function-specifiers
  1431. - include: function-trailing-return-type
  1432. method-definition-body:
  1433. - meta_content_scope: meta.method.c++ meta.block.c++
  1434. - match: '\{'
  1435. scope: punctuation.section.block.begin.c++
  1436. set:
  1437. - meta_content_scope: meta.method.c++ meta.block.c++
  1438. - match: '\}'
  1439. scope: meta.method.c++ meta.block.c++ punctuation.section.block.end.c++
  1440. pop: true
  1441. - match: (?=^\s*#\s*(elif|else|endif)\b)
  1442. pop: true
  1443. - match: '(?=({{before_tag}})([^(;]+$|.*\{))'
  1444. push: data-structures
  1445. - include: statements
  1446. ## Preprocessor for data-structures
  1447. preprocessor-data-structures:
  1448. - include: preprocessor-rule-enabled-data-structures
  1449. - include: preprocessor-rule-disabled-data-structures
  1450. - include: preprocessor-practical-workarounds
  1451. preprocessor-rule-disabled-data-structures:
  1452. - match: ^\s*((#if)\s+(0))\b
  1453. captures:
  1454. 1: meta.preprocessor.c++
  1455. 2: keyword.control.import.c++
  1456. 3: constant.numeric.preprocessor.c++
  1457. push:
  1458. - match: ^\s*(#\s*endif)\b
  1459. captures:
  1460. 1: meta.preprocessor.c++ keyword.control.import.c++
  1461. pop: true
  1462. - match: ^\s*(#\s*else)\b
  1463. captures:
  1464. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1465. push:
  1466. - match: (?=^\s*#\s*endif\b)
  1467. pop: true
  1468. - include: negated-block
  1469. - include: data-structures-body
  1470. - match: ""
  1471. push:
  1472. - meta_scope: comment.block.preprocessor.if-branch.c++
  1473. - match: (?=^\s*#\s*(else|endif)\b)
  1474. pop: true
  1475. - include: scope:source.c#preprocessor-disabled
  1476. preprocessor-rule-enabled-data-structures:
  1477. - match: ^\s*((#if)\s+(0*1))\b
  1478. captures:
  1479. 1: meta.preprocessor.c++
  1480. 2: keyword.control.import.c++
  1481. 3: constant.numeric.preprocessor.c++
  1482. push:
  1483. - match: ^\s*(#\s*endif)\b
  1484. captures:
  1485. 1: meta.preprocessor.c++ keyword.control.import.c++
  1486. pop: true
  1487. - match: ^\s*(#\s*else)\b
  1488. captures:
  1489. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1490. push:
  1491. - meta_content_scope: comment.block.preprocessor.else-branch.c++
  1492. - match: (?=^\s*#\s*endif\b)
  1493. pop: true
  1494. - include: scope:source.c#preprocessor-disabled
  1495. - match: ""
  1496. push:
  1497. - match: (?=^\s*#\s*(else|endif)\b)
  1498. pop: true
  1499. - include: negated-block
  1500. - include: data-structures-body
  1501. ## Preprocessor for global
  1502. preprocessor-global:
  1503. - include: preprocessor-rule-enabled-global
  1504. - include: preprocessor-rule-disabled-global
  1505. - include: preprocessor-rule-other-global
  1506. preprocessor-statements:
  1507. - include: preprocessor-rule-enabled-statements
  1508. - include: preprocessor-rule-disabled-statements
  1509. - include: preprocessor-rule-other-statements
  1510. preprocessor-expressions:
  1511. - include: scope:source.c#incomplete-inc
  1512. - include: preprocessor-macro-define
  1513. - include: scope:source.c#pragma-mark
  1514. - include: preprocessor-other
  1515. preprocessor-rule-disabled-global:
  1516. - match: ^\s*((#if)\s+(0))\b
  1517. captures:
  1518. 1: meta.preprocessor.c++
  1519. 2: keyword.control.import.c++
  1520. 3: constant.numeric.preprocessor.c++
  1521. push:
  1522. - match: ^\s*(#\s*endif)\b
  1523. captures:
  1524. 1: meta.preprocessor.c++ keyword.control.import.c++
  1525. pop: true
  1526. - match: ^\s*(#\s*else)\b
  1527. captures:
  1528. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1529. push:
  1530. - match: (?=^\s*#\s*endif\b)
  1531. pop: true
  1532. - include: preprocessor-global
  1533. - include: negated-block
  1534. - include: global
  1535. - match: ""
  1536. push:
  1537. - meta_scope: comment.block.preprocessor.if-branch.c++
  1538. - match: (?=^\s*#\s*(else|endif)\b)
  1539. pop: true
  1540. - include: scope:source.c#preprocessor-disabled
  1541. preprocessor-rule-enabled-global:
  1542. - match: ^\s*((#if)\s+(0*1))\b
  1543. captures:
  1544. 1: meta.preprocessor.c++
  1545. 2: keyword.control.import.c++
  1546. 3: constant.numeric.preprocessor.c++
  1547. push:
  1548. - match: ^\s*(#\s*endif)\b
  1549. captures:
  1550. 1: meta.preprocessor.c++ keyword.control.import.c++
  1551. pop: true
  1552. - match: ^\s*(#\s*else)\b
  1553. captures:
  1554. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1555. push:
  1556. - meta_content_scope: comment.block.preprocessor.else-branch.c++
  1557. - match: (?=^\s*#\s*endif\b)
  1558. pop: true
  1559. - include: scope:source.c#preprocessor-disabled
  1560. - match: ""
  1561. push:
  1562. - match: (?=^\s*#\s*(else|endif)\b)
  1563. pop: true
  1564. - include: preprocessor-global
  1565. - include: negated-block
  1566. - include: global
  1567. preprocessor-rule-other-global:
  1568. - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b
  1569. captures:
  1570. 1: keyword.control.import.c++
  1571. push:
  1572. - meta_scope: meta.preprocessor.c++
  1573. - include: scope:source.c#preprocessor-line-continuation
  1574. - include: scope:source.c#preprocessor-comments
  1575. - match: \bdefined\b
  1576. scope: keyword.control.c++
  1577. # Enter a new scope where all elif/else branches have their
  1578. # contexts popped by a subsequent elif/else/endif. This ensures that
  1579. # preprocessor branches don't push multiple meta.block scopes on
  1580. # the stack, thus messing up the "global" context's detection of
  1581. # functions.
  1582. - match: $\n
  1583. set: preprocessor-if-branch-global
  1584. # These gymnastics here ensure that we are properly handling scope even
  1585. # when the preprocessor is used to create different scope beginnings, such
  1586. # as a different if/while condition
  1587. preprocessor-if-branch-global:
  1588. - match: ^\s*(#\s*endif)\b
  1589. captures:
  1590. 1: meta.preprocessor.c++ keyword.control.import.c++
  1591. pop: true
  1592. - match: (?=^\s*#\s*(elif|else)\b)
  1593. push: preprocessor-elif-else-branch-global
  1594. - match: \{
  1595. scope: punctuation.section.block.begin.c++
  1596. set: preprocessor-block-if-branch-global
  1597. - include: preprocessor-global
  1598. - include: negated-block
  1599. - include: global
  1600. preprocessor-block-if-branch-global:
  1601. - meta_scope: meta.block.c++
  1602. - match: ^\s*(#\s*endif)\b
  1603. captures:
  1604. 1: meta.preprocessor.c++ keyword.control.import.c++
  1605. set: preprocessor-block-finish-global
  1606. - match: (?=^\s*#\s*(elif|else)\b)
  1607. push: preprocessor-elif-else-branch-global
  1608. - match: \}
  1609. scope: punctuation.section.block.end.c++
  1610. set: preprocessor-if-branch-global
  1611. - include: statements
  1612. preprocessor-block-finish-global:
  1613. - meta_scope: meta.block.c++
  1614. - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b
  1615. captures:
  1616. 1: meta.preprocessor.c++ keyword.control.import.c++
  1617. set: preprocessor-block-finish-if-branch-global
  1618. - match: \}
  1619. scope: punctuation.section.block.end.c++
  1620. pop: true
  1621. - include: statements
  1622. preprocessor-block-finish-if-branch-global:
  1623. - match: ^\s*(#\s*endif)\b
  1624. captures:
  1625. 1: keyword.control.import.c++
  1626. pop: true
  1627. - match: \}
  1628. scope: punctuation.section.block.end.c++
  1629. set: preprocessor-if-branch-global
  1630. - include: statements
  1631. preprocessor-elif-else-branch-global:
  1632. - match: (?=^\s*#\s*(endif)\b)
  1633. pop: true
  1634. - include: preprocessor-global
  1635. - include: negated-block
  1636. - include: global
  1637. ## Preprocessor for statements
  1638. preprocessor-rule-disabled-statements:
  1639. - match: ^\s*((#if)\s+(0))\b
  1640. captures:
  1641. 1: meta.preprocessor.c++
  1642. 2: keyword.control.import.c++
  1643. 3: constant.numeric.preprocessor.c++
  1644. push:
  1645. - match: ^\s*(#\s*endif)\b
  1646. captures:
  1647. 1: meta.preprocessor.c++ keyword.control.import.c++
  1648. pop: true
  1649. - match: ^\s*(#\s*else)\b
  1650. captures:
  1651. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1652. push:
  1653. - match: (?=^\s*#\s*endif\b)
  1654. pop: true
  1655. - include: negated-block
  1656. - include: statements
  1657. - match: ""
  1658. push:
  1659. - meta_scope: comment.block.preprocessor.if-branch.c++
  1660. - match: (?=^\s*#\s*(else|endif)\b)
  1661. pop: true
  1662. - include: scope:source.c#preprocessor-disabled
  1663. preprocessor-rule-enabled-statements:
  1664. - match: ^\s*((#if)\s+(0*1))\b
  1665. captures:
  1666. 1: meta.preprocessor.c++
  1667. 2: keyword.control.import.c++
  1668. 3: constant.numeric.preprocessor.c++
  1669. push:
  1670. - match: ^\s*(#\s*endif)\b
  1671. captures:
  1672. 1: meta.preprocessor.c++ keyword.control.import.c++
  1673. pop: true
  1674. - match: ^\s*(#\s*else)\b
  1675. captures:
  1676. 1: meta.preprocessor.c++ keyword.control.import.else.c++
  1677. push:
  1678. - meta_content_scope: comment.block.preprocessor.else-branch.c++
  1679. - match: (?=^\s*#\s*endif\b)
  1680. pop: true
  1681. - include: scope:source.c#preprocessor-disabled
  1682. - match: ""
  1683. push:
  1684. - match: (?=^\s*#\s*(else|endif)\b)
  1685. pop: true
  1686. - include: negated-block
  1687. - include: statements
  1688. preprocessor-rule-other-statements:
  1689. - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b
  1690. captures:
  1691. 1: keyword.control.import.c++
  1692. push:
  1693. - meta_scope: meta.preprocessor.c++
  1694. - include: scope:source.c#preprocessor-line-continuation
  1695. - include: scope:source.c#preprocessor-comments
  1696. - match: \bdefined\b
  1697. scope: keyword.control.c++
  1698. # Enter a new scope where all elif/else branches have their
  1699. # contexts popped by a subsequent elif/else/endif. This ensures that
  1700. # preprocessor branches don't push multiple meta.block scopes on
  1701. # the stack, thus messing up the "global" context's detection of
  1702. # functions.
  1703. - match: $\n
  1704. set: preprocessor-if-branch-statements
  1705. # These gymnastics here ensure that we are properly handling scope even
  1706. # when the preprocessor is used to create different scope beginnings, such
  1707. # as a different if/while condition
  1708. preprocessor-if-branch-statements:
  1709. - match: ^\s*(#\s*endif)\b
  1710. captures:
  1711. 1: meta.preprocessor.c++ keyword.control.import.c++
  1712. pop: true
  1713. - match: (?=^\s*#\s*(elif|else)\b)
  1714. push: preprocessor-elif-else-branch-statements
  1715. - match: \{
  1716. scope: punctuation.section.block.begin.c++
  1717. set: preprocessor-block-if-branch-statements
  1718. - match: (?=(?!{{non_func_keywords}}){{path_lookahead}}\s*\()
  1719. set: preprocessor-if-branch-function-call
  1720. - include: negated-block
  1721. - include: statements
  1722. preprocessor-if-branch-function-call:
  1723. - meta_content_scope: meta.function-call.c++
  1724. - include: scope:source.c#c99
  1725. - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*'
  1726. scope: variable.function.c++
  1727. captures:
  1728. 1: punctuation.accessor.c++
  1729. 2: punctuation.accessor.c++
  1730. - match: '(?:(::)\s*)?{{identifier}}'
  1731. scope: variable.function.c++
  1732. captures:
  1733. 1: punctuation.accessor.c++
  1734. - match: '\('
  1735. scope: meta.group.c++ punctuation.section.group.begin.c++
  1736. set: preprocessor-if-branch-function-call-arguments
  1737. preprocessor-if-branch-function-call-arguments:
  1738. - meta_content_scope: meta.function-call.c++ meta.group.c++
  1739. - match : \)
  1740. scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++
  1741. set: preprocessor-if-branch-statements
  1742. - match: ^\s*(#\s*(?:elif|else))\b
  1743. captures:
  1744. 1: meta.preprocessor.c++ keyword.control.import.c++
  1745. set: preprocessor-if-branch-statements
  1746. - match: ^\s*(#\s*endif)\b
  1747. captures:
  1748. 1: meta.preprocessor.c++ keyword.control.import.c++
  1749. set: preprocessor-if-branch-function-call-arguments-finish
  1750. - include: expressions
  1751. preprocessor-if-branch-function-call-arguments-finish:
  1752. - meta_content_scope: meta.function-call.c++ meta.group.c++
  1753. - match: \)
  1754. scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++
  1755. pop: true
  1756. - include: expressions
  1757. preprocessor-block-if-branch-statements:
  1758. - meta_scope: meta.block.c++
  1759. - match: ^\s*(#\s*endif)\b
  1760. captures:
  1761. 1: meta.preprocessor.c++ keyword.control.import.c++
  1762. set: preprocessor-block-finish-statements
  1763. - match: (?=^\s*#\s*(elif|else)\b)
  1764. push: preprocessor-elif-else-branch-statements
  1765. - match: \}
  1766. scope: punctuation.section.block.end.c++
  1767. set: preprocessor-if-branch-statements
  1768. - include: statements
  1769. preprocessor-block-finish-statements:
  1770. - meta_scope: meta.block.c++
  1771. - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b
  1772. captures:
  1773. 1: meta.preprocessor.c++ keyword.control.import.c++
  1774. set: preprocessor-block-finish-if-branch-statements
  1775. - match: \}
  1776. scope: punctuation.section.block.end.c++
  1777. pop: true
  1778. - include: statements
  1779. preprocessor-block-finish-if-branch-statements:
  1780. - match: ^\s*(#\s*endif)\b
  1781. captures:
  1782. 1: keyword.control.import.c++
  1783. pop: true
  1784. - match: \}
  1785. scope: meta.block.c++ punctuation.section.block.end.c++
  1786. set: preprocessor-if-branch-statements
  1787. - include: statements
  1788. preprocessor-elif-else-branch-statements:
  1789. - match: (?=^\s*#\s*endif\b)
  1790. pop: true
  1791. - include: negated-block
  1792. - include: statements
  1793. ## Preprocessor other
  1794. negated-block:
  1795. - match: '\}'
  1796. scope: punctuation.section.block.end.c++
  1797. push:
  1798. - match: '\{'
  1799. scope: punctuation.section.block.begin.c++
  1800. pop: true
  1801. - match: (?=^\s*#\s*(elif|else|endif)\b)
  1802. pop: true
  1803. - include: statements
  1804. preprocessor-macro-define:
  1805. - match: ^\s*(\#\s*define)\b
  1806. captures:
  1807. 1: meta.preprocessor.macro.c++ keyword.control.import.define.c++
  1808. push:
  1809. - meta_content_scope: meta.preprocessor.macro.c++
  1810. - include: scope:source.c#preprocessor-line-continuation
  1811. - include: scope:source.c#preprocessor-line-ending
  1812. - include: scope:source.c#preprocessor-comments
  1813. - match: '({{identifier}})(?=\()'
  1814. scope: entity.name.function.preprocessor.c++
  1815. set:
  1816. - match: '\('
  1817. scope: punctuation.section.group.begin.c++
  1818. set: preprocessor-macro-params
  1819. - match: '{{identifier}}'
  1820. scope: entity.name.constant.preprocessor.c++
  1821. set: preprocessor-macro-definition
  1822. preprocessor-macro-params:
  1823. - meta_scope: meta.preprocessor.macro.parameters.c++ meta.group.c++
  1824. - match: '{{identifier}}'
  1825. scope: variable.parameter.c++
  1826. - match: \)
  1827. scope: punctuation.section.group.end.c++
  1828. set: preprocessor-macro-definition
  1829. - match: ','
  1830. scope: punctuation.separator.c++
  1831. push:
  1832. - match: '{{identifier}}'
  1833. scope: variable.parameter.c++
  1834. pop: true
  1835. - include: scope:source.c#preprocessor-line-continuation
  1836. - include: scope:source.c#preprocessor-comments
  1837. - match: '\.\.\.'
  1838. scope: keyword.operator.variadic.c++
  1839. - match: '(?=\))'
  1840. pop: true
  1841. - match: (/\*).*(\*/)
  1842. scope: comment.block.c++
  1843. captures:
  1844. 1: punctuation.definition.comment.c++
  1845. 2: punctuation.definition.comment.c++
  1846. - match: '\S+'
  1847. scope: invalid.illegal.unexpected-character.c++
  1848. - include: scope:source.c#preprocessor-line-continuation
  1849. - include: scope:source.c#preprocessor-comments
  1850. - match: '\.\.\.'
  1851. scope: keyword.operator.variadic.c++
  1852. - match: (/\*).*(\*/)
  1853. scope: comment.block.c++
  1854. captures:
  1855. 1: punctuation.definition.comment.c++
  1856. 2: punctuation.definition.comment.c++
  1857. - match: $\n
  1858. scope: invalid.illegal.unexpected-end-of-line.c++
  1859. preprocessor-macro-definition:
  1860. - meta_content_scope: meta.preprocessor.macro.c++
  1861. - include: scope:source.c#preprocessor-line-continuation
  1862. - include: scope:source.c#preprocessor-line-ending
  1863. - include: scope:source.c#preprocessor-comments
  1864. # Don't define blocks in define statements
  1865. - match: '\{'
  1866. scope: punctuation.section.block.begin.c++
  1867. - match: '\}'
  1868. scope: punctuation.section.block.end.c++
  1869. - include: expressions
  1870. preprocessor-practical-workarounds:
  1871. - include: preprocessor-convention-ignore-uppercase-ident-lines
  1872. - include: scope:source.c#preprocessor-convention-ignore-uppercase-calls-without-semicolon
  1873. preprocessor-convention-ignore-uppercase-ident-lines:
  1874. - match: ^(\s*{{macro_identifier}})+\s*$
  1875. scope: meta.assumed-macro.c++
  1876. push:
  1877. # It's possible that we are dealing with a function return type on its own line, and the
  1878. # name of the function is on the subsequent line.
  1879. - match: '(?={{path_lookahead}}({{generic_lookahead}}({{path_lookahead}})?)\s*\()'
  1880. set: [function-definition-params, global-function-identifier-generic]
  1881. - match: '(?={{path_lookahead}}\s*\()'
  1882. set: [function-definition-params, global-function-identifier]
  1883. - match: ^
  1884. pop: true
  1885. preprocessor-other:
  1886. - match: ^\s*(#\s*(?:if|ifdef|ifndef|elif|else|line|pragma|undef))\b
  1887. captures:
  1888. 1: keyword.control.import.c++
  1889. push:
  1890. - meta_scope: meta.preprocessor.c++
  1891. - include: scope:source.c#preprocessor-line-continuation
  1892. - include: scope:source.c#preprocessor-line-ending
  1893. - include: scope:source.c#preprocessor-comments
  1894. - match: \bdefined\b
  1895. scope: keyword.control.c++
  1896. - match: ^\s*(#\s*endif)\b
  1897. captures:
  1898. 1: meta.preprocessor.c++ keyword.control.import.c++
  1899. - match: ^\s*(#\s*(?:error|warning))\b
  1900. captures:
  1901. 1: keyword.control.import.error.c++
  1902. push:
  1903. - meta_scope: meta.preprocessor.diagnostic.c++
  1904. - include: scope:source.c#preprocessor-line-continuation
  1905. - include: scope:source.c#preprocessor-line-ending
  1906. - include: scope:source.c#preprocessor-comments
  1907. - include: strings
  1908. - match: '\S+'
  1909. scope: string.unquoted.c++
  1910. - match: ^\s*(#\s*(?:include|include_next|import))\b
  1911. captures:
  1912. 1: keyword.control.import.include.c++
  1913. push:
  1914. - meta_scope: meta.preprocessor.include.c++
  1915. - include: scope:source.c#preprocessor-line-continuation
  1916. - include: scope:source.c#preprocessor-line-ending
  1917. - include: scope:source.c#preprocessor-comments
  1918. - match: '"'
  1919. scope: punctuation.definition.string.begin.c++
  1920. push:
  1921. - meta_scope: string.quoted.double.include.c++
  1922. - match: '"'
  1923. scope: punctuation.definition.string.end.c++
  1924. pop: true
  1925. - match: <
  1926. scope: punctuation.definition.string.begin.c++
  1927. push:
  1928. - meta_scope: string.quoted.other.lt-gt.include.c++
  1929. - match: '>'
  1930. scope: punctuation.definition.string.end.c++
  1931. pop: true
  1932. - include: preprocessor-practical-workarounds