Skip to main content

HostContext

Struct HostContext 

Source
pub struct HostContext { /* private fields */ }
Expand description

Host state for one file, shared with the functions installed on ctx.

Debug is hand-written: requiring it on BindingResolver would burden every language implementation for the sake of one derive here.

Implementations§

Source§

impl HostContext

Source

pub fn new(tree: Tree, source: String, file_path: &str) -> Self

Build a context over a parsed file.

Source

pub fn with_resolver_from(self, language: &dyn Language) -> Self

Attach whatever resolver a language provides, if any.

Source

pub fn with_today(self, today: &str) -> Self

Supply the date rules see as ctx.today.

Fixed for the run by the caller, not read here: two files checked a millisecond apart must not disagree about what day it is. Without one, ctx.today is absent rather than empty — a rule comparing against undefined would silently take a branch nobody intended, where a missing property is a TypeError naming what it reached for.

Source

pub fn date_was_read(&self) -> bool

Whether anything read ctx.today while checking this file.

The caller needs this to decide whether the result may be cached across days.

Source

pub fn with_language(self, language: Arc<dyn Language>) -> Self

Attach the grammar querySubtree and closestAncestor compile queries against.

Without one they are absent rather than present-and-failing. A rule reaching for them then gets a TypeError naming the function, which is the truthful answer — a stub returning nothing would look like a query that matched nothing.

Source

pub fn with_resolver(self, resolver: Arc<dyn BindingResolver>) -> Self

Attach a binding resolver, enabling the import-resolution functions.

Without one, those functions return false or undefined rather than being absent. A rule written against a language that has no resolver then behaves as though nothing resolves, which is a truthful answer — where a missing function would be a TypeError blamed on the rule.

Source

pub fn with_file_access(self, files: Rc<FileAccess>) -> Self

Allow tracked reads of other files in the project.

Without one, readFile and fileExists are absent rather than present-and-failing. A rule reaching for them then gets a TypeError naming the function, which is the truthful answer — where a stub returning undefined would look like an empty project and produce a rule that silently checks nothing.

Source

pub fn arena(&self) -> &Rc<RefCell<NodeArena>>

The arena, for interning query captures before invoking a handler.

Source

pub fn take_reports(&self) -> Vec<Report>

Take everything reported so far, leaving the context empty.

Source

pub fn take_facts(&self) -> Vec<EmittedFact>

Take everything emitted so far, in emission order, leaving the context empty.

Source

pub fn build<'js>(&self, ctx: &Ctx<'js>) -> Result<Object<'js>>

Build the ctx object.

§Errors

Returns an engine error if a property cannot be defined, which would mean a broken build rather than anything about a rule.

Trait Implementations§

Source§

impl Clone for HostContext

Source§

fn clone(&self) -> HostContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HostContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ParallelSend for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.