sophia.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. autoClosingPairs: [
  15. { open: '"', close: '"', notIn: ['string', 'comment'] },
  16. { open: '{', close: '}', notIn: ['string', 'comment'] },
  17. { open: '[', close: ']', notIn: ['string', 'comment'] },
  18. { open: '(', close: ')', notIn: ['string', 'comment'] },
  19. ]
  20. };
  21. exports.language = {
  22. defaultToken: '',
  23. tokenPostfix: '.aes',
  24. brackets: [
  25. { token: 'delimiter.curly', open: '{', close: '}' },
  26. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  27. { token: 'delimiter.square', open: '[', close: ']' },
  28. { token: 'delimiter.angle', open: '<', close: '>' }
  29. ],
  30. keywords: [
  31. // Main keywords
  32. 'contract',
  33. 'library',
  34. 'entrypoint',
  35. 'function',
  36. 'stateful',
  37. 'state',
  38. 'hash',
  39. 'signature',
  40. 'tuple',
  41. 'list',
  42. 'address',
  43. 'string',
  44. 'bool',
  45. 'int',
  46. 'record',
  47. 'datatype',
  48. 'type',
  49. 'option',
  50. 'oracle',
  51. 'oracle_query',
  52. 'Call',
  53. 'Bits',
  54. 'Bytes',
  55. 'Oracle',
  56. 'String',
  57. 'Crypto',
  58. 'Address',
  59. 'Auth',
  60. 'Chain',
  61. 'None',
  62. 'Some',
  63. 'bits',
  64. 'bytes',
  65. 'event',
  66. 'let',
  67. 'map',
  68. 'private',
  69. 'public',
  70. 'true',
  71. 'false',
  72. 'var',
  73. 'if',
  74. 'else',
  75. 'throw'
  76. ],
  77. operators: [
  78. '=', '>', '<', '!', '~', '?', '::', ':',
  79. '==', '<=', '>=', '!=', '&&', '||', '++', '--',
  80. '+', '-', '*', '/', '&', '|', '^', '%', '<<',
  81. '>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=',
  82. '^=', '%=', '<<=', '>>=', '>>>='
  83. ],
  84. // we include these common regular expressions
  85. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  86. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  87. integersuffix: /(ll|LL|u|U|l|L)?(ll|LL|u|U|l|L)?/,
  88. floatsuffix: /[fFlL]?/,
  89. // The main tokenizer for our languages
  90. tokenizer: {
  91. root: [
  92. // identifiers and keywords
  93. [/[a-zA-Z_]\w*/, {
  94. cases: {
  95. '@keywords': { token: 'keyword.$0' },
  96. '@default': 'identifier'
  97. }
  98. }],
  99. // whitespace
  100. { include: '@whitespace' },
  101. // [[ attributes ]].
  102. [/\[\[.*\]\]/, 'annotation'],
  103. // Preprocessor directive
  104. [/^\s*#\w+/, 'keyword'],
  105. //DataTypes
  106. [/int\d*/, 'keyword'],
  107. // delimiters and operators
  108. [/[{}()\[\]]/, '@brackets'],
  109. [/[<>](?!@symbols)/, '@brackets'],
  110. [/@symbols/, {
  111. cases: {
  112. '@operators': 'delimiter',
  113. '@default': ''
  114. }
  115. }],
  116. // numbers
  117. [/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  118. [/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  119. [/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, 'number.hex'],
  120. [/0[0-7']*[0-7](@integersuffix)/, 'number.octal'],
  121. [/0[bB][0-1']*[0-1](@integersuffix)/, 'number.binary'],
  122. [/\d[\d']*\d(@integersuffix)/, 'number'],
  123. [/\d(@integersuffix)/, 'number'],
  124. // delimiter: after number because of .\d floats
  125. [/[;,.]/, 'delimiter'],
  126. // strings
  127. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  128. [/"/, 'string', '@string'],
  129. // characters
  130. [/'[^\\']'/, 'string'],
  131. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  132. [/'/, 'string.invalid']
  133. ],
  134. whitespace: [
  135. [/[ \t\r\n]+/, ''],
  136. [/\/\*\*(?!\/)/, 'comment.doc', '@doccomment'],
  137. [/\/\*/, 'comment', '@comment'],
  138. [/\/\/.*$/, 'comment'],
  139. ],
  140. comment: [
  141. [/[^\/*]+/, 'comment'],
  142. [/\*\//, 'comment', '@pop'],
  143. [/[\/*]/, 'comment']
  144. ],
  145. //Identical copy of comment above, except for the addition of .doc
  146. doccomment: [
  147. [/[^\/*]+/, 'comment.doc'],
  148. [/\*\//, 'comment.doc', '@pop'],
  149. [/[\/*]/, 'comment.doc']
  150. ],
  151. string: [
  152. [/[^\\"]+/, 'string'],
  153. [/@escapes/, 'string.escape'],
  154. [/\\./, 'string.escape.invalid'],
  155. [/"/, 'string', '@pop']
  156. ],
  157. },
  158. };
  159. });