wdl_ast/v1/
tokens.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! V1 AST tokens.

use crate::AstToken;
use crate::SyntaxKind;
use crate::SyntaxToken;

/// Defines an AST token struct.
macro_rules! define_token_struct {
    ($name:ident, $doc:literal) => {
        #[derive(Clone, Debug)]
        #[doc = concat!("A token representing ", $doc, ".")]
        pub struct $name(SyntaxToken);

        impl AstToken for $name {
            fn can_cast(kind: SyntaxKind) -> bool
            where
                Self: Sized,
            {
                matches!(kind, SyntaxKind::$name)
            }

            fn cast(syntax: SyntaxToken) -> Option<Self>
            where
                Self: Sized,
            {
                if Self::can_cast(syntax.kind()) {
                    return Some(Self(syntax));
                }

                None
            }

            fn syntax(&self) -> &SyntaxToken {
                &self.0
            }
        }
    };
}

/// Defines an AST token.
macro_rules! define_token {
    ($name:ident, $doc:literal, $display:literal) => {
        define_token_struct!($name, $doc);

        impl std::fmt::Display for $name {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                write!(f, $display)
            }
        }
    };
    ($name:ident, $doc:literal) => {
        define_token_struct!($name, $doc);

        impl std::fmt::Display for $name {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                write!(f, "{}", self.0)
            }
        }
    };
}

define_token!(AfterKeyword, "the `after` keyword", "after");
define_token!(AliasKeyword, "the `alias` keyword", "alias");
define_token!(ArrayTypeKeyword, "the `Array` type keyword", "Array");
define_token!(AsKeyword, "the `as` keyword", "as");
define_token!(Assignment, "the `=` symbol", "=");
define_token!(Asterisk, "the `*` symbol", "*");
define_token!(BooleanTypeKeyword, "the `Boolean` type keyword", "Boolean");
define_token!(CallKeyword, "the `call` keyword", "call");
define_token!(CloseBrace, "the `}` symbol", "}}");
define_token!(CloseBracket, "the `]` symbol", "]");
define_token!(CloseHeredoc, "the `>>>` symbol", ">>>");
define_token!(CloseParen, "the `)` symbol", ")");
define_token!(Colon, "the `:` symbol", ":");
define_token!(Comma, "the `,` symbol", ",");
define_token!(CommandKeyword, "the `command` keyword", "command");
define_token!(
    DirectoryTypeKeyword,
    "the `Directory` type keyword",
    "Directory"
);
define_token!(Dot, "the `.` symbol", ".");
define_token!(DoubleQuote, "the `\"` symbol", "\"");
define_token!(ElseKeyword, "the `else` keyword", "else");
define_token!(Equal, "the `=` symbol", "=");
define_token!(Exclamation, "the `!` symbol", "!");
define_token!(Exponentiation, "the `**` symbol", "**");
define_token!(FalseKeyword, "the `false` keyword", "false");
define_token!(FileTypeKeyword, "the `File` type keyword", "File");
define_token!(FloatTypeKeyword, "the `Float` type keyword", "Float");
define_token!(Greater, "the `>` symbol", ">");
define_token!(GreaterEqual, "the `>=` symbol", ">=");
define_token!(HintsKeyword, "the `hints` keyword", "hints");
define_token!(IfKeyword, "the `if` keyword", "if");
define_token!(ImportKeyword, "the `import` keyword", "import");
define_token!(InKeyword, "the `in` keyword", "in");
define_token!(InputKeyword, "the `input` keyword", "input");
define_token!(IntTypeKeyword, "the `Int` type keyword", "Int");
define_token!(Less, "the `<` symbol", "<");
define_token!(LessEqual, "the `<=` symbol", "<=");
define_token!(LogicalAnd, "the `&&` symbol", "&&");
define_token!(LogicalOr, "the `||` symbol", "||");
define_token!(MapTypeKeyword, "the `Map` type keyword", "Map");
define_token!(MetaKeyword, "the `meta` keyword", "meta");
define_token!(Minus, "the `-` symbol", "-");
define_token!(NoneKeyword, "the `None` keyword", "None");
define_token!(NotEqual, "the `!=` symbol", "!=");
define_token!(NullKeyword, "the `null` keyword", "null");
define_token!(ObjectKeyword, "the `object` keyword", "object");
define_token!(ObjectTypeKeyword, "the `Object` type keyword", "Object");
define_token!(OpenBrace, "the `{` symbol", "{{");
define_token!(OpenBracket, "the `[` symbol", "[");
define_token!(OpenHeredoc, "the `<<<` symbol", "<<<");
define_token!(OpenParen, "the `(` symbol", "(");
define_token!(OutputKeyword, "the `output` keyword", "output");
define_token!(PairTypeKeyword, "the `Pair` type keyword", "Pair");
define_token!(
    ParameterMetaKeyword,
    "the `parameter_meta` keyword",
    "parameter_meta"
);
define_token!(Percent, "the `%` symbol", "%");
define_token!(PlaceholderOpen, "a `${` or `~{` symbol");
define_token!(Plus, "the `+` symbol", "+");
define_token!(QuestionMark, "the `?` symbol", "?");
define_token!(
    RequirementsKeyword,
    "the `requirements` keyword",
    "requirements"
);
define_token!(RuntimeKeyword, "the `runtime` keyword", "runtime");
define_token!(ScatterKeyword, "the `scatter` keyword", "scatter");
define_token!(SingleQuote, "the `'` symbol", "'");
define_token!(Slash, "the `/` symbol", "/");
define_token!(StringTypeKeyword, "the `String` type keyword", "String");
define_token!(StructKeyword, "the `struct` keyword", "struct");
define_token!(TaskKeyword, "the `task` keyword", "task");
define_token!(ThenKeyword, "the `then` keyword", "then");
define_token!(TrueKeyword, "the `true` keyword", "true");
define_token!(Unknown, "unknown contents within a WDL document");
define_token!(VersionKeyword, "the `version` keyword", "version");
define_token!(WorkflowKeyword, "the `workflow` keyword", "workflow");