lua.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define('vs/basic-languages/lua/lua',["require", "exports"], function (require, exports) {
  6. "use strict";
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.language = exports.conf = void 0;
  9. exports.conf = {
  10. comments: {
  11. lineComment: '--',
  12. blockComment: ['--[[', ']]']
  13. },
  14. brackets: [
  15. ['{', '}'],
  16. ['[', ']'],
  17. ['(', ')']
  18. ],
  19. autoClosingPairs: [
  20. { open: '{', close: '}' },
  21. { open: '[', close: ']' },
  22. { open: '(', close: ')' },
  23. { open: '"', close: '"' },
  24. { open: "'", close: "'" }
  25. ],
  26. surroundingPairs: [
  27. { open: '{', close: '}' },
  28. { open: '[', close: ']' },
  29. { open: '(', close: ')' },
  30. { open: '"', close: '"' },
  31. { open: "'", close: "'" }
  32. ]
  33. };
  34. exports.language = {
  35. defaultToken: '',
  36. tokenPostfix: '.lua',
  37. keywords: [
  38. 'and',
  39. 'break',
  40. 'do',
  41. 'else',
  42. 'elseif',
  43. 'end',
  44. 'false',
  45. 'for',
  46. 'function',
  47. 'goto',
  48. 'if',
  49. 'in',
  50. 'local',
  51. 'nil',
  52. 'not',
  53. 'or',
  54. 'repeat',
  55. 'return',
  56. 'then',
  57. 'true',
  58. 'until',
  59. 'while'
  60. ],
  61. brackets: [
  62. { token: 'delimiter.bracket', open: '{', close: '}' },
  63. { token: 'delimiter.array', open: '[', close: ']' },
  64. { token: 'delimiter.parenthesis', open: '(', close: ')' }
  65. ],
  66. operators: [
  67. '+',
  68. '-',
  69. '*',
  70. '/',
  71. '%',
  72. '^',
  73. '#',
  74. '==',
  75. '~=',
  76. '<=',
  77. '>=',
  78. '<',
  79. '>',
  80. '=',
  81. ';',
  82. ':',
  83. ',',
  84. '.',
  85. '..',
  86. '...'
  87. ],
  88. // we include these common regular expressions
  89. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  90. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  91. // The main tokenizer for our languages
  92. tokenizer: {
  93. root: [
  94. // identifiers and keywords
  95. [
  96. /[a-zA-Z_]\w*/,
  97. {
  98. cases: {
  99. '@keywords': { token: 'keyword.$0' },
  100. '@default': 'identifier'
  101. }
  102. }
  103. ],
  104. // whitespace
  105. { include: '@whitespace' },
  106. // keys
  107. [/(,)(\s*)([a-zA-Z_]\w*)(\s*)(:)(?!:)/, ['delimiter', '', 'key', '', 'delimiter']],
  108. [/({)(\s*)([a-zA-Z_]\w*)(\s*)(:)(?!:)/, ['@brackets', '', 'key', '', 'delimiter']],
  109. // delimiters and operators
  110. [/[{}()\[\]]/, '@brackets'],
  111. [
  112. /@symbols/,
  113. {
  114. cases: {
  115. '@operators': 'delimiter',
  116. '@default': ''
  117. }
  118. }
  119. ],
  120. // numbers
  121. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  122. [/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/, 'number.hex'],
  123. [/\d+?/, 'number'],
  124. // delimiter: after number because of .\d floats
  125. [/[;,.]/, 'delimiter'],
  126. // strings: recover on non-terminated strings
  127. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  128. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  129. [/"/, 'string', '@string."'],
  130. [/'/, 'string', "@string.'"]
  131. ],
  132. whitespace: [
  133. [/[ \t\r\n]+/, ''],
  134. [/--\[([=]*)\[/, 'comment', '@comment.$1'],
  135. [/--.*$/, 'comment']
  136. ],
  137. comment: [
  138. [/[^\]]+/, 'comment'],
  139. [
  140. /\]([=]*)\]/,
  141. {
  142. cases: {
  143. '$1==$S2': { token: 'comment', next: '@pop' },
  144. '@default': 'comment'
  145. }
  146. }
  147. ],
  148. [/./, 'comment']
  149. ],
  150. string: [
  151. [/[^\\"']+/, 'string'],
  152. [/@escapes/, 'string.escape'],
  153. [/\\./, 'string.escape.invalid'],
  154. [
  155. /["']/,
  156. {
  157. cases: {
  158. '$#==$S2': { token: 'string', next: '@pop' },
  159. '@default': 'string'
  160. }
  161. }
  162. ]
  163. ]
  164. }
  165. };
  166. });