tokenize

Function tokenize 

Source
pub fn tokenize(content: &str) -> Result<Vec<Token>, TokenizationError>
Expand description

Tokenizes the provided content string and produces a vector of tokens.

This function is part of the bracoxide crate and is used to tokenize a given string content. The tokenization process splits the string into meaningful units called tokens, which can be further processed or analyzed as needed.

§Arguments

  • content - The string to be tokenized.

§Returns

  • Result<Vec<Token>, TokenizationError> - A result that contains a vector of tokens if the tokenization is successful, or a TokenizationError if an error occurs during the tokenization process.

§Errors

The function can return the following errors:

§Examples

use bracoxide::tokenizer::{Token, TokenizationError, tokenize};

let content = "{1, 2, 3}";
let tokens = tokenize(content);

match tokens {
    Ok(tokens) => {
        println!("Tokenization successful!");
        for token in tokens {
            println!("{:?}", token);
        }
    }
    Err(error) => {
        eprintln!("Tokenization failed: {:?}", error);
    }
}

In this example, the tokenize function from the bracoxide crate is used to tokenize the content string “{1, 2, 3}”. If the tokenization is successful, the resulting tokens are printed. Otherwise, the corresponding error is displayed.