lua.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.conf = {
  9. comments: {
  10. lineComment: '--',
  11. blockComment: ['--[[', ']]'],
  12. },
  13. brackets: [
  14. ['{', '}'],
  15. ['[', ']'],
  16. ['(', ')']
  17. ],
  18. autoClosingPairs: [
  19. { open: '{', close: '}' },
  20. { open: '[', close: ']' },
  21. { open: '(', close: ')' },
  22. { open: '"', close: '"' },
  23. { open: '\'', close: '\'' },
  24. ],
  25. surroundingPairs: [
  26. { open: '{', close: '}' },
  27. { open: '[', close: ']' },
  28. { open: '(', close: ')' },
  29. { open: '"', close: '"' },
  30. { open: '\'', close: '\'' },
  31. ]
  32. };
  33. exports.language = {
  34. defaultToken: '',
  35. tokenPostfix: '.lua',
  36. keywords: [
  37. 'and', 'break', 'do', 'else', 'elseif',
  38. 'end', 'false', 'for', 'function', 'goto', 'if',
  39. 'in', 'local', 'nil', 'not', 'or',
  40. 'repeat', 'return', 'then', 'true', 'until',
  41. 'while'
  42. ],
  43. brackets: [
  44. { token: 'delimiter.bracket', open: '{', close: '}' },
  45. { token: 'delimiter.array', open: '[', close: ']' },
  46. { token: 'delimiter.parenthesis', open: '(', close: ')' }
  47. ],
  48. operators: [
  49. '+', '-', '*', '/', '%', '^', '#', '==', '~=', '<=', '>=', '<', '>', '=',
  50. ';', ':', ',', '.', '..', '...'
  51. ],
  52. // we include these common regular expressions
  53. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  54. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  55. // The main tokenizer for our languages
  56. tokenizer: {
  57. root: [
  58. // identifiers and keywords
  59. [/[a-zA-Z_]\w*/, {
  60. cases: {
  61. '@keywords': { token: 'keyword.$0' },
  62. '@default': 'identifier'
  63. }
  64. }],
  65. // whitespace
  66. { include: '@whitespace' },
  67. // keys
  68. [/(,)(\s*)([a-zA-Z_]\w*)(\s*)(:)(?!:)/, ['delimiter', '', 'key', '', 'delimiter']],
  69. [/({)(\s*)([a-zA-Z_]\w*)(\s*)(:)(?!:)/, ['@brackets', '', 'key', '', 'delimiter']],
  70. // delimiters and operators
  71. [/[{}()\[\]]/, '@brackets'],
  72. [/@symbols/, {
  73. cases: {
  74. '@operators': 'delimiter',
  75. '@default': ''
  76. }
  77. }],
  78. // numbers
  79. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  80. [/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/, 'number.hex'],
  81. [/\d+?/, 'number'],
  82. // delimiter: after number because of .\d floats
  83. [/[;,.]/, 'delimiter'],
  84. // strings: recover on non-terminated strings
  85. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  86. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  87. [/"/, 'string', '@string."'],
  88. [/'/, 'string', '@string.\''],
  89. ],
  90. whitespace: [
  91. [/[ \t\r\n]+/, ''],
  92. [/--\[([=]*)\[/, 'comment', '@comment.$1'],
  93. [/--.*$/, 'comment'],
  94. ],
  95. comment: [
  96. [/[^\]]+/, 'comment'],
  97. [/\]([=]*)\]/, {
  98. cases: {
  99. '$1==$S2': { token: 'comment', next: '@pop' },
  100. '@default': 'comment'
  101. }
  102. }],
  103. [/./, 'comment']
  104. ],
  105. string: [
  106. [/[^\\"']+/, 'string'],
  107. [/@escapes/, 'string.escape'],
  108. [/\\./, 'string.escape.invalid'],
  109. [/["']/, {
  110. cases: {
  111. '$#==$S2': { token: 'string', next: '@pop' },
  112. '@default': 'string'
  113. }
  114. }]
  115. ],
  116. },
  117. };
  118. });