Email Address Lexer (lexing/email_address.rs)

harper · dev-tools, email, lexer, validation, token, parsing

Lexes and validates email addresses, ensuring proper local‑part syntax and domain parsing within a character limit.

// Source: https://github.com/mperkins0155/harper | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use itertools::Itertools;

use super::FoundToken;
use super::hostname::lex_hostname;
use crate::TokenKind;

/// The maximum length of an email address, in characters.
pub(crate) const MAX_EMAIL_LEN: usize = 254;

pub fn lex_email_address(source: &[char]) -> Option<FoundToken> {
    let source = &source[..usize::min(source.len(), MAX_EMAIL_LEN)];

    // Location of the @ sign
    let at_loc = {
        let mut iter = source.iter().enumerate();
        // Assuming we don't start lexing in the middle of a local-part, i.e. we start unquoted.
        let mut in_quote = false;
        // L

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key