Sublime Forum

Where is the Meson syntax package?

#1

I went looking for a syntax package for the Meson build system and only found this package. It links to a Github repo that’s been deleted. I was unable to find a fork of the repo or any other hosting of it.

Does anyone have a copy of this package, or know where I can get it?

0 Likes

#2

You may search meson tmlanguage on google. As for build system :man_shrugging:

Derived from https://github.com/TingPing/language-meson/blob/master/grammars/meson.json

Meson.sublime-syntax:

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
# Derived from https://github.com/TingPing/language-meson/blob/master/grammars/meson.json
name: Meson
file_extensions:
  - meson.build
  - meson_options.txt
scope: source.meson
contexts:
  main:
    - match: \#.*$
      scope: comment.line.meson
    - include: string_quoted_single
    - match: \b(if|else|elif|endif|foreach|endforeach)\b
      scope: keyword.control.flow.meson
    - match: \b(and|not|or)\b
      scope: keyword.operator.logical.meson
    - match: \b(true|false)\b
      scope: constant.language.meson
    - match: '\b([1-9]+[0-9]*\.[0-9]*)'
      scope: constant.numeric.float.meson
    - match: '\b(?i:(0x[0-9a-f]+))'
      scope: constant.numeric.integer.hexadecimal.meson
    - match: '\b([1-9]+[0-9]*|0)'
      scope: constant.numeric.integer.decimal.meson
    - match: \b(meson|host_machine|build_machine|target_machine)\b
      scope: support.variable.meson
    - match: '\b([\w_]+)\s*(?=:)'
      scope: variable.parameter.function.keyword.meson
    - match: <\=|>\=|\=\=|<|>|\!\=
      scope: keyword.operator.comparison.meson
    - match: \+\=
      scope: keyword.operator.assignment.augmented.meson
    - match: \=
      scope: keyword.operator.assignment.meson
    - match: \+|\-|\*|%|\/
      scope: keyword.operator.arithmetic.meson
    - match: |-
        (?x)\b(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
        )\b\s*(?=\()
      scope: support.function.builtin.meson
  constant_placeholder:
    - match: '(?i:(%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?([hL][a-z]|[a-z%]))|(\{([!\[\].:\w ]+)?\}))'
      scope: constant.other.placeholder.meson
  escaped_character:
    - match: ((\\\n)|(\\\\)|(\\')|(\\n)|(\\r)|(\\t))
      captures:
        1: constant.character.escape.newline.meson
        2: constant.character.escape.backlash.meson
        3: constant.character.escape.single-quote.meson
        4: constant.character.escape.linefeed.meson
        5: constant.character.escape.return.meson
        6: constant.character.escape.tab.meson
  string_quoted_single:
    - match: (?<!')(')(('))(?!')
      scope: string.quoted.single.single-line.meson
      captures:
        1: puncutation.definition.string.begin.meson
        2: puncutation.definition.string.end.meson
        3: meta.empty-string.single.meson
    - match: (''')
      captures:
        1: punctuation.definition.string.begin.meson
      push:
        - meta_scope: string.quoted.single.block.meson
        - match: ((?<=''')(')''|''')
          captures:
            1: punctuation.definition.string.end.meson
            2: meta.empty-string.single.meson
          pop: true
        - include: constant_placeholder
        - include: escaped_character
    - match: (')
      captures:
        1: punctuation.definition.string.begin.meson
      push:
        - meta_scope: string.quoted.single.single-line.meson
        - match: (')|(\n)
          captures:
            1: punctuation.definition.string.end.meson
            2: invalid.illegal.unclosed-string.meson
          pop: true
        - include: constant_placeholder
        - include: escaped_character
0 Likes

#3

You can just set the syntax to Python and it’ll highlight correctly I believe.

0 Likes

#4

I don’t think it’ll quite work eg. Meson uses function(arg : value) for keyword args but Python does function(arg = value); Meson has foreach but Python has for, etc.

0 Likes

#5

Wow thanks! I’d forgotten that ST can also use TM syntaxes, so that helps. Thanks for the conversion!

0 Likes