sway_parse/
literal.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::{Parse, ParseResult, Parser, Peek, Peeker};

use sway_ast::Literal;
use sway_error::parser_error::ParseErrorKind;

impl Peek for Literal {
    fn peek(peeker: Peeker<'_>) -> Option<Literal> {
        peeker.peek_literal().ok().cloned()
    }
}

impl Parse for Literal {
    fn parse(parser: &mut Parser) -> ParseResult<Literal> {
        parser
            .take()
            .ok_or_else(|| parser.emit_error(ParseErrorKind::ExpectedLiteral))
    }
}