rnc.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.rnc
  4. ~~~~~~~~~~~~~~~~~~~
  5. Lexer for Relax-NG Compact syntax
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. from pygments.lexer import RegexLexer
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Punctuation
  12. __all__ = ['RNCCompactLexer']
  13. class RNCCompactLexer(RegexLexer):
  14. """
  15. For `RelaxNG-compact <http://relaxng.org>`_ syntax.
  16. .. versionadded:: 2.2
  17. """
  18. name = 'Relax-NG Compact'
  19. aliases = ['rnc', 'rng-compact']
  20. filenames = ['*.rnc']
  21. tokens = {
  22. 'root': [
  23. (r'namespace\b', Keyword.Namespace),
  24. (r'(?:default|datatypes)\b', Keyword.Declaration),
  25. (r'##.*$', Comment.Preproc),
  26. (r'#.*$', Comment.Single),
  27. (r'"[^"]*"', String.Double),
  28. # TODO single quoted strings and escape sequences outside of
  29. # double-quoted strings
  30. (r'(?:element|attribute|mixed)\b', Keyword.Declaration, 'variable'),
  31. (r'(text\b|xsd:[^ ]+)', Keyword.Type, 'maybe_xsdattributes'),
  32. (r'[,?&*=|~]|>>', Operator),
  33. (r'[(){}]', Punctuation),
  34. (r'.', Text),
  35. ],
  36. # a variable has been declared using `element` or `attribute`
  37. 'variable': [
  38. (r'[^{]+', Name.Variable),
  39. (r'\{', Punctuation, '#pop'),
  40. ],
  41. # after an xsd:<datatype> declaration there may be attributes
  42. 'maybe_xsdattributes': [
  43. (r'\{', Punctuation, 'xsdattributes'),
  44. (r'\}', Punctuation, '#pop'),
  45. (r'.', Text),
  46. ],
  47. # attributes take the form { key1 = value1 key2 = value2 ... }
  48. 'xsdattributes': [
  49. (r'[^ =}]', Name.Attribute),
  50. (r'=', Operator),
  51. (r'"[^"]*"', String.Double),
  52. (r'\}', Punctuation, '#pop'),
  53. (r'.', Text),
  54. ],
  55. }