rnix/ast/
expr_ext.rs

1use crate::ast::{self, support::*};
2
3// this is a separate type because it mixes tokens and nodes
4// for example, a Str is a node because it can contain nested subexpressions but an Integer is a token.
5// This means that we have to write it out manually instead of using the macro to create the type for us.
6#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7pub enum LiteralKind {
8    Float(ast::Float),
9    Integer(ast::Integer),
10    Uri(ast::Uri),
11}
12
13impl ast::Literal {
14    pub fn kind(&self) -> LiteralKind {
15        if let Some(it) = token(self) {
16            return LiteralKind::Float(it);
17        }
18
19        if let Some(it) = token(self) {
20            return LiteralKind::Integer(it);
21        }
22
23        if let Some(it) = token(self) {
24            return LiteralKind::Uri(it);
25        }
26
27        unreachable!()
28    }
29}