Skip to main content

PrologBackend

Struct PrologBackend 

Source
pub struct PrologBackend {
    pub swi_mode: bool,
    pub utf8_encoding: bool,
    pub options: PrologBackendOptions,
}
Expand description

The Prolog code generation backend.

Converts a PrologModule (or individual items) into .pl source text.

Fields§

§swi_mode: bool

Whether to emit SWI-Prolog-specific pragmas (:- use_module(library(lists))).

§utf8_encoding: bool

Whether to add :- encoding(utf8). at the top.

§options: PrologBackendOptions

Extra options reserved for future use.

Implementations§

Source§

impl PrologBackend

Source

pub fn new() -> Self

Create a backend in default (ISO) mode.

Source

pub fn swi() -> Self

Create a backend targeting SWI-Prolog.

Source

pub fn emit_module(&self, module: &PrologModule) -> String

Emit a complete PrologModule as .pl source text.

Source

pub fn emit_clause(&self, clause: &PrologClause) -> String

Emit a single clause.

Source

pub fn emit_predicate(&self, pred: &PrologPredicate) -> String

Emit a single predicate.

Source

pub fn emit_dcg(&self, rule: &DcgRule) -> String

Emit a single DCG rule.

Source

pub fn emit_directive(&self, directive: &PrologDirective) -> String

Emit a single directive.

Source

pub fn emit_clauses(&self, clauses: &[PrologClause]) -> String

Emit a list of clauses separated by newlines.

Source

pub fn build_swi_preamble( &self, module_name: &str, exports: &[(&str, usize)], libraries: &[&str], ) -> String

Build a standard SWI-Prolog module preamble.

Trait Implementations§

Source§

impl Debug for PrologBackend

Source§

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

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

impl Default for PrologBackend

Source§

fn default() -> PrologBackend

Returns the “default value” for a type. 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> 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, 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.