syntax.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /* TODO for markdown:
  103. urls
  104. probably something else
  105. */
  106. syntax_t mdsyn[] = {
  107. {"__", ID_CONSTANT}, {"**", ID_FUNCTION},
  108. {NULL}};
  109. syntax_t luasyn[] = {
  110. {"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  111. {"return", ID_FUNCTION}, {"while", ID_FUNCTION}, {"elseif", ID_FUNCTION},
  112. {"local", ID_SYMBOL},
  113. {"assert", ID_FUNCTION}, {"break", ID_FUNCTION}, {"switch", ID_FUNCTION},
  114. {"continue", ID_FUNCTION}, {"function", ID_FUNCTION}, {"end", ID_FUNCTION},
  115. {"case", ID_FUNCTION}, {"nil", ID_CONSTANT}, {"then", ID_SYMBOL},
  116. {"true", ID_CONSTANT}, {"false", ID_CONSTANT}, {NULL}};
  117. /* TODO for haskell:
  118. foreign
  119. hiding
  120. infix, infixl, infixr
  121. mdo
  122. newtype
  123. proc
  124. rec
  125. type
  126. type family
  127. type instance
  128. */
  129. syntax_t hssyn[]= {
  130. {"as", ID_DIGITS}, {"case", ID_FUNCTION}, {"of", ID_DIGITS}, {"class", ID_FUNCTION},
  131. {"data family", ID_SYMBOL}, {"data instance", ID_SYMBOL}, {"data", ID_SYMBOL},
  132. {"default", ID_DIGITS}, {"deriving instance", ID_SYMBOL}, {"deriving", ID_SYMBOL},
  133. {"do", ID_FUNCTION}, {"forall", ID_SYMBOL}, {"if", ID_FUNCTION}, {"else", ID_FUNCTION},
  134. {"then", ID_DIGITS}, {"module", ID_FUNCTION}, {"where", ID_FUNCTION},
  135. {"import", ID_FUNCTION}, {"qualified", ID_DIGITS}, {"let", ID_FUNCTION},
  136. {"in", ID_DIGITS}, {"instance", ID_FUNCTION},
  137. {NULL}};
  138. /* WIP */
  139. syntax_t datsyn[] = {
  140. {"-$", ID_FUNCTION}, {NULL},
  141. };
  142. /* WIP */
  143. syntax_t sqlsyn[] = {
  144. {"SELECT", ID_FUNCTION}, {"select", ID_FUNCTION}, {"FROM", ID_FUNCTION}, {"from", ID_FUNCTION},
  145. {"WHERE", ID_FUNCTION}, {"where", ID_FUNCTION}, {"ORDER BY", ID_FUNCTION}, {"order BY", ID_FUNCTION},
  146. {"GROUP BY", ID_FUNCTION}, {"group BY", ID_FUNCTION}, {"HAVING", ID_DIGITS}, {"having", ID_DIGITS},
  147. {"INSERT INTO", ID_FUNCTION}, {"insert into", ID_FUNCTION},
  148. {"UPDATE", ID_FUNCTION}, {"update", ID_FUNCTION}, {"DELETE", ID_FUNCTION}, {"delete", ID_FUNCTION},
  149. {"CREATE", ID_FUNCTION}, {"create", ID_FUNCTION}, {"ALTER", ID_FUNCTION}, {"alter", ID_FUNCTION},
  150. {"JOIN", ID_SYMBOL}, {"join", ID_SYMBOL}, {"UNION", ID_FUNCTION}, {"union", ID_FUNCTION},
  151. {"LIKE", ID_FUNCTION}, {"like", ID_FUNCTION}, {"IN", ID_DIGITS}, {"in", ID_DIGITS},
  152. {"EXISTS", ID_DIGITS}, {"exists", ID_DIGITS}, {"NOT", ID_FUNCTION}, {"not", ID_FUNCTION},
  153. {"AND", ID_FUNCTION}, {"and", ID_FUNCTION}, {"OR", ID_FUNCTION}, {"or", ID_FUNCTION},
  154. {"BETWEEN", ID_FUNCTION}, {"between", ID_FUNCTION}, {"DISTINCT", ID_DIGITS}, {"distinct", ID_DIGITS},
  155. {"NULL", ID_CONSTANT}, {"null", ID_CONSTANT}, {"COUNT", ID_FUNCTION}, {"count", ID_FUNCTION},
  156. {"SUM", ID_FUNCTION}, {"sum", ID_FUNCTION}, {"AVG", ID_FUNCTION}, {"avg", ID_FUNCTION},
  157. {"MIN", ID_FUNCTION}, {"min", ID_FUNCTION}, {"MAX", ID_FUNCTION}, {"max", ID_FUNCTION},
  158. {"AS", ID_DIGITS}, {"as", ID_DIGITS}, {"IF", ID_FUNCTION}, {"if", ID_FUNCTION},
  159. {"SET", ID_FUNCTION}, {"set", ID_FUNCTION}, {"ADD", ID_FUNCTION}, {"add", ID_FUNCTION},
  160. {"FALSE", ID_CONSTANT}, {"false", ID_CONSTANT}, {"TRUE", ID_CONSTANT}, {"true", ID_CONSTANT},
  161. {NULL}
  162. };
  163. syntax_t ktsyn[] = {{"if", ID_FUNCTION}, {"else", ID_FUNCTION}, {"for", ID_FUNCTION},
  164. {"return", ID_FUNCTION}, {"while", ID_FUNCTION},
  165. {"val", ID_SYMBOL}, {"class", ID_SYMBOL}, {"var", ID_SYMBOL},
  166. {"break", ID_FUNCTION}, {"switch", ID_FUNCTION}, {"export", ID_FUNCTION},
  167. {"typeof", ID_FUNCTION}, {"case", ID_FUNCTION}, {"null", ID_CONSTANT},
  168. {"import", ID_FUNCTION}, {"from", ID_SYMBOL}, {"default", ID_DIGITS},
  169. {"undefined", ID_CONSTANT}, {"true", ID_CONSTANT}, {"false", ID_CONSTANT},
  170. {"fun", ID_SYMBOL}, {"lateinit", ID_DIGITS}, {"open", ID_DIGITS},
  171. {"try", ID_FUNCTION}, {"catch", ID_FUNCTION}, {"finally", ID_FUNCTION},
  172. {"package", ID_FUNCTION}, {"override", ID_DIGITS}, {"private", ID_DIGITS},
  173. {"public", ID_DIGITS}, {"object", ID_SYMBOL}, {"companion", ID_DIGITS},
  174. {NULL}};
  175. /* list of keywords _must_ end with NULL */
  176. keywords_t keywords[] = {
  177. /* programming */
  178. {".c", "//", "/*", "*/", TRUE, FALSE, csyn},
  179. {".h", "//", "/*", "*/", TRUE, FALSE, csyn},
  180. {".css", "//", "/*", "*/", FALSE, FALSE, NULL},
  181. {".html", "", "<!--", "-->", FALSE, FALSE, htmlsyn},
  182. {".js", "//", "/*", "*/", TRUE, TRUE, jssyn},
  183. {".jsx", "//", "/*", "*/", TRUE, TRUE, jsxsyn},
  184. {".ts", "//", "/*", "*/", TRUE, TRUE, tssyn},
  185. {".tsx", "//", "/*", "*/", TRUE, TRUE, tsxsyn},
  186. {".lisp", ";;", NULL, NULL, FALSE, FALSE, NULL},
  187. {".clj", ";;", NULL, NULL, FALSE, FALSE, NULL},
  188. {".cljs", ";;", NULL, NULL, FALSE, FALSE, NULL},
  189. {".joke", ";;", NULL, NULL, FALSE, FALSE, NULL},
  190. {".hs", "--", NULL, NULL, FALSE, FALSE, hssyn},
  191. {".sh", "#", NULL, NULL, FALSE, FALSE, NULL},
  192. {".awk", "#", NULL, NULL, FALSE, FALSE, awksyn},
  193. {".java", "//", "/*", "*/", FALSE, FALSE, NULL},
  194. {".kt", "//", "/*", "*/", FALSE, TRUE, ktsyn},
  195. {".sql", "--", NULL, NULL, FALSE, FALSE, sqlsyn},
  196. {".nix", "#", NULL, NULL, TRUE, TRUE, NULL},
  197. {".lua", "--", NULL, NULL, TRUE, FALSE, luasyn},
  198. /* non-programming */
  199. {".md", "#", NULL, NULL, FALSE, TRUE, mdsyn},
  200. {".dat", ";;", NULL, NULL, FALSE, FALSE, datsyn},
  201. {"NULL", NULL, NULL, NULL, FALSE, FALSE, NULL},
  202. };