syntax.Languages
class pub Languages
A registry of languages and their lexers.
A Languages
registry is useful for consumers that want to support multiple
languages, without having to map language names to the corresponding lexers
themselves.
Examples
Getting a language using a name, and creating its lexer:
import syntax (Languages)
let langs = Languages.new
langs.for_name('inko').unwrap.create('# test'.to_byte_array)
Getting a language using a file name:
import syntax (Languages)
let langs = Languages.new
langs.for_filename('*.inko').unwrap.create('# test'.to_byte_array)
Static methods
empty
Show source codeHide source code
fn pub static empty -> Languages {
Languages(aliases: Map.new, map: Map.new)
}
fn pub static empty -> Languages
Returns a new empty registry.
You'll probably want to use Languages.new
in most cases. This method is
meant for cases where you only want a subset of the available languages, and
are OK with registering them yourself.
new
Show source codeHide source code
fn pub static new -> Languages {
let langs = empty
c.register(langs)
fish.register(langs)
inko.register(langs)
make.register(langs)
ruby.register(langs)
rust.register(langs)
shell.register(langs)
toml.register(langs)
langs
}
fn pub static new -> Languages
Returns a new registry, containing all default lexers.
Instance methods
add
Show source codeHide source code
fn pub mut add(language: Language) {
language.aliases.iter.each(fn (name) { @aliases.set(name, language) })
@map.set(language.name, language)
}
fn pub mut add(language: Language)
Registers a new language.
get
Show source codeHide source code
fn pub mut get(name: String) -> Option[mut Language] {
@map.opt_mut(name).else(fn { @aliases.opt_mut(name) })
}
fn pub mut get(name: String) -> Option[mut Language]
Returns the language for the given name.
If the name isn't recognized, a None
is returned.