docs: refman: add vim syntax file generator

Signed-off-by: Liam Beguin <liambeguin@gmail.com>
pull/12165/head
Liam Beguin 1 year ago committed by Eli Schwartz
parent c663476075
commit ba1ba1f5b0
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 37
      docs/refman/generatorvim.py
  2. 4
      docs/refman/main.py
  3. 103
      docs/refman/templates/meson.vim.mustache

@ -0,0 +1,37 @@
# SPDX-License-Identifer: Apache-2.0
# Copyright 2023 The Meson development team
from __future__ import annotations
from pathlib import Path
from .generatorbase import GeneratorBase
from .model import ReferenceManual
class GeneratorVim(GeneratorBase):
def __init__(self, manual: ReferenceManual, out_dir: Path) -> None:
super().__init__(manual)
self.out_dir = out_dir
def generate(self) -> None:
template_dir = Path(__file__).resolve().parent / 'templates'
outname = 'meson.vim'
template_name = f'{outname}.mustache'
template_file = template_dir / template_name
builtin_funcs = [f.name for f in self.sorted_and_filtered(self.functions)]
data = {
'builtin_funcs': '\n \\ '.join(builtin_funcs)
}
# Import here, so that other generators don't also depend on it
import chevron
result = chevron.render(
template=template_file.read_text(encoding='utf-8'),
data=data,
warn=True,
)
self.out_dir.mkdir(parents=True, exist_ok=True)
out_file = self.out_dir / outname
out_file.write_text(result, encoding='utf-8')

@ -28,13 +28,14 @@ from .generatorprint import GeneratorPrint
from .generatorpickle import GeneratorPickle
from .generatormd import GeneratorMD
from .generatorman import GeneratorMan
from .generatorvim import GeneratorVim
meson_root = Path(__file__).absolute().parents[2]
def main() -> int:
parser = argparse.ArgumentParser(description='Meson reference manual generator')
parser.add_argument('-l', '--loader', type=str, default='yaml', choices=['yaml', 'fastyaml', 'pickle'], help='Information loader backend')
parser.add_argument('-g', '--generator', type=str, choices=['print', 'pickle', 'md', 'json', 'man'], required=True, help='Generator backend')
parser.add_argument('-g', '--generator', type=str, choices=['print', 'pickle', 'md', 'json', 'man', 'vim'], required=True, help='Generator backend')
parser.add_argument('-s', '--sitemap', type=Path, default=meson_root / 'docs' / 'sitemap.txt', help='Path to the input sitemap.txt')
parser.add_argument('-o', '--out', type=Path, required=True, help='Output directory for generated files')
parser.add_argument('-i', '--input', type=Path, default=meson_root / 'docs' / 'yaml', help='Input path for the selected loader')
@ -66,6 +67,7 @@ def main() -> int:
'md': lambda: GeneratorMD(refMan, args.out, args.sitemap, args.link_defs, not args.no_modules),
'json': lambda: GeneratorJSON(refMan, args.out, not args.no_modules),
'man': lambda: GeneratorMan(refMan, args.out, not args.no_modules),
'vim': lambda: GeneratorVim(refMan, args.out),
}
generator = generators[args.generator]()

@ -0,0 +1,103 @@
" Vim syntax file
" Language: Meson
" License: VIM License
" Maintainer: Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
" Liam Beguin <liambeguin@gmail.com>
" Last Change: 2023 Aug 27
" Credits: Zvezdan Petkovic <zpetkovic@acm.org>
" Neil Schemenauer <nas@meson.ca>
" Dmitry Vasiliev
"
" This version is copied and edited from python.vim
" It's very basic, and doesn't do many things I'd like it to
" For instance, it should show errors for syntax that is valid in
" Python but not in Meson.
"
" Optional highlighting can be controlled using these variables.
"
" let meson_space_error_highlight = 1
"
if exists("b:current_syntax")
finish
endif
" We need nocompatible mode in order to continue lines with backslashes.
" Original setting will be restored.
let s:cpo_save = &cpo
set cpo&vim
" http://mesonbuild.com/Syntax.html
syn keyword mesonConditional elif else if endif
syn keyword mesonRepeat foreach endforeach
syn keyword mesonOperator and not or in
syn keyword mesonStatement continue break
syn match mesonComment "#.*$" contains=mesonTodo,@Spell
syn keyword mesonTodo FIXME NOTE NOTES TODO XXX contained
" Strings can either be single quoted or triple counted across multiple lines,
" but always with a '
syn region mesonString
\ start="\z('\)" end="\z1" skip="\\\\\|\\\z1"
\ contains=mesonEscape,@Spell
syn region mesonString
\ start="\z('''\)" end="\z1" keepend
\ contains=mesonEscape,mesonSpaceError,@Spell
syn match mesonEscape "\\[abfnrtv'\\]" contained
syn match mesonEscape "\\\o\{1,3}" contained
syn match mesonEscape "\\x\x\{2}" contained
syn match mesonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
" Meson allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
syn match mesonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
syn match mesonEscape "\\$"
" Meson only supports integer numbers
" http://mesonbuild.com/Syntax.html#numbers
syn match mesonNumber "\<\d\+\>"
syn match mesonNumber "\<0x\x\+\>"
syn match mesonNumber "\<0o\o\+\>"
" booleans
syn keyword mesonBoolean false true
" Built-in functions
syn keyword mesonBuiltin
\ build_machine
\ host_machine
\ meson
\ option
\ target_machine
\ {{builtin_funcs}}
if exists("meson_space_error_highlight")
" trailing whitespace
syn match mesonSpaceError display excludenl "\s\+$"
" mixed tabs and spaces
syn match mesonSpaceError display " \+\t"
syn match mesonSpaceError display "\t\+ "
endif
" The default highlight links. Can be overridden later.
hi def link mesonStatement Statement
hi def link mesonConditional Conditional
hi def link mesonRepeat Repeat
hi def link mesonOperator Operator
hi def link mesonComment Comment
hi def link mesonTodo Todo
hi def link mesonString String
hi def link mesonEscape Special
hi def link mesonNumber Number
hi def link mesonBuiltin Function
hi def link mesonBoolean Boolean
if exists("meson_space_error_highlight")
hi def link mesonSpaceError Error
endif
let b:current_syntax = "meson"
let &cpo = s:cpo_save
unlet s:cpo_save
" vim:set sw=2 sts=2 ts=8 noet:
Loading…
Cancel
Save