language_js.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. local syntax = require "core.syntax"
  2. syntax.add {
  3. files = { "%.js$", "%.json$", "%.cson$" },
  4. comment = "//",
  5. patterns = {
  6. { pattern = "//.-\n", type = "comment" },
  7. { pattern = { "/%*", "%*/" }, type = "comment" },
  8. { pattern = { '"', '"', '\\' }, type = "string" },
  9. { pattern = { "'", "'", '\\' }, type = "string" },
  10. { pattern = "0x[%da-fA-F]+", type = "number" },
  11. { pattern = "-?%d+[%d%.eE]*", type = "number" },
  12. { pattern = "-?%.?%d+", type = "number" },
  13. { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
  14. { pattern = "[%a_][%w_]*%f[(]", type = "function" },
  15. { pattern = "[%a_][%w_]*", type = "symbol" },
  16. },
  17. symbols = {
  18. ["if"] = "keyword",
  19. ["then"] = "keyword",
  20. ["else"] = "keyword",
  21. ["do"] = "keyword",
  22. ["while"] = "keyword",
  23. ["for"] = "keyword",
  24. ["break"] = "keyword",
  25. ["continue"] = "keyword",
  26. ["return"] = "keyword",
  27. ["switch"] = "keyword",
  28. ["case"] = "keyword",
  29. ["const"] = "keyword",
  30. ["try"] = "keyword",
  31. ["catch"] = "keyword",
  32. ["throw"] = "keyword",
  33. ["var"] = "keyword",
  34. ["let"] = "keyword",
  35. ["get"] = "keyword",
  36. ["set"] = "keyword",
  37. ["function"] = "keyword",
  38. ["new"] = "keyword",
  39. ["this"] = "keyword2",
  40. ["true"] = "literal",
  41. ["false"] = "literal",
  42. ["null"] = "literal",
  43. },
  44. }