Struct Parser

Source
pub struct Parser<'p> { /* private fields */ }
Expand description

The Parser struct and its related structs allow a caller to configure how AsciiDoc parsing occurs and then to initiate the parsing process.

Implementations§

Source§

impl<'p> Parser<'p>

Source

pub fn parse<'src>(&self, source: &'src str) -> Document<'src>

Parse a UTF-8 string as an AsciiDoc document.

Note that the document references the underlying source string and necessarily has the same lifetime as the source.

The Document data structure returned by this call and nearly all data structures contained within it are gated by the lifetime of the source text passed in to this function. For that reason all of those data structures are given the lifetime 'src.

IMPORTANT: The AsciiDoc language documentation states that UTF-16 encoding is allowed if a byte-order-mark (BOM) is present at the start of a file. This format is not directly supported by the asciidoc-parser crate. Any UTF-16 content must be re-encoded as UTF-8 prior to parsing.

§Warnings, not errors

Any UTF-8 string is a valid AsciiDoc document, so this function does not return an Option or Result data type. There may be any number of character sequences that have ambiguous or potentially unintended meanings. For that reason, a caller is advised to review the warnings provided via the warnings() iterator.

Source

pub fn attribute_value<N: AsRef<str>>(&self, name: N) -> InterpretedValue<'p>

Retrieves the current interpreted value of a document attribute.

Each document holds a set of name-value pairs called document attributes. These attributes provide a means of configuring the AsciiDoc processor, declaring document metadata, and defining reusable content. This page introduces document attributes and answers some questions about the terminology used when referring to them.

§What are document attributes?

Document attributes are effectively document-scoped variables for the AsciiDoc language. The AsciiDoc language defines a set of built-in attributes, and also allows the author (or extensions) to define additional document attributes, which may replace built-in attributes when permitted.

Built-in attributes either provide access to read-only information about the document and its environment or allow the author to configure behavior of the AsciiDoc processor for a whole document or select regions. Built-in attributes are effectively unordered. User-defined attribute serve as a powerful text replacement tool. User-defined attributes are stored in the order in which they are defined.

Source

pub fn with_intrinsic_attribute<N: AsRef<str>, V: AsRef<str>>( self, name: N, value: V, modification_context: ModificationContext, ) -> Self

Sets the value of an intrinsic attribute.

Intrinsic attributes are set automatically by the processor. These attributes provide information about the document being processed (e.g., docfile), the security mode under which the processor is running (e.g., safe-mode-name), and information about the user’s environment (e.g., user-home).

The modification_context establishes whether the value can be subsequently modified by the document header and/or in the document body.

Subsequent calls to this function or with_intrinsic_attribute_bool() are always permitted. The last such call for any given attribute name takes precendence.

Source

pub fn with_intrinsic_attribute_bool<N: AsRef<str>>( self, name: N, value: bool, modification_context: ModificationContext, ) -> Self

Sets the value of an intrinsic attribute from a boolean flag.

A boolean true is interpreted as “set.” A boolean false is interpreted as “unset.”

Intrinsic attributes are set automatically by the processor. These attributes provide information about the document being processed (e.g., docfile), the security mode under which the processor is running (e.g., safe-mode-name), and information about the user’s environment (e.g., user-home).

The modification_context establishes whether the value can be subsequently modified by the document header and/or in the document body.

Subsequent calls to this function or with_intrinsic_attribute() are always permitted. The last such call for any given attribute name takes precendence.

Trait Implementations§

Source§

impl<'p> Clone for Parser<'p>

Source§

fn clone(&self) -> Parser<'p>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'p> Debug for Parser<'p>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'p> Default for Parser<'p>

Source§

fn default() -> Parser<'p>

Returns the “default value” for a type. Read more
Source§

impl<'p> PartialEq for Parser<'p>

Source§

fn eq(&self, other: &Parser<'p>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'p> Eq for Parser<'p>

Source§

impl<'p> StructuralPartialEq for Parser<'p>

Auto Trait Implementations§

§

impl<'p> Freeze for Parser<'p>

§

impl<'p> RefUnwindSafe for Parser<'p>

§

impl<'p> Send for Parser<'p>

§

impl<'p> Sync for Parser<'p>

§

impl<'p> Unpin for Parser<'p>

§

impl<'p> UnwindSafe for Parser<'p>

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> 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.