Skip to main content

ShapeSet

Struct ShapeSet 

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

The declarations a lex and a parse share.

Implementations§

Source§

impl ShapeSet

Source

pub fn new() -> Self

An empty set.

Source

pub fn consults_library(&self) -> bool

Whether a parse against this set resolves a name it does not declare from the shipped library.

Source

pub fn base_dir(&self) -> Option<&Path>

The directory a relative @file set is read from during a parse against this set, or none for the current directory.

Source

pub fn set_base_dir(&mut self, dir: Option<PathBuf>)

Read a relative @file in a pattern parsed against this set, or in a line declared into it, from dir, or from the current directory where it is None. A pattern file declared into the set reads its own from beside the file whatever this says.

Source

pub fn declare_file(&mut self, path: &Path) -> Result<(), ShapeError>

Declare everything the pattern file at path says, as Self::declare_text does, with a relative @file set in it read from beside the file. A file whose byte-order mark declares UTF-8, UTF-16 or UTF-32 is read as its text, as an input to a scan is.

§Errors

The file cannot be read, or a line of it is refused.

Source

pub fn declare_file_members( &mut self, path: &Path, ) -> Result<Vec<(String, Pattern)>, ShapeError>

The pattern file at path declared as Self::declare_file declares it, and the named patterns a set built from it holds, in order: each let and rule under its name, and each line that is no declaration under its line number.

§Errors

The file cannot be read, or a line of it is refused.

Source

pub fn is_empty(&self) -> bool

Whether nothing here changes a lex: no shape and no kind from a pattern. Named sub-patterns bear on the parse alone.

Source

pub fn shapes(&self) -> &[TokenShape]

The declared shapes, in declaration order.

Source

pub fn pattern_kinds(&self) -> &[PatternKind]

The kinds declared from patterns, in declaration order.

Source

pub fn lets(&self) -> &[(String, Pattern)]

The named sub-patterns, in declaration order.

Source

pub fn tests(&self) -> &[LibTest]

The test lines declared, in declaration order.

Source

pub fn rules(&self) -> &[Rule]

The rules declared, in declaration order.

Source

pub fn rule_of(&self, name: &str) -> Option<&Rule>

The rule declared under name.

Source

pub fn id_of(&self, name: &str) -> Option<u8>

The id of the shape or kind called name: the payload of its crate::token::TokenKind::Custom.

Source

pub fn name_of(&self, id: u8) -> Option<&str>

The name of the shape or kind id, here or in the shipped library.

Source

pub fn let_of(&self, name: &str) -> Option<&Pattern>

The sub-pattern declared under name, the last so declared.

Source

pub fn fields_of(&self, name: &str) -> Option<&[FieldMark]>

The fields a fields line gives the sub-pattern name, in order.

Source

pub fn declare_fields(&mut self, decl: &str) -> Result<(), ShapeError>

Record a fields line, NAME {mark}...: the fields of the sub-pattern declared as NAME before it, in order, each a mark with the example text left out, as crate::infer::marks::field_marks reads them.

§Errors

A name no sub-pattern is declared under, a second fields line for one, a line naming no field, a mark that does not read, a field named twice, and a field the sub-pattern binds no register under or reads through an accessor that is not one.

Source

pub fn is_free(&self, name: &str) -> bool

Whether a declaration here can take name without shadowing any other: alphanumerics and underscores, not a built-in atom’s, not a shape, kind or sub-pattern declared here, and not an entry of the shipped library.

Source

pub fn declare( &mut self, decl: &str, precedence: Precedence, ) -> Result<u8, ShapeError>

Declare a shape from name = followed by a backtick byte-pattern.

§Errors

Rejects a malformed declaration, an unparseable byte-pattern, an unbounded one, a duplicate name, a name held by a built-in atom, or more shapes and kinds than the ids below LIBRARY_ID_BASE hold.

Source

pub fn declare_kind(&mut self, decl: &str) -> Result<u8, ShapeError>

Declare a kind from name = followed by a pattern over the stream, parsed against the declarations so far.

§Errors

Rejects a malformed declaration, a pattern that does not parse, a duplicate name, a name held by a built-in atom, or more shapes and kinds than the ids below LIBRARY_ID_BASE hold.

Source

pub fn declare_let(&mut self, decl: &str) -> Result<(), ShapeError>

Declare a named sub-pattern from name = followed by a pattern, parsed against the declarations so far; a later declaration of the same name shadows this one.

§Errors

Rejects a malformed declaration, a pattern that does not parse, or a name held by a built-in atom or by a shape or kind here.

Source

pub fn declare_test( &mut self, decl: &str, line: usize, ) -> Result<(), ShapeError>

Record a test line from NAME accepts "text"... reads "span" in "text"... rejects "text"...: the name, then any number of clauses, accepts and rejects each followed by the double-quoted texts it covers and reads by one span and the one text it is read out of, at least one text in all. A text reads \", \\, \n and \t.

§Errors

Rejects a malformed line: a name that is not alphanumerics and underscores, a word that is no keyword, a text before any keyword, a reads whose span stands without in or without the text after it, an unterminated text or an unknown escape, or no text at all.

Source

pub fn run_tests(&self) -> Vec<TestFailure>

Run every test line declared here against what the set finally declares, so a test stands anywhere in its file. A name accepts a text when its match in the text is the whole of it, from the first significant token to the last, and rejects a text when it matches nowhere in it. The expectations not met, in line order; a failing accepts carries the lex of its text on a second line of its message.

Source

pub fn declare_text(&mut self, text: &str) -> Result<(), ShapeError>

Declare everything a pattern file says: let NAME = PATTERN, kind NAME = PATTERN, shape NAME = BYTES, `shape-after NAME = `BYTES and test NAME accepts "text"... rejects "text"... one a line, and a rule as a block, rule NAME over indented field = value lines, or as one line, rule NAME [severity] "message" = PATTERN, its other fields as fix NAME = TEMPLATE, meta NAME KEY = VALUE, files NAME = GLOBS, unless NAME = PATTERN, record NAME = UNIT, record-start NAME = PATTERN and record-span NAME = PATTERN lines below it. Blank lines and lines opening with # are skipped. A fields line gives a sub-pattern’s fields, as Self::declare_fields reads it.

§Errors

The first line that is not a declaration, or whose declaration is refused, with its line number in the message.

Source

pub fn declare_lines( &mut self, text: &str, members: Option<&mut Vec<(String, Pattern)>>, ) -> Result<(), ShapeError>

Self::declare_text, collecting into members the named patterns a set built from the file holds, in order: each let and rule under its name, and each line that is no declaration, parsed as a pattern against the declarations so far, under its line number. A line that is no declaration is refused where no members are collected.

§Errors

As Self::declare_text.

Source

pub fn longest_at( &self, input: &[u8], i: usize, when: Precedence, ) -> Option<(u8, usize)>

The longest shape matching at i, as (id, end), among those with the given precedence whose guard accepts the bytes. A longer span wins; equal spans go to the earlier declaration.

Trait Implementations§

Source§

impl Clone for ShapeSet

Source§

fn clone(&self) -> Self

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 ShapeSet

Source§

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

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

impl Default for ShapeSet

Source§

fn default() -> Self

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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.