1use crate::AstToken;
4use crate::SyntaxKind;
5use crate::SyntaxToken;
6use crate::TreeToken;
7
8macro_rules! define_token_struct {
10 ($name:ident, $doc:literal) => {
11 #[derive(Clone, Debug)]
12 #[doc = concat!("A token representing ", $doc, ".")]
13 pub struct $name<T: TreeToken = SyntaxToken>(T);
14
15 impl<T: TreeToken> AstToken<T> for $name<T> {
16 fn can_cast(kind: SyntaxKind) -> bool {
17 matches!(kind, SyntaxKind::$name)
18 }
19
20 fn cast(inner: T) -> Option<Self> {
21 if Self::can_cast(inner.kind()) {
22 return Some(Self(inner));
23 }
24
25 None
26 }
27
28 fn inner(&self) -> &T {
29 &self.0
30 }
31 }
32 };
33}
34
35macro_rules! define_token {
37 ($name:ident, $doc:literal, $display:literal) => {
38 define_token_struct!($name, $doc);
39
40 impl std::fmt::Display for $name {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(f, $display)
43 }
44 }
45 };
46 ($name:ident, $doc:literal) => {
47 define_token_struct!($name, $doc);
48
49 impl std::fmt::Display for $name {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 write!(f, "{}", self.0)
52 }
53 }
54 };
55}
56
57define_token!(AfterKeyword, "the `after` keyword", "after");
58define_token!(AliasKeyword, "the `alias` keyword", "alias");
59define_token!(ArrayTypeKeyword, "the `Array` type keyword", "Array");
60define_token!(AsKeyword, "the `as` keyword", "as");
61define_token!(Assignment, "the `=` symbol", "=");
62define_token!(Asterisk, "the `*` symbol", "*");
63define_token!(BooleanTypeKeyword, "the `Boolean` type keyword", "Boolean");
64define_token!(CallKeyword, "the `call` keyword", "call");
65define_token!(CloseBrace, "the `}` symbol", "}}");
66define_token!(CloseBracket, "the `]` symbol", "]");
67define_token!(CloseHeredoc, "the `>>>` symbol", ">>>");
68define_token!(CloseParen, "the `)` symbol", ")");
69define_token!(Colon, "the `:` symbol", ":");
70define_token!(Comma, "the `,` symbol", ",");
71define_token!(CommandKeyword, "the `command` keyword", "command");
72define_token!(
73 DirectoryTypeKeyword,
74 "the `Directory` type keyword",
75 "Directory"
76);
77define_token!(Dot, "the `.` symbol", ".");
78define_token!(DoubleQuote, "the `\"` symbol", "\"");
79define_token!(ElseKeyword, "the `else` keyword", "else");
80define_token!(EnvKeyword, "the `env` keyword", "env");
81define_token!(Equal, "the `=` symbol", "=");
82define_token!(Exclamation, "the `!` symbol", "!");
83define_token!(Exponentiation, "the `**` symbol", "**");
84define_token!(FalseKeyword, "the `false` keyword", "false");
85define_token!(FileTypeKeyword, "the `File` type keyword", "File");
86define_token!(FloatTypeKeyword, "the `Float` type keyword", "Float");
87define_token!(Greater, "the `>` symbol", ">");
88define_token!(GreaterEqual, "the `>=` symbol", ">=");
89define_token!(HintsKeyword, "the `hints` keyword", "hints");
90define_token!(IfKeyword, "the `if` keyword", "if");
91define_token!(ImportKeyword, "the `import` keyword", "import");
92define_token!(InKeyword, "the `in` keyword", "in");
93define_token!(InputKeyword, "the `input` keyword", "input");
94define_token!(IntTypeKeyword, "the `Int` type keyword", "Int");
95define_token!(Less, "the `<` symbol", "<");
96define_token!(LessEqual, "the `<=` symbol", "<=");
97define_token!(LogicalAnd, "the `&&` symbol", "&&");
98define_token!(LogicalOr, "the `||` symbol", "||");
99define_token!(MapTypeKeyword, "the `Map` type keyword", "Map");
100define_token!(MetaKeyword, "the `meta` keyword", "meta");
101define_token!(Minus, "the `-` symbol", "-");
102define_token!(NoneKeyword, "the `None` keyword", "None");
103define_token!(NotEqual, "the `!=` symbol", "!=");
104define_token!(NullKeyword, "the `null` keyword", "null");
105define_token!(ObjectKeyword, "the `object` keyword", "object");
106define_token!(ObjectTypeKeyword, "the `Object` type keyword", "Object");
107define_token!(OpenBrace, "the `{` symbol", "{{");
108define_token!(OpenBracket, "the `[` symbol", "[");
109define_token!(OpenHeredoc, "the `<<<` symbol", "<<<");
110define_token!(OpenParen, "the `(` symbol", "(");
111define_token!(OutputKeyword, "the `output` keyword", "output");
112define_token!(PairTypeKeyword, "the `Pair` type keyword", "Pair");
113define_token!(
114 ParameterMetaKeyword,
115 "the `parameter_meta` keyword",
116 "parameter_meta"
117);
118define_token!(Percent, "the `%` symbol", "%");
119define_token!(PlaceholderOpen, "a `${` or `~{` symbol");
120define_token!(Plus, "the `+` symbol", "+");
121define_token!(QuestionMark, "the `?` symbol", "?");
122define_token!(
123 RequirementsKeyword,
124 "the `requirements` keyword",
125 "requirements"
126);
127define_token!(RuntimeKeyword, "the `runtime` keyword", "runtime");
128define_token!(ScatterKeyword, "the `scatter` keyword", "scatter");
129define_token!(SingleQuote, "the `'` symbol", "'");
130define_token!(Slash, "the `/` symbol", "/");
131define_token!(StringTypeKeyword, "the `String` type keyword", "String");
132define_token!(StructKeyword, "the `struct` keyword", "struct");
133define_token!(TaskKeyword, "the `task` keyword", "task");
134define_token!(ThenKeyword, "the `then` keyword", "then");
135define_token!(TrueKeyword, "the `true` keyword", "true");
136define_token!(Unknown, "unknown contents within a WDL document");
137define_token!(VersionKeyword, "the `version` keyword", "version");
138define_token!(WorkflowKeyword, "the `workflow` keyword", "workflow");