57 std::vector<shell_token> vTokens
58 ) : m_oIstream(oIstream),
59 m_vTokens(std::move(vTokens)) {
68 if (m_nPos >= m_vTokens.size() || m_nPos < 0)
return nullptr;
69 return &m_vTokens[m_nPos];
78 if (m_nPos + 1 >= m_vTokens.size() || m_nPos + 1 < 0)
return nullptr;
79 return &m_vTokens[m_nPos + 1];
88 if (m_nPos >= m_vTokens.size() + 1 || m_nPos <= 0)
return nullptr;
89 return &m_vTokens[m_nPos - 1];
99 if (m_nPos >= m_vTokens.size())
return nullptr;
100 return &m_vTokens[m_nPos];
117 [[nodiscard]] std::size_t
pos() const noexcept {
118 if (m_nPos >= m_vTokens.size() || m_nPos < 0)
return m_oIstream.
size();
129 if (m_nPos >= m_vTokens.size() || m_nPos < 0)
return false;
130 return m_vTokens[m_nPos].m_nType == nType;
140 if (m_nPos + 1 >= m_vTokens.size())
return false;
141 return m_vTokens[m_nPos + 1].m_nType == nType;
158 return this->
keyword() == nKeyword;
165 std::vector<shell_token> m_vTokens;
167 std::intptr_t m_nPos = -1;
172 const auto pCurrent = this->
current();
174 const auto pNext = this->
next();
177 if (pNext ==
nullptr) {
185 const auto nTypeNext = pNext->m_nType;
A class for input stream behavior with a character type.
Definition fakestream.h:70
ALWAYS_INLINE std::size_t size() const noexcept
Gets the stream data size.
Definition fakestream.h:191
A class that manages a collection of shell tokens for processing.
Definition token_holder.h:47
shell_keyword keyword() const noexcept
Retrieves the current shell keyword.
Definition token_holder.h:170
const shell_token * next() const noexcept
Retrieves the next token.
Definition token_holder.h:77
std::size_t pos() const noexcept
Retrieves the current position of the token holder.
Definition token_holder.h:117
bool is_next(const shell_token_type nType) const noexcept
Checks if the next token is of a specified type.
Definition token_holder.h:139
void put_back() noexcept
Moves the position back by one token.
Definition token_holder.h:108
const shell_token * previous() const noexcept
Retrieves the previous token.
Definition token_holder.h:87
const shell_token * current() const noexcept
Retrieves the current token.
Definition token_holder.h:67
token_holder(ifakestream &oIstream, std::vector< shell_token > vTokens)
Constructs a token_holder instance.
Definition token_holder.h:55
bool is(const shell_token_type nType) const noexcept
Checks if the current token is of a specified type.
Definition token_holder.h:128
const shell_token * get() noexcept
Retrieves and advances to the next token.
Definition token_holder.h:97
BashSpark main namespace.
Definition command.h:39
shell_token_type
Enumeration of types of tokens that can be parsed from shell commands.
Definition shell_tokenizer.h:44
@ TK_CMD_SEPARATOR
Represents command separators (e.g., ;).
@ TK_OPEN_PARENTHESIS
Represents an open parenthesis ('(').
@ TK_CLOSE_SQR_BRACKETS
Represents a close square bracket (']').
@ TK_OPEN_BRACKETS
Represents an open bracket ('{').
@ TK_CLOSE_PARENTHESIS
Represents a close parenthesis (')').
@ TK_WORD
Represents a word in the command.
@ TK_SPACE
Represents whitespace in the command.
@ TK_CLOSE_BRACKETS
Represents a close bracket ('}').
@ TK_OPEN_SQR_BRACKETS
Represents an open square bracket ('[').
shell_keyword get_keyword_id(const std::string_view &oString)
Identifies shell special keywords.
Definition shell_tools.h:152
shell_keyword
Enumeration of shell keywords for scripting.
Definition shell_keyword.h:39
@ SK_NONE
No keyword (default value).
Defines enum bs::shell_keyword.
Defines class bs::shell_tokenizer.
Represents a token generated during command parsing.
Definition shell_tokenizer.h:82