prismjs_components_prism-c.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // node_modules/prismjs/components/prism-c.js
  2. Prism.languages.c = Prism.languages.extend("clike", {
  3. "comment": {
  4. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  5. greedy: true
  6. },
  7. "string": {
  8. // https://en.cppreference.com/w/c/language/string_literal
  9. pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
  10. greedy: true
  11. },
  12. "class-name": {
  13. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  14. lookbehind: true
  15. },
  16. "keyword": /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
  17. "function": /\b[a-z_]\w*(?=\s*\()/i,
  18. "number": /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  19. "operator": />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  20. });
  21. Prism.languages.insertBefore("c", "string", {
  22. "char": {
  23. // https://en.cppreference.com/w/c/language/character_constant
  24. pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
  25. greedy: true
  26. }
  27. });
  28. Prism.languages.insertBefore("c", "string", {
  29. "macro": {
  30. // allow for multiline macro definitions
  31. // spaces after the # character compile fine with gcc
  32. pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  33. lookbehind: true,
  34. greedy: true,
  35. alias: "property",
  36. inside: {
  37. "string": [
  38. {
  39. // highlight the path of the include statement as a string
  40. pattern: /^(#\s*include\s*)<[^>]+>/,
  41. lookbehind: true
  42. },
  43. Prism.languages.c["string"]
  44. ],
  45. "char": Prism.languages.c["char"],
  46. "comment": Prism.languages.c["comment"],
  47. "macro-name": [
  48. {
  49. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  50. lookbehind: true
  51. },
  52. {
  53. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  54. lookbehind: true,
  55. alias: "function"
  56. }
  57. ],
  58. // highlight macro directives as keywords
  59. "directive": {
  60. pattern: /^(#\s*)[a-z]+/,
  61. lookbehind: true,
  62. alias: "keyword"
  63. },
  64. "directive-hash": /^#/,
  65. "punctuation": /##|\\(?=[\r\n])/,
  66. "expression": {
  67. pattern: /\S[\s\S]*/,
  68. inside: Prism.languages.c
  69. }
  70. }
  71. }
  72. });
  73. Prism.languages.insertBefore("c", "function", {
  74. // highlight predefined macros as constants
  75. "constant": /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
  76. });
  77. delete Prism.languages.c["boolean"];
  78. //# sourceMappingURL=prismjs_components_prism-c.js.map