rnc.py 1.9 KB

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