meson.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. """
  2. pygments.lexers.meson
  3. ~~~~~~~~~~~~~~~~~~~~~
  4. Pygments lexer for the Meson build system
  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, words, include
  9. from pygments.token import Comment, Name, Number, Punctuation, Operator, \
  10. Keyword, String, Whitespace
  11. __all__ = ['MesonLexer']
  12. class MesonLexer(RegexLexer):
  13. """Meson language lexer.
  14. The grammar definition use to transcribe the syntax was retrieved from
  15. https://mesonbuild.com/Syntax.html#grammar for version 0.58.
  16. Some of those definitions are improperly transcribed, so the Meson++
  17. implementation was also checked: https://github.com/dcbaker/meson-plus-plus.
  18. .. versionadded:: 2.10
  19. """
  20. # TODO String interpolation @VARNAME@ inner matches
  21. # TODO keyword_arg: value inner matches
  22. name = 'Meson'
  23. url = 'https://mesonbuild.com/'
  24. aliases = ['meson', 'meson.build']
  25. filenames = ['meson.build', 'meson_options.txt']
  26. mimetypes = ['text/x-meson']
  27. tokens = {
  28. 'root': [
  29. (r'#.*?$', Comment),
  30. (r"'''.*'''", String.Single),
  31. (r'[1-9][0-9]*', Number.Integer),
  32. (r'0o[0-7]+', Number.Oct),
  33. (r'0x[a-fA-F0-9]+', Number.Hex),
  34. include('string'),
  35. include('keywords'),
  36. include('expr'),
  37. (r'[a-zA-Z_][a-zA-Z_0-9]*', Name),
  38. (r'\s+', Whitespace),
  39. ],
  40. 'string': [
  41. (r"[']{3}([']{0,2}([^\\']|\\(.|\n)))*[']{3}", String),
  42. (r"'.*?(?<!\\)(\\\\)*?'", String),
  43. ],
  44. 'keywords': [
  45. (words((
  46. 'if',
  47. 'elif',
  48. 'else',
  49. 'endif',
  50. 'foreach',
  51. 'endforeach',
  52. 'break',
  53. 'continue',
  54. ),
  55. suffix=r'\b'), Keyword),
  56. ],
  57. 'expr': [
  58. (r'(in|and|or|not)\b', Operator.Word),
  59. (r'(\*=|/=|%=|\+]=|-=|==|!=|\+|-|=)', Operator),
  60. (r'[\[\]{}:().,?]', Punctuation),
  61. (words(('true', 'false'), suffix=r'\b'), Keyword.Constant),
  62. include('builtins'),
  63. (words((
  64. 'meson',
  65. 'build_machine',
  66. 'host_machine',
  67. 'target_machine',
  68. ),
  69. suffix=r'\b'), Name.Variable.Magic),
  70. ],
  71. 'builtins': [
  72. # This list was extracted from the v0.58 reference manual
  73. (words((
  74. 'add_global_arguments',
  75. 'add_global_link_arguments',
  76. 'add_languages',
  77. 'add_project_arguments',
  78. 'add_project_link_arguments',
  79. 'add_test_setup',
  80. 'assert',
  81. 'benchmark',
  82. 'both_libraries',
  83. 'build_target',
  84. 'configuration_data',
  85. 'configure_file',
  86. 'custom_target',
  87. 'declare_dependency',
  88. 'dependency',
  89. 'disabler',
  90. 'environment',
  91. 'error',
  92. 'executable',
  93. 'files',
  94. 'find_library',
  95. 'find_program',
  96. 'generator',
  97. 'get_option',
  98. 'get_variable',
  99. 'include_directories',
  100. 'install_data',
  101. 'install_headers',
  102. 'install_man',
  103. 'install_subdir',
  104. 'is_disabler',
  105. 'is_variable',
  106. 'jar',
  107. 'join_paths',
  108. 'library',
  109. 'message',
  110. 'project',
  111. 'range',
  112. 'run_command',
  113. 'set_variable',
  114. 'shared_library',
  115. 'shared_module',
  116. 'static_library',
  117. 'subdir',
  118. 'subdir_done',
  119. 'subproject',
  120. 'summary',
  121. 'test',
  122. 'vcs_tag',
  123. 'warning',
  124. ),
  125. prefix=r'(?<!\.)',
  126. suffix=r'\b'), Name.Builtin),
  127. (r'(?<!\.)import\b', Name.Namespace),
  128. ],
  129. }