y_lang/ast/
str.rs

1use super::{Position, Rule};
2use pest::iterators::Pair;
3use unescape::unescape;
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Str<T> {
7    pub value: String,
8    pub position: Position,
9    pub info: T,
10}
11
12impl Str<()> {
13    pub fn from_pair(pair: Pair<Rule>, file: &str) -> Str<()> {
14        assert_eq!(pair.as_rule(), Rule::string);
15        let (line, col) = pair.line_col();
16
17        Str {
18            value: unescape(pair.clone().into_inner().next().unwrap().as_str())
19                .expect("Invalid character escaped"),
20            position: (file.to_string(), line, col),
21            info: (),
22        }
23    }
24}