yog_script_analyze/source/
token.rs1use crate::words::Word;
4
5pub use yog_data::Span;
7
8pub const QUOTE: char = '\'';
11
12#[derive(Debug, Clone, PartialEq)]
14pub enum StrPart {
15 Text(String),
16 Expr(Vec<Token>),
17}
18
19#[derive(Debug, Clone, PartialEq)]
21pub enum Tok {
22 Ident(String),
23 Keyword(&'static Word),
25 Int(i64),
26 Float(f64),
27 Unit(String, String),
30 Version(String),
32 Str(Vec<StrPart>),
33 RawStr(String),
34 Char(char),
35 Lifetime(String),
37 Text(String),
39 Content(String, String),
41 Tag(String),
43 Doc(String),
45 Punct(Punct),
46 Eof,
47}
48
49#[derive(Debug, Clone, PartialEq)]
51pub struct Token {
52 pub tok: Tok,
53 pub span: Span,
54}
55
56macro_rules! puncts {
57 ($(#[$doc:meta])* $name:ident { $($variant:ident = $text:literal,)* }) => {
58 $(#[$doc])*
59 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
60 pub enum $name { $($variant),* }
61
62 impl $name {
63 pub const ALL: &'static [$name] = &[$($name::$variant),*];
64
65 #[must_use]
67 pub const fn text(self) -> &'static str {
68 match self { $($name::$variant => $text),* }
69 }
70 }
71 };
72}
73
74puncts! {
75 Punct {
77 RangeExcl = "..<", NullAssign = "??=",
78 FatArrow = "=>", SafeDot = "?.", Coalesce = "??",
79 EqEq = "==", NotEq = "!=", LtEq = "<=", GtEq = ">=", AndAnd = "&&", OrOr = "||",
80 PlusEq = "+=", MinusEq = "-=", StarEq = "*=", SlashEq = "/=", PercentEq = "%=",
81 Range = "..",
82 LBrace = "{", RBrace = "}", LParen = "(", RParen = ")", LBracket = "[", RBracket = "]",
83 Comma = ",", Dot = ".", Colon = ":", Semi = ";", Question = "?",
84 Eq = "=", Lt = "<", Gt = ">", Plus = "+", Minus = "-", Star = "*", Slash = "/",
85 Percent = "%", Bang = "!", Amp = "&", Hash = "#", Dollar = "$",
86 }
87}