graphql.js 4.7 KB

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