[][src]Struct liblet::symbol::Symbol

pub struct Symbol { /* fields omitted */ }

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]

impl Display for Symbol[src]

impl Eq for Symbol[src]

impl Hash for Symbol[src]

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?

impl Ord for Symbol[src]

impl PartialEq<Symbol> for Symbol[src]

impl PartialOrd<Symbol> for Symbol[src]

impl Serialize for Symbol[src]

impl StructuralEq for Symbol[src]

impl StructuralPartialEq for Symbol[src]

impl<'_> TryFrom<&'_ str> for Symbol[src]

type Error = SymbolError

The type returned in the event of a conversion error.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.