sparql.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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: "'", notIn: ['string'] },
  16. { open: '"', close: '"', notIn: ['string'] },
  17. { open: '{', close: '}' },
  18. { open: '[', close: ']' },
  19. { open: '(', close: ')' }
  20. ]
  21. };
  22. export var language = {
  23. defaultToken: '',
  24. tokenPostfix: '.rq',
  25. brackets: [
  26. { token: 'delimiter.curly', open: '{', close: '}' },
  27. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  28. { token: 'delimiter.square', open: '[', close: ']' },
  29. { token: 'delimiter.angle', open: '<', close: '>' }
  30. ],
  31. keywords: [
  32. 'add',
  33. 'as',
  34. 'asc',
  35. 'ask',
  36. 'base',
  37. 'by',
  38. 'clear',
  39. 'construct',
  40. 'copy',
  41. 'create',
  42. 'data',
  43. 'delete',
  44. 'desc',
  45. 'describe',
  46. 'distinct',
  47. 'drop',
  48. 'false',
  49. 'filter',
  50. 'from',
  51. 'graph',
  52. 'group',
  53. 'having',
  54. 'in',
  55. 'insert',
  56. 'limit',
  57. 'load',
  58. 'minus',
  59. 'move',
  60. 'named',
  61. 'not',
  62. 'offset',
  63. 'optional',
  64. 'order',
  65. 'prefix',
  66. 'reduced',
  67. 'select',
  68. 'service',
  69. 'silent',
  70. 'to',
  71. 'true',
  72. 'undef',
  73. 'union',
  74. 'using',
  75. 'values',
  76. 'where',
  77. 'with'
  78. ],
  79. builtinFunctions: [
  80. 'a',
  81. 'abs',
  82. 'avg',
  83. 'bind',
  84. 'bnode',
  85. 'bound',
  86. 'ceil',
  87. 'coalesce',
  88. 'concat',
  89. 'contains',
  90. 'count',
  91. 'datatype',
  92. 'day',
  93. 'encode_for_uri',
  94. 'exists',
  95. 'floor',
  96. 'group_concat',
  97. 'hours',
  98. 'if',
  99. 'iri',
  100. 'isblank',
  101. 'isiri',
  102. 'isliteral',
  103. 'isnumeric',
  104. 'isuri',
  105. 'lang',
  106. 'langmatches',
  107. 'lcase',
  108. 'max',
  109. 'md5',
  110. 'min',
  111. 'minutes',
  112. 'month',
  113. 'now',
  114. 'rand',
  115. 'regex',
  116. 'replace',
  117. 'round',
  118. 'sameterm',
  119. 'sample',
  120. 'seconds',
  121. 'sha1',
  122. 'sha256',
  123. 'sha384',
  124. 'sha512',
  125. 'str',
  126. 'strafter',
  127. 'strbefore',
  128. 'strdt',
  129. 'strends',
  130. 'strlang',
  131. 'strlen',
  132. 'strstarts',
  133. 'struuid',
  134. 'substr',
  135. 'sum',
  136. 'timezone',
  137. 'tz',
  138. 'ucase',
  139. 'uri',
  140. 'uuid',
  141. 'year'
  142. ],
  143. // describe tokens
  144. ignoreCase: true,
  145. tokenizer: {
  146. root: [
  147. // resource indicators
  148. [/<[^\s\u00a0>]*>?/, 'tag'],
  149. // strings
  150. { include: '@strings' },
  151. // line comment
  152. [/#.*/, 'comment'],
  153. // special chars with special meaning
  154. [/[{}()\[\]]/, '@brackets'],
  155. [/[;,.]/, 'delimiter'],
  156. // (prefixed) name
  157. [
  158. /[_\w\d]+:(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])*/,
  159. 'tag'
  160. ],
  161. [/:(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])+/, 'tag'],
  162. // identifiers, builtinFunctions and keywords
  163. [
  164. /[$?]?[_\w\d]+/,
  165. {
  166. cases: {
  167. '@keywords': { token: 'keyword' },
  168. '@builtinFunctions': { token: 'predefined.sql' },
  169. '@default': 'identifier'
  170. }
  171. }
  172. ],
  173. // operators
  174. [/\^\^/, 'operator.sql'],
  175. [/\^[*+\-<>=&|^\/!?]*/, 'operator.sql'],
  176. [/[*+\-<>=&|\/!?]/, 'operator.sql'],
  177. // symbol
  178. [/@[a-z\d\-]*/, 'metatag.html'],
  179. // whitespaces
  180. [/\s+/, 'white']
  181. ],
  182. strings: [
  183. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  184. [/'$/, 'string.sql', '@pop'],
  185. [/'/, 'string.sql', '@stringBody'],
  186. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  187. [/"$/, 'string.sql', '@pop'],
  188. [/"/, 'string.sql', '@dblStringBody']
  189. ],
  190. // single-quoted strings
  191. stringBody: [
  192. [/[^\\']+/, 'string.sql'],
  193. [/\\./, 'string.escape'],
  194. [/'/, 'string.sql', '@pop']
  195. ],
  196. // double-quoted strings
  197. dblStringBody: [
  198. [/[^\\"]+/, 'string.sql'],
  199. [/\\./, 'string.escape'],
  200. [/"/, 'string.sql', '@pop']
  201. ]
  202. }
  203. };