sysml_parser/
keyword.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::Span;
4
5#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd)]
6pub enum Keyword {
7    About,
8    Abstract,
9    Accept,
10    Action,
11    Actor,
12    After,
13    Alias,
14    All,
15    Allocate,
16    Allocation,
17    Analysis,
18    And,
19    As,
20    Assert,
21    Assign,
22    Assoc,
23    Assume,
24    At,
25    Attribute,
26    Bind,
27    Binding,
28    Block,
29    By,
30    Calc,
31    Case,
32    Comment,
33    Concern,
34    Connect,
35    Connection,
36    Constraint,
37    Decide,
38    Def,
39    Default,
40    Defined,
41    Dependency,
42    Derived,
43    Do,
44    Doc,
45    Else,
46    End,
47    Entry,
48    Enum,
49    Event,
50    Exhibit,
51    Exit,
52    Expose,
53    Filter,
54    First,
55    Flow,
56    For,
57    Fork,
58    Frame,
59    From,
60    HasType,
61    If,
62    Implies,
63    Import,
64    In,
65    Include,
66    Individual,
67    InOut,
68    Interface,
69    IsType,
70    Item,
71    Join,
72    Language,
73    Loop,
74    Merge,
75    Message,
76    Metadata,
77    NonUnique,
78    Not,
79    Objective,
80    Occurrence,
81    Of,
82    Or,
83    Ordered,
84    Out,
85    Package,
86    Parallel,
87    Part,
88    Perform,
89    Port,
90    Private,
91    Protected,
92    Public,
93    ReadOnly,
94    Redefines,
95    Ref,
96    References,
97    Render,
98    Rendering,
99    Rep,
100    Require,
101    Requirement,
102    Return,
103    Satisfy,
104    Send,
105    Snapshot,
106    Specializes,
107    Stakeholder,
108    State,
109    Subject,
110    Subsets,
111    Succession,
112    Then,
113    TimeSlice,
114    To,
115    Transition,
116    Until,
117    Use,
118    Variant,
119    Variation,
120    Verification,
121    Verify,
122    Via,
123    View,
124    Viewpoint,
125    When,
126    While,
127    Xor,
128}
129
130impl<'a> TryFrom<Span<'a>> for Keyword {
131    type Error = Span<'a>;
132
133    fn try_from(input: Span<'a>) -> Result<Self, Self::Error> {
134        Self::try_from(*input.fragment()).map_err(|_| input)
135    }
136}
137
138impl<'a> TryFrom<&'a str> for Keyword {
139    type Error = &'a str;
140
141    fn try_from(input: &'a str) -> Result<Self, Self::Error> {
142        use Keyword::*;
143        Ok(match input {
144            "about" => About,
145            "abstract" => Abstract,
146            "accept" => Accept,
147            "action" => Action,
148            "actor" => Actor,
149            "after" => After,
150            "alias" => Alias,
151            "all" => All,
152            "allocate" => Allocate,
153            "allocation" => Allocation,
154            "analysis" => Analysis,
155            "and" => And,
156            "as" => As,
157            "assert" => Assert,
158            "assign" => Assign,
159            "assoc" => Assoc,
160            "assume" => Assume,
161            "at" => At,
162            "attribute" => Attribute,
163            "bind" => Bind,
164            "binding" => Binding,
165            "block" => Block,
166            "by" => By,
167            "calc" => Calc,
168            "case" => Case,
169            "comment" => Comment,
170            "concern" => Concern,
171            "connect" => Connect,
172            "connection" => Connection,
173            "constraint" => Constraint,
174            "decide" => Decide,
175            "def" => Def,
176            "default" => Default,
177            "defined" => Defined,
178            "dependency" => Dependency,
179            "derived" => Derived,
180            "do" => Do,
181            "doc" => Doc,
182            "else" => Else,
183            "end" => End,
184            "entry" => Entry,
185            "enum" => Enum,
186            "event" => Event,
187            "exhibit" => Exhibit,
188            "exit" => Exit,
189            "expose" => Expose,
190            "filter" => Filter,
191            "first" => First,
192            "flow" => Flow,
193            "for" => For,
194            "fork" => Fork,
195            "frame" => Frame,
196            "from" => From,
197            "hastype" => HasType,
198            "if" => If,
199            "implies" => Implies,
200            "import" => Import,
201            "in" => In,
202            "include" => Include,
203            "individual" => Individual,
204            "inout" => InOut,
205            "interface" => Interface,
206            "istype" => IsType,
207            "item" => Item,
208            "join" => Join,
209            "language" => Language,
210            "loop" => Loop,
211            "merge" => Merge,
212            "message" => Message,
213            "metadata" => Metadata,
214            "nonunique" => NonUnique,
215            "not" => Not,
216            "objective" => Objective,
217            "occurrence" => Occurrence,
218            "of" => Of,
219            "or" => Or,
220            "ordered" => Ordered,
221            "out" => Out,
222            "package" => Package,
223            "parallel" => Parallel,
224            "part" => Part,
225            "perform" => Perform,
226            "port" => Port,
227            "private" => Private,
228            "protected" => Protected,
229            "public" => Public,
230            "readonly" => ReadOnly,
231            "redefines" => Redefines,
232            "ref" => Ref,
233            "references" => References,
234            "render" => Render,
235            "rendering" => Rendering,
236            "rep" => Rep,
237            "require" => Require,
238            "requirement" => Requirement,
239            "return" => Return,
240            "satisfy" => Satisfy,
241            "send" => Send,
242            "snapshot" => Snapshot,
243            "specializes" => Specializes,
244            "stakeholder" => Stakeholder,
245            "state" => State,
246            "subject" => Subject,
247            "subsets" => Subsets,
248            "succession" => Succession,
249            "then" => Then,
250            "timeslice" => TimeSlice,
251            "to" => To,
252            "transition" => Transition,
253            "until" => Until,
254            "use" => Use,
255            "variant" => Variant,
256            "variation" => Variation,
257            "verification" => Verification,
258            "verify" => Verify,
259            "via" => Via,
260            "view" => View,
261            "viewpoint" => Viewpoint,
262            "when" => When,
263            "while" => While,
264            "xor" => Xor,
265            _ => return Err(input),
266        })
267    }
268}