rnix/
kinds.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2#[repr(u16)]
3#[allow(non_camel_case_types)]
4pub enum SyntaxKind {
5    // Internals
6    TOKEN_COMMENT,
7    TOKEN_ERROR,
8    TOKEN_WHITESPACE,
9
10    // Keywords
11    TOKEN_ASSERT,
12    TOKEN_ELSE,
13    TOKEN_IF,
14    TOKEN_IN,
15    TOKEN_INHERIT,
16    TOKEN_LET,
17    TOKEN_OR,
18    TOKEN_REC,
19    TOKEN_THEN,
20    TOKEN_WITH,
21
22    // Symbols
23    TOKEN_L_BRACE,
24    TOKEN_R_BRACE,
25    TOKEN_L_BRACK,
26    TOKEN_R_BRACK,
27    TOKEN_ASSIGN,
28    TOKEN_AT,
29    TOKEN_COLON,
30    TOKEN_COMMA,
31    TOKEN_DOT,
32    TOKEN_ELLIPSIS,
33    TOKEN_QUESTION,
34    TOKEN_SEMICOLON,
35
36    // Operators
37    TOKEN_L_PAREN,
38    TOKEN_R_PAREN,
39    TOKEN_CONCAT,
40    TOKEN_INVERT,
41    TOKEN_UPDATE,
42
43    TOKEN_ADD,
44    TOKEN_SUB,
45    TOKEN_MUL,
46    TOKEN_DIV,
47
48    TOKEN_AND_AND,
49    TOKEN_EQUAL,
50    TOKEN_IMPLICATION,
51    TOKEN_LESS,
52    TOKEN_LESS_OR_EQ,
53    TOKEN_MORE,
54    TOKEN_MORE_OR_EQ,
55    TOKEN_NOT_EQUAL,
56    TOKEN_OR_OR,
57
58    // Identifiers and values
59    TOKEN_FLOAT,
60    TOKEN_IDENT,
61    TOKEN_INTEGER,
62    TOKEN_INTERPOL_END,
63    TOKEN_INTERPOL_START,
64    TOKEN_PATH,
65    TOKEN_URI,
66    TOKEN_STRING_CONTENT,
67    TOKEN_STRING_END,
68    TOKEN_STRING_START,
69
70    NODE_APPLY,
71    NODE_ASSERT,
72    NODE_ATTRPATH,
73    NODE_DYNAMIC,
74    NODE_ERROR,
75    NODE_IDENT,
76    NODE_IF_ELSE,
77    NODE_SELECT,
78    NODE_INHERIT,
79    NODE_INHERIT_FROM,
80    NODE_STRING,
81    NODE_INTERPOL,
82    NODE_LAMBDA,
83    NODE_IDENT_PARAM,
84    // An old let { x = 92; body = x; } syntax
85    NODE_LEGACY_LET,
86    NODE_LET_IN,
87    NODE_LIST,
88    NODE_BIN_OP,
89    NODE_PAREN,
90    NODE_PATTERN,
91    NODE_PAT_BIND,
92    NODE_PAT_ENTRY,
93    NODE_ROOT,
94    NODE_ATTR_SET,
95    NODE_ATTRPATH_VALUE,
96    NODE_UNARY_OP,
97    NODE_LITERAL,
98    NODE_WITH,
99    NODE_PATH,
100    // Attrpath existence check: foo ? bar.${baz}."bux"
101    NODE_HAS_ATTR,
102
103    #[doc(hidden)]
104    __LAST,
105}
106use SyntaxKind::*;
107
108impl SyntaxKind {
109    /// Returns true if this token is a literal, such as an integer or a string
110    pub fn is_literal(self) -> bool {
111        matches!(self, TOKEN_FLOAT | TOKEN_INTEGER | TOKEN_PATH | TOKEN_URI)
112    }
113
114    /// Returns true if this token should be used as a function argument.
115    /// ```ignore
116    /// Example:
117    /// add 1 2 + 3
118    /// ^   ^ ^ ^
119    /// |   | | +- false
120    /// |   | +- true
121    /// |   +- true
122    /// +- true
123    /// ```
124    pub fn is_fn_arg(self) -> bool {
125        match self {
126            TOKEN_REC | TOKEN_L_BRACE | TOKEN_L_BRACK | TOKEN_L_PAREN | TOKEN_STRING_START
127            | TOKEN_IDENT => true,
128            _ => self.is_literal(),
129        }
130    }
131    /// Returns true if this token is a comment, whitespace, or similar, and
132    /// should be skipped over by the parser.
133    pub fn is_trivia(self) -> bool {
134        matches!(self, TOKEN_COMMENT | TOKEN_ERROR | TOKEN_WHITESPACE)
135    }
136}