sophia.js 5.3 KB

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