soong.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. pygments.lexers.soong
  3. ~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for Soong (Android.bp Blueprint) files.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, bygroups, include
  9. from pygments.token import Comment, Name, Number, Operator, Punctuation, \
  10. String, Whitespace
  11. __all__ = ['SoongLexer']
  12. class SoongLexer(RegexLexer):
  13. name = 'Soong'
  14. version_added = '2.18'
  15. url = 'https://source.android.com/docs/setup/reference/androidbp'
  16. aliases = ['androidbp', 'bp', 'soong']
  17. filenames = ['Android.bp']
  18. tokens = {
  19. 'root': [
  20. # A variable assignment
  21. (r'(\w*)(\s*)(\+?=)(\s*)',
  22. bygroups(Name.Variable, Whitespace, Operator, Whitespace),
  23. 'assign-rhs'),
  24. # A top-level module
  25. (r'(\w*)(\s*)(\{)',
  26. bygroups(Name.Function, Whitespace, Punctuation),
  27. 'in-rule'),
  28. # Everything else
  29. include('comments'),
  30. (r'\s+', Whitespace), # newlines okay
  31. ],
  32. 'assign-rhs': [
  33. include('expr'),
  34. (r'\n', Whitespace, '#pop'),
  35. ],
  36. 'in-list': [
  37. include('expr'),
  38. include('comments'),
  39. (r'\s+', Whitespace), # newlines okay in a list
  40. (r',', Punctuation),
  41. (r'\]', Punctuation, '#pop'),
  42. ],
  43. 'in-map': [
  44. # A map key
  45. (r'(\w+)(:)(\s*)', bygroups(Name, Punctuation, Whitespace)),
  46. include('expr'),
  47. include('comments'),
  48. (r'\s+', Whitespace), # newlines okay in a map
  49. (r',', Punctuation),
  50. (r'\}', Punctuation, '#pop'),
  51. ],
  52. 'in-rule': [
  53. # Just re-use map syntax
  54. include('in-map'),
  55. ],
  56. 'comments': [
  57. (r'//.*', Comment.Single),
  58. (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
  59. ],
  60. 'expr': [
  61. (r'(true|false)\b', Name.Builtin),
  62. (r'0x[0-9a-fA-F]+', Number.Hex),
  63. (r'\d+', Number.Integer),
  64. (r'".*?"', String),
  65. (r'\{', Punctuation, 'in-map'),
  66. (r'\[', Punctuation, 'in-list'),
  67. (r'\w+', Name),
  68. ],
  69. }