[−][src]Struct erl_tokenize::tokens::CharToken
Character token.
Examples
use erl_tokenize::Position; use erl_tokenize::tokens::CharToken; let pos = Position::new(); // Ok assert_eq!(CharToken::from_text("$a", pos.clone()).unwrap().value(), 'a'); assert_eq!(CharToken::from_text("$a ", pos.clone()).unwrap().value(), 'a'); assert_eq!(CharToken::from_text(r"$\t", pos.clone()).unwrap().value(), '\t'); assert_eq!(CharToken::from_text(r"$\123", pos.clone()).unwrap().value(), 'I'); assert_eq!(CharToken::from_text(r"$\x6F", pos.clone()).unwrap().value(), 'o'); assert_eq!(CharToken::from_text(r"$\x{06F}", pos.clone()).unwrap().value(), 'o'); assert_eq!(CharToken::from_text(r"$\^a", pos.clone()).unwrap().value(), '\u{1}'); // Err assert!(CharToken::from_text(" $a", pos.clone()).is_err()); assert!(CharToken::from_text(r"$\", pos.clone()).is_err()); assert!(CharToken::from_text("a", pos.clone()).is_err());
Methods
impl CharToken
[src]
pub fn from_value(value: char, pos: Position) -> Self
[src]
Makes a new CharToken
instance from the value.
Examples
use erl_tokenize::Position; use erl_tokenize::tokens::CharToken; let pos = Position::new(); assert_eq!(CharToken::from_value('a', pos.clone()).text(), "$a");
pub fn from_text(text: &str, pos: Position) -> Result<Self>
[src]
Tries to convert from any prefixes of the text to a CharToken
.
pub fn value(&self) -> char
[src]
Returns the value of this token.
Example
use erl_tokenize::Position; use erl_tokenize::tokens::CharToken; let pos = Position::new(); assert_eq!(CharToken::from_text("$a", pos.clone()).unwrap().value(), 'a'); assert_eq!(CharToken::from_text(r"$\123", pos.clone()).unwrap().value(), 'I');
pub fn text(&self) -> &str
[src]
Returns the original textual representation of this token.
Example
use erl_tokenize::Position; use erl_tokenize::tokens::CharToken; let pos = Position::new(); assert_eq!(CharToken::from_text("$a", pos.clone()).unwrap().text(), "$a"); assert_eq!(CharToken::from_text(r"$\123", pos.clone()).unwrap().text(), r#"$\123"#);
Trait Implementations
impl PositionRange for CharToken
[src]
fn start_position(&self) -> Position
[src]
fn end_position(&self) -> Position
[src]
impl From<CharToken> for LexicalToken
[src]
impl From<CharToken> for Token
[src]
impl Clone for CharToken
[src]
fn clone(&self) -> CharToken
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for CharToken
[src]
impl Display for CharToken
[src]
Auto Trait Implementations
Blanket Implementations
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> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,