BashSpark
Loading...
Searching...
No Matches
shell_parser.h
Go to the documentation of this file.
1
30#pragma once
31
33#include "BashSpark/shell.h"
37
38namespace bs {
39 class token_holder;
40
54 public:
56 using expandable_ptr = std::unique_ptr<shell_node_expandable>;
58 using evaluable_ptr = std::unique_ptr<shell_node_evaluable>;
59
60 public:
62 constexpr static std::size_t MAX_DEPTH = shell::MAX_DEPTH;
63
73 static evaluable_ptr parse(
74 ifakestream &oIstream
75 );
76
77 private:
79 ifakestream &oIstream,
80 token_holder &oTokens
81 );
82
83 private:
90 [[nodiscard]] static expandable_ptr parse_word(const token_holder &oTokens);
91
97 [[nodiscard]] expandable_ptr parse_unicode() const;
98
104 [[nodiscard]] expandable_ptr parse_quote_simple() const;
105
111 [[nodiscard]] expandable_ptr parse_quote_double();
112
118 [[nodiscard]] expandable_ptr parse_quote_back();
119
125 [[nodiscard]] expandable_ptr parse_dollar();
126
132 [[nodiscard]] expandable_ptr parse_dollar_variable() const;
133
139 [[nodiscard]] expandable_ptr parse_dollar_command();
140
147 [[nodiscard]] evaluable_ptr parse_command(parse_mode nMode);
148
155 [[nodiscard]] std::unique_ptr<shell_node_command_expression>
156 parse_command_expression(parse_mode nMode);
157
164 [[nodiscard]] evaluable_ptr parse_command_group(
165 parse_mode nMode
166 );
167
176 void parse_command_group_oper(
177 std::vector<evaluable_ptr> &vExpressions,
178 shell_node_type nNodeType,
179 std::size_t nPos,
180 parse_mode nMode
181 );
182
188 [[nodiscard]] evaluable_ptr parse_parentheses();
189
195 [[nodiscard]] evaluable_ptr parse_brackets();
196
202 [[nodiscard]] evaluable_ptr parse_sqr_brackets();
203
210 [[nodiscard]] evaluable_ptr parse_block(shell_token_type nEnd);
211
219 [[nodiscard]] evaluable_ptr parse_block(shell_keyword nEnd, parse_mode nMode);
220
227 [[nodiscard]] evaluable_ptr parse_keyword(shell_keyword nKeyword, parse_mode nMode);
228
234 [[nodiscard]] expandable_ptr parse_test_expression();
235
241 [[nodiscard]] evaluable_ptr parse_if();
242
248 [[nodiscard]] evaluable_ptr parse_for();
249
255 [[nodiscard]] evaluable_ptr parse_while();
256
262 [[nodiscard]] evaluable_ptr parse_until();
263
269 shell_parser::evaluable_ptr parse_function();
270
271 public:
277 void increase_depth(std::size_t nPos);
278
282 void decrease_depth();
283
284 private:
286 std::size_t m_nDepth = 0;
288 ifakestream &m_oIstream;
289 // Token holder
290 token_holder &m_oTokens;
291 };
292}
A class for input stream behavior with a character type.
Definition fakestream.h:70
Parses tokens into an evaluable shell AST.
Definition shell_parser.h:53
std::unique_ptr< shell_node_evaluable > evaluable_ptr
Unique pointer to an evaluable shell node (sugar syntax).
Definition shell_parser.h:58
void increase_depth(std::size_t nPos)
Increase the nesting depth and check limits.
Definition shell_parser.cpp:104
static evaluable_ptr parse(ifakestream &oIstream)
Parse input into an evaluable AST.
Definition shell_parser.cpp:80
static constexpr std::size_t MAX_DEPTH
Maximum recursion depth allowed for nested constructs.
Definition shell_parser.h:62
void decrease_depth()
Decrease the current nesting depth.
Definition shell_parser.cpp:114
std::unique_ptr< shell_node_expandable > expandable_ptr
Unique pointer to an expandable shell node (sugar syntax).
Definition shell_parser.h:56
static constexpr std::size_t MAX_DEPTH
Maximum depth the command interpreter can reach.
Definition shell.h:66
A class that manages a collection of shell tokens for processing.
Definition token_holder.h:47
Generic input and output stream classes with character types.
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
shell_node_type
Types of nodes recognized by the shell parser.
Definition shell_node.h:56
parse_mode
Enumeration for different parsing modes.
Definition shell_keyword.h:65
shell_keyword
Enumeration of shell keywords for scripting.
Definition shell_keyword.h:39
Defines the bs::shell interface and built-in shell functionality.
Defines enum bs::shell_keyword.
Defines the shell node hierarchy used by the parser.
Defines class bs::shell_tokenizer.