[−][src]Struct liblet::symbol::Symbol
The main type of this module. It provides abstraction over symbols. Great to work with correct dataset when dealing with grammars and productions, or similar.
A Symbol can be made of every ascii-graphic chars,
like the one described in rust documentation
for chars ascii_graphic
method, which accept chars going from U+0021 '!' ..= U+007E '~', including 'ε', the "empty word" symbol.
Symbols can be logically divided in 2 major categories, defined as follow:
- non terminals, which start with an uppercase letter (A-Z)
- terminals, which start with everything else
Checking if a symbol is terminal or non terminal can be done using the according boolean methods you can find below.
A symbol can be created easily from strings, following these rules:
- string can contain any number of whitespace
- string has to contain at least one valid char (see above)
- string can't contain anything else
It also implements the IntoIterator
to iterate over the collection of chars which make up the Symbol.
Implementations
impl Symbol
[src]
pub fn new(string: &str) -> Result<Symbol, SymbolError>
[src]
Creates a new Symbol based on the chars in the input.
Errors
It can return an error if the input is empty or contains invalid chars.
Examples
use liblet::symbol::Symbol; // create a new symbol based from the string "mysymbol" let symbol = Symbol::new("mysymbol"); assert!(symbol.is_ok());
pub fn as_str(&self) -> &str
[src]
Return the &str
representing this symbol chars.
Examples
use liblet::symbol::Symbol; // create a new symbol based from the string "mysymbol" let symbol = Symbol::new("mysymbol")?; assert_eq!(symbol.as_str(), "mysymbol");
pub fn to_string(&self) -> String
[src]
Return the String
representing this symbol chars.
Examples
use liblet::symbol::Symbol; // create a new symbol based from the string "mysymbol" let symbol = Symbol::new("mysymbol")?; assert_eq!(symbol.to_string(), String::from("mysymbol"));
pub fn is_terminal(&self) -> bool
[src]
Check if symbol is terminal.
You can expect the call to is_non_terminal
to return an opposite result.
true
if symbol is terminal, false
otherwise
Examples
use liblet::symbol::Symbol; // create a new symbol based from the string "mysymbol" let symbol = Symbol::new("mysymbol").unwrap(); assert!(symbol.is_terminal()); assert!(!symbol.is_non_terminal());
pub fn is_non_terminal(&self) -> bool
[src]
Check if symbol is non terminal.
You can expect the call to is_terminal
to return an opposite result.
true
if symbol is non terminal, false
otherwise
Examples
use liblet::symbol::Symbol; // create a new symbol based from the string "Mysymbol" let symbol = Symbol::new("Mysymbol")?; assert!(symbol.is_non_terminal()); assert!(!symbol.is_terminal());
pub fn is_valid_char(c: &char) -> bool
[src]
Check if char is a valid symbol char.
true
if char is a valid symbol char, false
otherwise
Examples
use liblet::symbol::Symbol; assert!(Symbol::is_valid_char(&'c')); assert!(!Symbol::is_valid_char(&'\n'));
pub fn is_valid_symbol(string: &str) -> bool
[src]
Check if a string is a valid symbol.
true
if the string is a valid symbol, false
otherwise
Examples
use liblet::symbol::Symbol; assert!(Symbol::is_valid_symbol("A")); assert!(!Symbol::is_valid_symbol("\n"));
pub fn from_string(string: &str) -> Result<Vec<Symbol>, SymbolError>
[src]
Create a collection of symbols from a raw input string.
Errors
Can return an error if the raw string can't be parsed to obtain actual symbols both due to wrong string formatting (symbols should be contiguous chars separated between them by every kind of whitespace) and due to symbol creation error (invalid char, empty symbol, etc.).
In the case an empty or whitespace only string is given, it just returns an empty collection of symbols.
Examples
use liblet::symbol::Symbol; let result = Symbol::from_string("A B C")?; assert_eq!(result.len(), 3);
pub fn epsilon() -> Symbol
[src]
Return a new symbol which represents the empty symbol 'ε'.
Examples
use liblet::symbol::Symbol; let symbol = Symbol::epsilon(); assert_eq!(symbol.to_string(), "ε");
pub fn is_epsilon(&self) -> bool
[src]
Check if a symbol is the empty symbol ε.
Return true
if it is, false
otherwise.
Examples
use liblet::symbol::{Symbol,symbol}; let symbol_epsilon = Symbol::epsilon(); let symbol_other = symbol("A"); assert!(symbol_epsilon.is_epsilon()); assert!(!symbol_other.is_epsilon());
Trait Implementations
impl Clone for Symbol
[src]
impl Debug for Symbol
[src]
impl<'de> Deserialize<'de> for Symbol
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Symbol
[src]
impl Eq for Symbol
[src]
impl Hash for Symbol
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> IntoIterator for &'a Symbol
[src]
type Item = char
The type of the elements being iterated over.
type IntoIter = Chars<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl Ord for Symbol
[src]
fn cmp(&self, other: &Symbol) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Symbol> for Symbol
[src]
impl PartialOrd<Symbol> for Symbol
[src]
fn partial_cmp(&self, other: &Symbol) -> Option<Ordering>
[src]
fn lt(&self, other: &Symbol) -> bool
[src]
fn le(&self, other: &Symbol) -> bool
[src]
fn gt(&self, other: &Symbol) -> bool
[src]
fn ge(&self, other: &Symbol) -> bool
[src]
impl Serialize for Symbol
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for Symbol
[src]
impl StructuralPartialEq for Symbol
[src]
impl<'_> TryFrom<&'_ str> for Symbol
[src]
Auto Trait Implementations
impl RefUnwindSafe for Symbol
impl Send for Symbol
impl Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,