nash-parse 0.6.1

Parser for the nash programming language
Documentation
//! Number expression parsing for Nash.

use nash_region::{Located, Position};
use nash_source::Expr;

use crate::Parser;
use crate::error;

impl<'a> Parser<'a> {
    /// Parse a number expression.
    ///
    /// Parses Nash integer literals and adds the source region.
    pub(crate) fn number(
        &mut self,
        start: Position,
    ) -> Result<&'a Located<Expr<'a>>, error::Expr<'a>> {
        let n = self.number_literal(error::Expr::Start, error::Expr::Number)?;
        Ok(self.add_end(start, Expr::Int(n)))
    }
}

#[cfg(test)]
mod tests {
    use crate::expression::assert_expr_snapshot;

    #[test]
    fn int_simple() {
        assert_expr_snapshot!("42");
    }

    #[test]
    fn int_zero() {
        assert_expr_snapshot!("0");
    }

    #[test]
    fn int_hex() {
        assert_expr_snapshot!("0xFF");
    }
}