pub struct GrammarRegistry { /* private fields */ }Expand description
A collection of TextMate JSON grammars and their external include scopes.
Implementations§
Source§impl GrammarRegistry
impl GrammarRegistry
Sourcepub fn with_limits(limits: GrammarLimits) -> Self
pub fn with_limits(limits: GrammarLimits) -> Self
Creates an empty registry with the supplied limits, clamped to at least one.
Sourcepub fn add_json(&mut self, json: &str) -> Result<GrammarId>
pub fn add_json(&mut self, json: &str) -> Result<GrammarId>
Parses and adds one JSON TextMate grammar.
Add every grammar referenced through an external include before constructing a tokenizer.
Sourcepub fn validate_regexes(&self) -> Result<()>
pub fn validate_regexes(&self) -> Result<()>
Checks every registered regex for parser diagnostics, returning the first.
This opt-in check does not change loading or tokenization. The engine is permissive and can skip malformed or unsupported constructs. A diagnostic may describe unsupported syntax rather than invalid Oniguruma syntax. Positions count Unicode scalar values from zero within the pattern.
use syntaxmate::{Error, GrammarErrorKind, GrammarRegistry};
let mut registry = GrammarRegistry::new();
registry.add_json(r#"{"scopeName":"source.demo","patterns":[{"match":"é)"}]}"#)?;
match registry.validate_regexes() {
Err(Error::Grammar(error)) => {
assert_eq!(error.scope_name(), Some("source.demo"));
if let GrammarErrorKind::InvalidRegex(regex) = error.kind() {
assert_eq!(regex.pattern(), "é)");
assert_eq!(regex.position(), 1);
}
}
result => panic!("expected a regex diagnostic: {result:?}"),
}Sourcepub fn grammar_count(&self) -> usize
pub fn grammar_count(&self) -> usize
Returns the number of registered grammars.
Trait Implementations§
Source§impl Clone for GrammarRegistry
impl Clone for GrammarRegistry
Source§impl Debug for GrammarRegistry
impl Debug for GrammarRegistry
Auto Trait Implementations§
impl Freeze for GrammarRegistry
impl RefUnwindSafe for GrammarRegistry
impl Send for GrammarRegistry
impl Sync for GrammarRegistry
impl Unpin for GrammarRegistry
impl UnsafeUnpin for GrammarRegistry
impl UnwindSafe for GrammarRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more