syntax.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include "header.h"
  2. /* Syntax Highlighting is kinda goofy and no where near advanced.
  3. The goal isn't to be advanced but to give your eyes a little bit
  4. of contrast.
  5. Firstly, you can highlight keywords such as "if" or "else". Then,
  6. you give it the color you want it to be. The general rule of thumb
  7. is that functions, methods, macros, or statements are given the ID
  8. of ID_FUNCTION. Varible, types, and other defining syntax is given
  9. ID_SYMBOL. Secondary type definitions such as "long" in C or
  10. "default" in JS are generally given TB_DIGIT. Contants such as
  11. NULL, null, true/false, etc. are given ID_CONSTANT.
  12. This is very much still a work in progress.
  13. TODO:
  14. - , to end of line
  15. */
  16. syntax_t csyn[] = {
  17. {"<>", ID_DIGITS},
  18. {"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  19. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  20. {"void", ID_SYMBOL}, {"#", ID_FUNCTION}, {"int", ID_SYMBOL}, {"enum", ID_SYMBOL},
  21. {"char", ID_SYMBOL}, {"const", ID_DIGITS}, {"unsigned", ID_DIGITS}, {"static", ID_DIGITS},
  22. {"assert", ID_FUNCTION}, {"break", ID_FUNCTION}, {"switch", ID_FUNCTION},
  23. {"continue", ID_FUNCTION},
  24. {"case", ID_FUNCTION}, {"NULL", ID_CONSTANT}, {"long", ID_DIGITS}, {"struct", ID_DIGITS},
  25. {"typedef", ID_SYMBOL}, {"_t", ID_SYMBOL},
  26. {"TRUE", ID_CONSTANT}, {"FALSE", ID_CONSTANT}, {NULL}};
  27. syntax_t htmlsyn[] = {
  28. {"<>", ID_DEFAULT}, {"</>", ID_DEFAULT},
  29. {"</>", ID_FUNCTION}, {"</>", ID_FUNCTION},
  30. {"<>", ID_FUNCTION}, {"<", ID_FUNCTION}, {NULL}
  31. };
  32. syntax_t jssyn[] = {{"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  33. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  34. {"const", ID_SYMBOL}, {"let", ID_SYMBOL}, {"var", ID_SYMBOL},
  35. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION}, {"export", ID_FUNCTION},
  36. {"typeof", ID_FUNCTION}, {"case", ID_FUNCTION}, {"null", ID_CONSTANT},
  37. {"import", ID_FUNCTION}, {"from", ID_SYMBOL}, {"default", ID_DIGITS},
  38. {"undefined", ID_CONSTANT}, {"true", ID_CONSTANT}, {"false", ID_CONSTANT},
  39. {"function", ID_SYMBOL}, {"new", ID_DIGITS}, {"try", ID_FUNCTION},
  40. {"catch", ID_FUNCTION}, {"finally", ID_FUNCTION}, {"async", ID_DIGITS},
  41. {"await", ID_DIGITS},
  42. {NULL}};
  43. syntax_t tssyn[] = {
  44. {"interface", ID_FUNCTION}, {"type", ID_FUNCTION}, {"as", ID_DIGITS},
  45. // below is the same as jssyn
  46. {"if", ID_FUNCTION}, {"else", ID_FUNCTION},
  47. {"for", ID_FUNCTION},
  48. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  49. {"const", ID_SYMBOL}, {"let", ID_SYMBOL}, {"var", ID_SYMBOL},
  50. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION}, {"export", ID_FUNCTION},
  51. {"typeof", ID_FUNCTION}, {"case", ID_FUNCTION}, {"null", ID_CONSTANT},
  52. {"import", ID_FUNCTION}, {"from", ID_SYMBOL}, {"default", ID_DIGITS},
  53. {"undefined", ID_CONSTANT}, {"true", ID_CONSTANT}, {"false", ID_CONSTANT},
  54. {"function", ID_SYMBOL}, {"new", ID_DIGITS}, {"try", ID_FUNCTION},
  55. {"catch", ID_FUNCTION}, {"finally", ID_FUNCTION}, {"async", ID_DIGITS},
  56. {"await", ID_DIGITS},
  57. {NULL}};
  58. syntax_t jsxsyn[] = {
  59. // below is the same as htmlsyn
  60. {"<>", ID_DEFAULT}, {"</>", ID_DEFAULT},
  61. {"</>", ID_FUNCTION}, {"</>", ID_FUNCTION},
  62. {"<>", ID_FUNCTION}, {"<", ID_FUNCTION},
  63. // below is the same as jssyn
  64. {"if", ID_FUNCTION}, {"else", ID_FUNCTION},
  65. {"for", ID_FUNCTION},
  66. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  67. {"const", ID_SYMBOL}, {"let", ID_SYMBOL}, {"var", ID_SYMBOL},
  68. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION}, {"export", ID_FUNCTION},
  69. {"typeof", ID_FUNCTION}, {"case", ID_FUNCTION}, {"null", ID_CONSTANT},
  70. {"import", ID_FUNCTION}, {"from", ID_SYMBOL}, {"default", ID_DIGITS},
  71. {"undefined", ID_CONSTANT}, {"true", ID_CONSTANT}, {"false", ID_CONSTANT},
  72. {"function", ID_SYMBOL}, {"new", ID_DIGITS}, {"try", ID_FUNCTION},
  73. {"catch", ID_FUNCTION}, {"finally", ID_FUNCTION}, {"async", ID_DIGITS},
  74. {"await", ID_DIGITS},
  75. {NULL}};
  76. syntax_t tsxsyn[] = {
  77. // below is the same as htmlsyn
  78. {"<>", ID_DEFAULT}, {"</>", ID_DEFAULT},
  79. {"</>", ID_FUNCTION}, {"</>", ID_FUNCTION},
  80. {"<>", ID_FUNCTION}, {"<", ID_FUNCTION},
  81. // below is the same as tssyn
  82. {"interface", ID_FUNCTION}, {"type", ID_FUNCTION}, {"as", ID_DIGITS},
  83. // below is the same as jssyn
  84. {"if", ID_FUNCTION}, {"else", ID_FUNCTION},
  85. {"for", ID_FUNCTION},
  86. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  87. {"const", ID_SYMBOL}, {"let", ID_SYMBOL}, {"var", ID_SYMBOL},
  88. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION}, {"export", ID_FUNCTION},
  89. {"typeof", ID_FUNCTION}, {"case", ID_FUNCTION}, {"null", ID_CONSTANT},
  90. {"import", ID_FUNCTION}, {"from", ID_SYMBOL}, {"default", ID_DIGITS},
  91. {"undefined", ID_CONSTANT}, {"true", ID_CONSTANT}, {"false", ID_CONSTANT},
  92. {"function", ID_SYMBOL}, {"new", ID_DIGITS}, {"try", ID_FUNCTION},
  93. {"catch", ID_FUNCTION}, {"finally", ID_FUNCTION}, {"async", ID_DIGITS},
  94. {"await", ID_DIGITS},
  95. {NULL}};
  96. syntax_t awksyn[] = {{"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  97. {"return", ID_FUNCTION}, {"while", ID_FUNCTION}, {"BEGIN", ID_FUNCTION},
  98. {"END", ID_FUNCTION},
  99. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION},
  100. {"case", ID_FUNCTION}, {"NULL", ID_CONSTANT},{"TRUE", ID_CONSTANT},
  101. {"FALSE", ID_CONSTANT}, {NULL}};
  102. syntax_t mdsyn[] = {
  103. {"__", ID_CONSTANT}, {"**", ID_FUNCTION},
  104. {NULL}};
  105. syntax_t luasyn[] = {
  106. {"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  107. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  108. {"local", ID_SYMBOL},
  109. {"assert", ID_FUNCTION}, {"break", ID_FUNCTION}, {"switch", ID_FUNCTION},
  110. {"continue", ID_FUNCTION}, {"function", ID_FUNCTION}, {"end", ID_FUNCTION},
  111. {"case", ID_FUNCTION}, {"nil", ID_CONSTANT}, {"then", ID_SYMBOL},
  112. {"true", ID_CONSTANT}, {"false", ID_CONSTANT}, {NULL}};
  113. /* TODO for haskell:
  114. foreign
  115. hiding
  116. infix, infixl, infixr
  117. mdo
  118. newtype
  119. proc
  120. rec
  121. type
  122. type family
  123. type instance
  124. */
  125. syntax_t hssyn[]= {
  126. {"as", ID_DIGITS}, {"case", ID_FUNCTION}, {"of", ID_DIGITS}, {"class", ID_FUNCTION},
  127. {"data family", ID_SYMBOL}, {"data instance", ID_SYMBOL}, {"data", ID_SYMBOL},
  128. {"default", ID_DIGITS}, {"deriving instance", ID_SYMBOL}, {"deriving", ID_SYMBOL},
  129. {"do", ID_FUNCTION}, {"forall", ID_SYMBOL}, {"if", ID_FUNCTION}, {"else", ID_FUNCTION},
  130. {"then", ID_DIGITS}, {"module", ID_FUNCTION}, {"where", ID_FUNCTION},
  131. {"import", ID_FUNCTION}, {"qualified", ID_DIGITS}, {"let", ID_FUNCTION},
  132. {"in", ID_DIGITS}, {"instance", ID_FUNCTION},
  133. {NULL}};
  134. /* WIP */
  135. syntax_t datsyn[] = {
  136. {"-$", ID_FUNCTION}, {NULL},
  137. };
  138. /* WIP */
  139. syntax_t sqlsyn[] = {
  140. {"SELECT", ID_FUNCTION}, {"select", ID_FUNCTION}, {"FROM", ID_FUNCTION}, {"from", ID_FUNCTION},
  141. {"WHERE", ID_FUNCTION}, {"where", ID_FUNCTION}, {"ORDER BY", ID_FUNCTION}, {"order BY", ID_FUNCTION},
  142. {"GROUP BY", ID_FUNCTION}, {"group BY", ID_FUNCTION}, {"HAVING", ID_DIGITS}, {"having", ID_DIGITS},
  143. {"INSERT INTO", ID_FUNCTION}, {"insert into", ID_FUNCTION},
  144. {"UPDATE", ID_FUNCTION}, {"update", ID_FUNCTION}, {"DELETE", ID_FUNCTION}, {"delete", ID_FUNCTION},
  145. {"CREATE", ID_FUNCTION}, {"create", ID_FUNCTION}, {"ALTER", ID_FUNCTION}, {"alter", ID_FUNCTION},
  146. {"JOIN", ID_SYMBOL}, {"join", ID_SYMBOL}, {"UNION", ID_FUNCTION}, {"union", ID_FUNCTION},
  147. {"LIKE", ID_FUNCTION}, {"like", ID_FUNCTION}, {"IN", ID_DIGITS}, {"in", ID_DIGITS},
  148. {"EXISTS", ID_DIGITS}, {"exists", ID_DIGITS}, {"NOT", ID_FUNCTION}, {"not", ID_FUNCTION},
  149. {"AND", ID_FUNCTION}, {"and", ID_FUNCTION}, {"OR", ID_FUNCTION}, {"or", ID_FUNCTION},
  150. {"BETWEEN", ID_FUNCTION}, {"between", ID_FUNCTION}, {"DISTINCT", ID_DIGITS}, {"distinct", ID_DIGITS},
  151. {"NULL", ID_CONSTANT}, {"null", ID_CONSTANT}, {"COUNT", ID_FUNCTION}, {"count", ID_FUNCTION},
  152. {"SUM", ID_FUNCTION}, {"sum", ID_FUNCTION}, {"AVG", ID_FUNCTION}, {"avg", ID_FUNCTION},
  153. {"MIN", ID_FUNCTION}, {"min", ID_FUNCTION}, {"MAX", ID_FUNCTION}, {"max", ID_FUNCTION},
  154. {"AS", ID_DIGITS}, {"as", ID_DIGITS}, {"IF", ID_FUNCTION}, {"if", ID_FUNCTION},
  155. {"SET", ID_FUNCTION}, {"set", ID_FUNCTION}, {"ADD", ID_FUNCTION}, {"add", ID_FUNCTION},
  156. {"FALSE", ID_CONSTANT}, {"false", ID_CONSTANT}, {"TRUE", ID_CONSTANT}, {"true", ID_CONSTANT},
  157. {NULL}
  158. };
  159. /* list of keywords _must_ end with NULL */
  160. keywords_t keywords[] = {
  161. /* programming */
  162. {".c", "//", "/*", "*/", FALSE, FALSE, csyn},
  163. {".h", "//", "/*", "*/", FALSE, FALSE, csyn},
  164. {".css", "//", "/*", "*/", FALSE, FALSE, NULL},
  165. {".html", "", "<!--", "-->", FALSE, FALSE, htmlsyn},
  166. {".js", "//", "/*", "*/", TRUE, TRUE, jssyn},
  167. {".jsx", "//", "/*", "*/", TRUE, TRUE, jsxsyn},
  168. {".ts", "//", "/*", "*/", TRUE, TRUE, tssyn},
  169. {".tsx", "//", "/*", "*/", TRUE, TRUE, tsxsyn},
  170. {".lisp", ";;", NULL, NULL, FALSE, FALSE, NULL},
  171. {".clj", ";;", NULL, NULL, FALSE, FALSE, NULL},
  172. {".cljs", ";;", NULL, NULL, FALSE, FALSE, NULL},
  173. {".joke", ";;", NULL, NULL, FALSE, FALSE, NULL},
  174. {".hs", "--", NULL, NULL, FALSE, FALSE, hssyn},
  175. {".sh", "#", NULL, NULL, FALSE, FALSE, NULL},
  176. {".awk", "#", NULL, NULL, FALSE, FALSE, awksyn},
  177. {".java", "//", "/*", "*/", FALSE, FALSE, NULL},
  178. {".kt", "//", "/*", "*/", FALSE, FALSE, NULL},
  179. {".sql", "--", NULL, NULL, FALSE, FALSE, sqlsyn},
  180. {".nix", "#", NULL, NULL, TRUE, TRUE, NULL},
  181. {".lua", "--", NULL, NULL, TRUE, FALSE, luasyn},
  182. /* non-programming */
  183. {".md", "#", NULL, NULL, FALSE, TRUE, mdsyn},
  184. {".dat", ";;", NULL, NULL, FALSE, FALSE, datsyn},
  185. {"NULL", NULL, NULL, NULL, FALSE, FALSE, NULL},
  186. };