aiken_lang/parser/expr/
string.rs1use chumsky::prelude::*;
2
3use crate::{
4 expr::UntypedExpr,
5 parser::{error::ParseError, literal::string, literal::utf8_string, token::Token},
6};
7
8pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
9 string().map_with_span(|value, span| UntypedExpr::String {
10 location: span,
11 value,
12 })
13}
14
15pub fn hybrid() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
16 choice((
17 string(),
18 utf8_string().map(|(_, bytes)| String::from_utf8(bytes).unwrap()),
19 ))
20 .map_with_span(|value, span| UntypedExpr::String {
21 location: span,
22 value,
23 })
24}
25
26#[cfg(test)]
27mod tests {
28 use crate::assert_expr;
29
30 #[test]
31 fn string_basic() {
32 assert_expr!("@\"aiken\"");
33 }
34}