25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

109 satır
4.0 KiB

  1. """
  2. pygments.lexers.graph
  3. ~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for graph query languages.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, include, bygroups, using, this, words
  10. from pygments.token import Keyword, Punctuation, Comment, Operator, Name,\
  11. String, Number, Whitespace
  12. __all__ = ['CypherLexer']
  13. class CypherLexer(RegexLexer):
  14. """
  15. For Cypher Query Language
  16. For the Cypher version in Neo4j 3.3
  17. """
  18. name = 'Cypher'
  19. url = 'https://neo4j.com/docs/developer-manual/3.3/cypher/'
  20. aliases = ['cypher']
  21. filenames = ['*.cyp', '*.cypher']
  22. version_added = '2.0'
  23. flags = re.MULTILINE | re.IGNORECASE
  24. tokens = {
  25. 'root': [
  26. include('clauses'),
  27. include('keywords'),
  28. include('relations'),
  29. include('strings'),
  30. include('whitespace'),
  31. include('barewords'),
  32. include('comment'),
  33. ],
  34. 'keywords': [
  35. (r'(create|order|match|limit|set|skip|start|return|with|where|'
  36. r'delete|foreach|not|by|true|false)\b', Keyword),
  37. ],
  38. 'clauses': [
  39. # based on https://neo4j.com/docs/cypher-refcard/3.3/
  40. (r'(create)(\s+)(index|unique)\b',
  41. bygroups(Keyword, Whitespace, Keyword)),
  42. (r'(drop)(\s+)(contraint|index)(\s+)(on)\b',
  43. bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
  44. (r'(ends)(\s+)(with)\b',
  45. bygroups(Keyword, Whitespace, Keyword)),
  46. (r'(is)(\s+)(node)(\s+)(key)\b',
  47. bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
  48. (r'(is)(\s+)(null|unique)\b',
  49. bygroups(Keyword, Whitespace, Keyword)),
  50. (r'(load)(\s+)(csv)(\s+)(from)\b',
  51. bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
  52. (r'(on)(\s+)(match|create)\b',
  53. bygroups(Keyword, Whitespace, Keyword)),
  54. (r'(optional)(\s+)(match)\b',
  55. bygroups(Keyword, Whitespace, Keyword)),
  56. (r'(order)(\s+)(by)\b',
  57. bygroups(Keyword, Whitespace, Keyword)),
  58. (r'(starts)(\s+)(with)\b',
  59. bygroups(Keyword, Whitespace, Keyword)),
  60. (r'(union)(\s+)(all)\b',
  61. bygroups(Keyword, Whitespace, Keyword)),
  62. (r'(using)(\s+)(periodic)(\s+)(commit)\b',
  63. bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
  64. (r'(using)(\s+)(index)\b',
  65. bygroups(Keyword, Whitespace, Keyword)),
  66. (r'(using)(\s+)(range|text|point)(\s+)(index)\b',
  67. bygroups(Keyword, Whitespace, Name, Whitespace, Keyword)),
  68. (words((
  69. 'all', 'any', 'as', 'asc', 'ascending', 'assert', 'call', 'case', 'create',
  70. 'delete', 'desc', 'descending', 'distinct', 'end', 'fieldterminator',
  71. 'foreach', 'in', 'limit', 'match', 'merge', 'none', 'not', 'null',
  72. 'remove', 'return', 'set', 'skip', 'single', 'start', 'then', 'union',
  73. 'unwind', 'yield', 'where', 'when', 'with', 'collect'), suffix=r'\b'), Keyword),
  74. ],
  75. 'relations': [
  76. (r'(-\[)(.*?)(\]->)', bygroups(Operator, using(this), Operator)),
  77. (r'(<-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)),
  78. (r'(-\[)(.*?)(\]-)', bygroups(Operator, using(this), Operator)),
  79. (r'-->|<--|\[|\]', Operator),
  80. (r'<|>|<>|=|<=|=>|\(|\)|\||:|,|;', Punctuation),
  81. (r'[.*{}]', Punctuation),
  82. ],
  83. 'strings': [
  84. (r'([\'"])(?:\\[tbnrf\'"\\]|[^\\])*?\1', String),
  85. (r'`(?:``|[^`])+`', Name.Variable),
  86. ],
  87. 'whitespace': [
  88. (r'\s+', Whitespace),
  89. ],
  90. 'barewords': [
  91. (r'[a-z]\w*', Name),
  92. (r'\d+', Number),
  93. ],
  94. 'comment': [
  95. (r'//.*$', Comment.Single),
  96. ],
  97. }