pub struct ShapeSet { /* private fields */ }Expand description
The declarations a lex and a parse share.
Implementations§
Source§impl ShapeSet
impl ShapeSet
Sourcepub fn consults_library(&self) -> bool
pub fn consults_library(&self) -> bool
Whether a parse against this set resolves a name it does not declare from the shipped library.
Sourcepub fn base_dir(&self) -> Option<&Path>
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.
Sourcepub fn set_base_dir(&mut self, dir: Option<PathBuf>)
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.
Sourcepub fn declare_file(&mut self, path: &Path) -> Result<(), ShapeError>
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.
Sourcepub fn declare_file_members(
&mut self,
path: &Path,
) -> Result<Vec<(String, Pattern)>, ShapeError>
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn shapes(&self) -> &[TokenShape]
pub fn shapes(&self) -> &[TokenShape]
The declared shapes, in declaration order.
Sourcepub fn pattern_kinds(&self) -> &[PatternKind]
pub fn pattern_kinds(&self) -> &[PatternKind]
The kinds declared from patterns, in declaration order.
Sourcepub fn id_of(&self, name: &str) -> Option<u8>
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.
Sourcepub fn name_of(&self, id: u8) -> Option<&str>
pub fn name_of(&self, id: u8) -> Option<&str>
The name of the shape or kind id, here or in the shipped library.
Sourcepub fn let_of(&self, name: &str) -> Option<&Pattern>
pub fn let_of(&self, name: &str) -> Option<&Pattern>
The sub-pattern declared under name, the last so declared.
Sourcepub fn fields_of(&self, name: &str) -> Option<&[FieldMark]>
pub fn fields_of(&self, name: &str) -> Option<&[FieldMark]>
The fields a fields line gives the sub-pattern name, in order.
Sourcepub fn declare_fields(&mut self, decl: &str) -> Result<(), ShapeError>
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.
Sourcepub fn is_free(&self, name: &str) -> bool
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.
Sourcepub fn declare(
&mut self,
decl: &str,
precedence: Precedence,
) -> Result<u8, ShapeError>
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.
Sourcepub fn declare_kind(&mut self, decl: &str) -> Result<u8, ShapeError>
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.
Sourcepub fn declare_let(&mut self, decl: &str) -> Result<(), ShapeError>
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.
Sourcepub fn declare_test(
&mut self,
decl: &str,
line: usize,
) -> Result<(), ShapeError>
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.
Sourcepub fn run_tests(&self) -> Vec<TestFailure>
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.
Sourcepub fn declare_text(&mut self, text: &str) -> Result<(), ShapeError>
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.
Sourcepub fn declare_lines(
&mut self,
text: &str,
members: Option<&mut Vec<(String, Pattern)>>,
) -> Result<(), ShapeError>
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
Sourcepub fn longest_at(
&self,
input: &[u8],
i: usize,
when: Precedence,
) -> Option<(u8, usize)>
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.