diff --git a/lib/rouge/demos/meson b/lib/rouge/demos/meson new file mode 100644 index 0000000000..a10a60c9c6 --- /dev/null +++ b/lib/rouge/demos/meson @@ -0,0 +1,10 @@ +project('tutorial', 'c', version: '0.2.3') +executable('demo', 'main.c') + +version_array = meson.project_version().split('.') +api_version = '@0@.@1@'.format(version_array[0], version_array[1]) + +d = dependency('foo', required : get_option('myfeature')) +if d.found() + app = executable('app', 'app.c', dependencies : [d]) +endif diff --git a/lib/rouge/lexers/meson.rb b/lib/rouge/lexers/meson.rb new file mode 100644 index 0000000000..2c313a3b1a --- /dev/null +++ b/lib/rouge/lexers/meson.rb @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- # +# frozen_string_literal: true + +module Rouge + module Lexers + class Meson < RegexLexer + title "Meson" + desc "Meson's specification language (mesonbuild.com)" + tag 'meson' + filenames 'meson.build', 'meson_options.txt' + + def self.keywords + @keywords ||= %w( + continue break elif else endif + if true false foreach endforeach + ) + end + + def self.builtin_variables + @builtin_variables ||= %w( + meson host_machine build_machine target_machine + ) + end + + def self.builtin_functions + @builtin_functions ||= %w( + add_global_arguments add_project_arguments + add_global_link_arguments add_project_link_arguments add_test_setup add_languages + alias_target assert benchmark both_libraries build_target configuration_data configure_file + custom_target declare_dependency dependency disabler environment error executable + generator gettext get_option get_variable files find_library find_program + include_directories import install_data install_headers install_man install_subdir + is_disabler is_variable jar join_paths library message option project + run_target run_command set_variable subdir subdir_done + subproject summary shared_library shared_module static_library test vcs_tag warning + ) + end + + identifier = /[[:alpha:]_][[:alnum:]_]*/ + dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ + + def current_string + @string_register ||= StringRegister.new + end + + state :root do + rule %r/\n+/m, Text + + rule %r/[^\S\n]+/, Text + rule %r(#(.*)?\n?), Comment::Single + rule %r/[\[\]{}:(),;.]/, Punctuation + rule %r/\\\n/, Text + rule %r/\\/, Text + + rule %r/(in|and|or|not)\b/, Operator::Word + rule %r/[-+\/*%=<>]=?|!=/, Operator + + rule %r/([f]?)('''|['])/i do |m| + groups Str::Affix, Str + current_string.register type: m[1].downcase, delim: m[2] + push :generic_string + end + + rule %r/(?