pub fn register_syntaxes<'a>(
definitions: impl IntoIterator<Item = &'a str>,
) -> Result<(), SyntaxRegistrationError>Expand description
Adds syntax definitions, in Sublime Text’s .sublime-syntax format, to the
set every editor highlights with.
A definition is chosen like the bundled ones, by the file extensions it
lists (file_extensions) matching the editor’s syntax name. Registered
syntaxes are looked up before the bundled ones, so one can replace a bundled
syntax; among registered ones claiming the same extension, the one
registered last wins.
Registered syntaxes form a set of their own, which keeps building it cheap
(adding to the bundled set would re-link every bundled grammar). They can
include each other by scope (include: scope:source.zig), but not the
bundled ones: register the grammars a definition includes along with it.
An include that resolves to nothing is ignored.
The set is built once per process, the first time an editor highlights text, so call this before that, typically at startup. All or nothing: if one definition does not parse, none is registered.
§Errors
SyntaxRegistrationError::Parse for an invalid definition, and
SyntaxRegistrationError::AlreadyBuilt when the set already exists.
§Example
let ini = r#"
name: Tiny INI
file_extensions: [tini]
scope: source.tini
contexts:
main:
- match: '^\[.*\]$'
scope: entity.name.section.tini
"#;
iced_code_editor::register_syntaxes([ini]).expect("valid syntax");