use enumset::enum_set;
use indoc::indoc;

use crate::lst_parser::{
    grammar::check_parser,
    syntax_kind::{SyntaxKind::*, TokenSet},
    CompletedMarker, Parser,
};

const LIT_TOKENS: TokenSet = enum_set!(INT_NUM | FLOAT_NUM | STRING);

pub fn literal(p: &mut Parser) -> Option<CompletedMarker> {
    if !LIT_TOKENS.contains(p.current()) {
        return None;
    }

    let lit = p.start("lit");

    p.do_bump();

    Some(lit.complete(p, LITERAL))
}

#[test]
fn test_parse_lst_lit() {
    check_parser(
        "42",
        |p| {
            literal(p);
        },
        indoc! {r#"
            LITERAL {
                INT_NUM "42";
            }
        "#},
    );
    check_parser(
        "3.14",
        |p| {
            literal(p);
        },
        indoc! {r#"
            LITERAL {
                FLOAT_NUM "3.14";
            }
        "#},
    );
    check_parser(
        r#""Meow""#,
        |p| {
            literal(p);
        },
        indoc! {r#"
            LITERAL {
                STRING "\"Meow\"";
            }
        "#},
    );
}
