BashSpark
Loading...
Searching...
No Matches
shell_keyword.h
Go to the documentation of this file.
1
30#pragma once
31
32#include <type_traits>
33
34namespace bs {
39 enum class shell_keyword {
40 SK_NONE = 0x0,
41 SK_FUNCTION = 1 << 0,
42 SK_IF = 1 << 1,
43 SK_THEN = 1 << 2,
44 SK_ELSE = 1 << 3,
45 SK_ELIF = 1 << 4,
46 SK_FI = 1 << 5,
47 SK_FOR = 1 << 6,
48 SK_IN = 1 << 7,
49 SK_WHILE = 1 << 8,
50 SK_UNTIL = 1 << 9,
51 SK_DO = 1 << 10,
52 SK_DONE = 1 << 11,
53 SK_CONTINUE = 1 << 12,
54 SK_BREAK = 1 << 13,
56 };
57
65 enum class parse_mode {
66 PM_NORMAL = 0x0,
67 PM_BACKQUOTE = 1 << 0,
68 PM_LOOP = 1 << 1,
69 PM_FUNCTION_NAME = 1 << 2, // Function name parsing mode
71 };
72
79 constexpr bool has(const parse_mode nItem, const parse_mode nSet) {
80 return (
81 static_cast<std::underlying_type_t<parse_mode>>(nItem) &
82 static_cast<std::underlying_type_t<parse_mode>>(nSet)
83 ) != 0;
84 }
85
92 constexpr bool has(const shell_keyword nItem, const shell_keyword nSet) {
93 return (
94 static_cast<std::underlying_type_t<shell_keyword>>(nItem) &
95 static_cast<std::underlying_type_t<shell_keyword>>(nSet)
96 ) != 0;
97 }
98}
99
107 return static_cast<bs::shell_keyword>(
108 static_cast<std::underlying_type_t<bs::shell_keyword>>(nLeft) |
109 static_cast<std::underlying_type_t<bs::shell_keyword>>(nRight));
110}
111
119 return static_cast<bs::shell_keyword>(
120 static_cast<std::underlying_type_t<bs::shell_keyword>>(nLeft) &
121 static_cast<std::underlying_type_t<bs::shell_keyword>>(nRight));
122}
123
124
132 return static_cast<bs::shell_keyword>(
133 static_cast<std::underlying_type_t<bs::shell_keyword>>(nLeft) ^
134 static_cast<std::underlying_type_t<bs::shell_keyword>>(nRight));
135}
136
144 return nLeft = nLeft | nRight;
145}
146
154 return nLeft = nLeft & nRight;
155}
156
164 return nLeft = nLeft ^ nRight;
165}
166
173constexpr bs::parse_mode operator|(const bs::parse_mode nLeft, const bs::parse_mode nRight) {
174 return static_cast<bs::parse_mode>(
175 static_cast<std::underlying_type_t<bs::parse_mode>>(nLeft) |
176 static_cast<std::underlying_type_t<bs::parse_mode>>(nRight));
177}
178
185constexpr bs::parse_mode operator&(const bs::parse_mode nLeft, const bs::parse_mode nRight) {
186 return static_cast<bs::parse_mode>(
187 static_cast<std::underlying_type_t<bs::parse_mode>>(nLeft) &
188 static_cast<std::underlying_type_t<bs::parse_mode>>(nRight));
189}
190
191
198constexpr bs::parse_mode operator^(const bs::parse_mode nLeft, const bs::parse_mode nRight) {
199 return static_cast<bs::parse_mode>(
200 static_cast<std::underlying_type_t<bs::parse_mode>>(nLeft) ^
201 static_cast<std::underlying_type_t<bs::parse_mode>>(nRight));
202}
203
211 return nLeft = nLeft | nRight;
212}
213
221 return nLeft = nLeft & nRight;
222}
223
231 return nLeft = nLeft ^ nRight;
232}
BashSpark main namespace.
Definition command.h:39
parse_mode
Enumeration for different parsing modes.
Definition shell_keyword.h:65
@ PM_BACKQUOTE
Backquote parsing mode.
@ PM_NORMAL
Normal parsing mode.
@ PM_LOOP
Loop parsing mode.
@ PM_BACKQUOTE_LOOP
Combined mode for handling both backquote and looping.
shell_keyword
Enumeration of shell keywords for scripting.
Definition shell_keyword.h:39
@ SK_FUNCTION
Start of a function definition.
@ SK_DO
Beginning of a block for loops and conditionals.
@ SK_NONE
No keyword (default value).
@ SK_WHILE
Start of a while loop.
@ SK_DONE
End of a do block or loop.
@ SK_FOR
Start of a for loop.
@ SK_CONTINUE
Continue statement.
@ SK_ELSE
Alternative block for when the 'if' condition is false.
@ SK_IN
Collection specified in a for loop.
@ SK_IF_DELIMITER
End of a if block.
@ SK_IF
Beginning of an if conditional statement.
@ SK_BREAK
Break staement.
@ SK_ELIF
Additional condition in an if-else chain.
@ SK_FI
End of an if-else construct.
@ SK_UNTIL
Loop continues until a condition is met.
@ SK_THEN
Block that executes if the 'if' condition is true.
constexpr bool has(const parse_mode nItem, const parse_mode nSet)
Checks if the bitwise and of two parse_mode is 0.
Definition shell_keyword.h:79
bs::shell_keyword & operator|=(bs::shell_keyword &nLeft, const bs::shell_keyword nRight)
Bitwise OR assignment operator for shell_keyword.
Definition shell_keyword.h:143
constexpr bs::shell_keyword operator|(const bs::shell_keyword nLeft, const bs::shell_keyword nRight)
Bitwise OR operator for shell_keyword.
Definition shell_keyword.h:106
constexpr bs::shell_keyword operator&(const bs::shell_keyword nLeft, const bs::shell_keyword nRight)
Bitwise AND operator for shell_keyword.
Definition shell_keyword.h:118
bs::shell_keyword & operator^=(bs::shell_keyword &nLeft, const bs::shell_keyword nRight)
Bitwise XOR assignment operator for shell_keyword.
Definition shell_keyword.h:163
bs::shell_keyword & operator&=(bs::shell_keyword &nLeft, const bs::shell_keyword nRight)
Bitwise AND assignment operator for shell_keyword.
Definition shell_keyword.h:153
constexpr bs::shell_keyword operator^(const bs::shell_keyword nLeft, const bs::shell_keyword nRight)
Bitwise XOR operator for shell_keyword.
Definition shell_keyword.h:131