graphql.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. },
  12. brackets: [
  13. ['{', '}'],
  14. ['[', ']'],
  15. ['(', ')']
  16. ],
  17. autoClosingPairs: [
  18. { open: '{', close: '}' },
  19. { open: '[', close: ']' },
  20. { open: '(', close: ')' },
  21. { open: '"""', close: '"""', notIn: ['string', 'comment'] },
  22. { open: '"', close: '"', notIn: ['string', 'comment'] },
  23. ],
  24. surroundingPairs: [
  25. { open: '{', close: '}' },
  26. { open: '[', close: ']' },
  27. { open: '(', close: ')' },
  28. { open: '"""', close: '"""' },
  29. { open: '"', close: '"' },
  30. ],
  31. folding: {
  32. offSide: true
  33. }
  34. };
  35. exports.language = {
  36. // Set defaultToken to invalid to see what you do not tokenize yet
  37. defaultToken: 'invalid',
  38. tokenPostfix: '.gql',
  39. keywords: [
  40. 'null', 'true', 'false',
  41. 'query', 'mutation', 'subscription',
  42. 'extend', 'schema', 'directive',
  43. 'scalar', 'type', 'interface', 'union', 'enum', 'input', 'implements',
  44. 'fragment', 'on',
  45. ],
  46. typeKeywords: ['Int', 'Float', 'String', 'Boolean', 'ID'],
  47. directiveLocations: [
  48. 'SCHEMA', 'SCALAR', 'OBJECT', 'FIELD_DEFINITION', 'ARGUMENT_DEFINITION',
  49. 'INTERFACE', 'UNION', 'ENUM', 'ENUM_VALUE', 'INPUT_OBJECT', 'INPUT_FIELD_DEFINITION',
  50. 'QUERY', 'MUTATION', 'SUBSCRIPTION', 'FIELD', 'FRAGMENT_DEFINITION',
  51. 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT', 'VARIABLE_DEFINITION',
  52. ],
  53. operators: ['=', '!', '?', ':', '&', '|'],
  54. // we include these common regular expressions
  55. symbols: /[=!?:&|]+/,
  56. // https://facebook.github.io/graphql/draft/#sec-String-Value
  57. escapes: /\\(?:["\\\/bfnrt]|u[0-9A-Fa-f]{4})/,
  58. // The main tokenizer for our languages
  59. tokenizer: {
  60. root: [
  61. // fields and argument names
  62. [
  63. /[a-z_][\w$]*/,
  64. {
  65. cases: {
  66. '@keywords': 'keyword',
  67. '@default': 'key.identifier',
  68. },
  69. },
  70. ],
  71. // identify typed input variables
  72. [
  73. /[$][\w$]*/,
  74. {
  75. cases: {
  76. '@keywords': 'keyword',
  77. '@default': 'argument.identifier',
  78. },
  79. },
  80. ],
  81. // to show class names nicely
  82. [
  83. /[A-Z][\w\$]*/,
  84. {
  85. cases: {
  86. '@typeKeywords': 'keyword',
  87. '@default': 'type.identifier',
  88. },
  89. },
  90. ],
  91. // whitespace
  92. { include: '@whitespace' },
  93. // delimiters and operators
  94. [/[{}()\[\]]/, '@brackets'],
  95. [
  96. /@symbols/,
  97. { cases: { '@operators': 'operator', '@default': '' } },
  98. ],
  99. // @ annotations.
  100. // As an example, we emit a debugging log message on these tokens.
  101. // Note: message are supressed during the first load -- change some lines to see them.
  102. [
  103. /@\s*[a-zA-Z_\$][\w\$]*/,
  104. { token: 'annotation', log: 'annotation token: $0' },
  105. ],
  106. // numbers
  107. [/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
  108. [/0[xX][0-9a-fA-F]+/, 'number.hex'],
  109. [/\d+/, 'number'],
  110. // delimiter: after number because of .\d floats
  111. [/[;,.]/, 'delimiter'],
  112. [/"""/,
  113. { token: 'string', next: '@mlstring', nextEmbedded: 'markdown' }
  114. ],
  115. // strings
  116. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  117. [/"/, { token: 'string.quote', bracket: '@open', next: '@string' }],
  118. ],
  119. mlstring: [
  120. [/[^"]+/, 'string'],
  121. ['"""', { token: 'string', next: '@pop', nextEmbedded: '@pop' }]
  122. ],
  123. string: [
  124. [/[^\\"]+/, 'string'],
  125. [/@escapes/, 'string.escape'],
  126. [/\\./, 'string.escape.invalid'],
  127. [/"/, { token: 'string.quote', bracket: '@close', next: '@pop' }],
  128. ],
  129. whitespace: [[/[ \t\r\n]+/, ''], [/#.*$/, 'comment']],
  130. },
  131. };
  132. });