rnc.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. pygments.lexers.rnc
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexer for Relax-NG Compact syntax
  5. :copyright: Copyright 2006-2023 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 syntax.
  15. .. versionadded:: 2.2
  16. """
  17. name = 'Relax-NG Compact'
  18. url = 'http://relaxng.org'
  19. aliases = ['rng-compact', 'rnc']
  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. }