lua.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Language: Lua
  3. Author: Andrew Fedorov <[email protected]>
  4. Category: scripting
  5. */
  6. function(hljs) {
  7. var OPENING_LONG_BRACKET = '\\[=*\\[';
  8. var CLOSING_LONG_BRACKET = '\\]=*\\]';
  9. var LONG_BRACKETS = {
  10. begin: OPENING_LONG_BRACKET, end: CLOSING_LONG_BRACKET,
  11. contains: ['self']
  12. };
  13. var COMMENTS = [
  14. hljs.COMMENT('--(?!' + OPENING_LONG_BRACKET + ')', '$'),
  15. hljs.COMMENT(
  16. '--' + OPENING_LONG_BRACKET,
  17. CLOSING_LONG_BRACKET,
  18. {
  19. contains: [LONG_BRACKETS],
  20. relevance: 10
  21. }
  22. )
  23. ];
  24. return {
  25. lexemes: hljs.UNDERSCORE_IDENT_RE,
  26. keywords: {
  27. keyword:
  28. 'and break do else elseif end false for if in local nil not or repeat return then ' +
  29. 'true until while',
  30. built_in:
  31. '_G _VERSION assert collectgarbage dofile error getfenv getmetatable ipairs load ' +
  32. 'loadfile loadstring module next pairs pcall print rawequal rawget rawset require ' +
  33. 'select setfenv setmetatable tonumber tostring type unpack xpcall coroutine debug ' +
  34. 'io math os package string table'
  35. },
  36. contains: COMMENTS.concat([
  37. {
  38. className: 'function',
  39. beginKeywords: 'function', end: '\\)',
  40. contains: [
  41. hljs.inherit(hljs.TITLE_MODE, {begin: '([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*'}),
  42. {
  43. className: 'params',
  44. begin: '\\(', endsWithParent: true,
  45. contains: COMMENTS
  46. }
  47. ].concat(COMMENTS)
  48. },
  49. hljs.C_NUMBER_MODE,
  50. hljs.APOS_STRING_MODE,
  51. hljs.QUOTE_STRING_MODE,
  52. {
  53. className: 'string',
  54. begin: OPENING_LONG_BRACKET, end: CLOSING_LONG_BRACKET,
  55. contains: [LONG_BRACKETS],
  56. relevance: 5
  57. }
  58. ])
  59. };
  60. }