57 SNT_COMMAND_EXPRESSION,
67 SNT_DOLLAR_VARIABLE_DHOP,
88 SNT_COMMAND_BLOCK_SUBSHELL,
105 : std::invalid_argument(sMessage) {
129 const std::size_t nPos
148 [[nodiscard]] std::size_t
get_pos() const noexcept {
173 const std::size_t nPos
203 const std::size_t nPos
216 std::vector<std::string> &vTokens,
239 std::vector<std::unique_ptr<shell_node_expandable> > &&vChildren
248 std::vector<std::string> &vTokens,
258 [[nodiscard]]
const std::vector<std::unique_ptr<shell_node_expandable> > &
get_children() const noexcept {
259 return this->m_vChildren;
263 std::vector<std::unique_ptr<shell_node_expandable> > m_vChildren;
285 std::vector<std::unique_ptr<shell_node_expandable> > &&vChildren
294 std::vector<std::string> &vTokens,
303 [[nodiscard]]
const std::vector<std::unique_ptr<shell_node_expandable> > &
get_children() const noexcept {
304 return this->m_vChildren;
308 std::vector<std::unique_ptr<shell_node_expandable> > m_vChildren;
325 const std::size_t nPos,
326 std::vector<std::unique_ptr<shell_node_expandable> > &&vChildren
347 const std::size_t nPos,
348 std::vector<std::unique_ptr<shell_node_expandable> > &&vChildren
372 std::unique_ptr<shell_node_evaluable> &&pCommand
381 std::vector<std::string> &vTokens,
391 return this->m_pCommand.get();
395 std::unique_ptr<shell_node_evaluable> m_pCommand;
412 const std::size_t nPos,
416 m_sText(std::move(sText)) {
425 std::vector<std::string> &vTokens,
435 [[nodiscard]] std::string
get_text() const noexcept {
436 return this->m_sText;
458 const std::size_t nPos,
459 const char32_t cCharacter
462 m_cCharacter(cCharacter) {
470 std::vector<std::string> &vTokens,
481 return this->m_cCharacter;
485 char32_t m_cCharacter;
504 const std::size_t nPos
518 std::vector<std::string> &vTokens,
544 const std::size_t nPos,
545 const std::uint64_t nArg
563 [[nodiscard]] std::uint64_t
get_arg() const noexcept {
568 std::uint64_t m_nArg;
585 const std::size_t nPos,
586 std::string sVariable
589 m_sVariable(std::move(sVariable)) {
605 return this->m_sVariable;
609 std::string m_sVariable;
626 const std::size_t nPos,
627 std::string sVariable
630 m_sVariable(std::move(sVariable)) {
646 return this->m_sVariable;
650 std::string m_sVariable;
665 const std::size_t nPos,
666 const std::uint64_t nArg
684 [[nodiscard]] std::uint64_t
get_arg() const noexcept {
689 std::uint64_t m_nArg;
704 const std::size_t nPos,
705 const std::uint64_t nArg
723 [[nodiscard]] std::uint64_t
get_arg() const noexcept {
728 std::uint64_t m_nArg;
743 const std::size_t nPos,
744 std::string sVariable
747 m_sVariable(std::move(sVariable)) {
763 return this->m_sVariable;
767 std::string m_sVariable;
786 std::unique_ptr<shell_node_evaluable> &&pCommand
795 std::vector<std::string> &vTokens,
805 return this->m_pCommand.get();
809 std::unique_ptr<shell_node_evaluable> m_pCommand;
824 const std::size_t nPos,
845 return this->m_cItem;
863 const std::size_t nPos
893 std::unique_ptr<shell_node_command_expression> &&pCommand
909 return this->m_pCommand.get();
913 std::unique_ptr<shell_node_command_expression> m_pCommand;
928 const std::size_t nPos,
929 std::vector<std::unique_ptr<shell_node_evaluable> > &&vSubCommands
933 m_vSubCommands(std::move(vSubCommands)) {
948 [[nodiscard]]
const std::vector<std::unique_ptr<shell_node_evaluable> > &
get_children() const noexcept {
949 return this->m_vSubCommands;
953 std::vector<std::unique_ptr<shell_node_evaluable> > m_vSubCommands;
968 const std::size_t nPos,
969 std::vector<std::unique_ptr<shell_node_evaluable> > &&vSubCommands
973 m_vSubCommands(std::move(vSubCommands)) {
988 [[nodiscard]]
const std::vector<std::unique_ptr<shell_node_evaluable> > &
get_children() const noexcept {
989 return this->m_vSubCommands;
993 std::vector<std::unique_ptr<shell_node_evaluable> > m_vSubCommands;
1012 std::unique_ptr<shell_node_evaluable> &&pCommand
1029 return this->m_pCommand.get();
1033 std::unique_ptr<shell_node_evaluable> m_pCommand;
1067 static std::unique_ptr<shell_node_evaluable>
make(
1070 std::unique_ptr<shell_node_evaluable> &&pLeft,
1071 std::unique_ptr<shell_node_evaluable> &&pRight
1088 std::unique_ptr<shell_node_evaluable> &&pLeft,
1089 std::unique_ptr<shell_node_evaluable> &&pRight
1114 return this->m_nPriority;
1122 return this->m_pLeft.get();
1130 return this->m_pRight.get();
1139 std::unique_ptr<shell_node_evaluable>
swap_left(std::unique_ptr<shell_node_evaluable> &&pLeft);
1147 std::unique_ptr<shell_node_evaluable>
swap_right(std::unique_ptr<shell_node_evaluable> &&pRight);
1151 std::unique_ptr<shell_node_evaluable> m_pLeft;
1152 std::unique_ptr<shell_node_evaluable> m_pRight;
1171 const std::size_t nPos,
1172 std::unique_ptr<shell_node_evaluable> &&pLeft,
1173 std::unique_ptr<shell_node_evaluable> &&pRight
1178 std::move(pLeft), std::move(pRight)
1192 const std::size_t nPos
1215 const std::size_t nPos,
1216 std::unique_ptr<shell_node_evaluable> &&pLeft,
1217 std::unique_ptr<shell_node_evaluable> &&pRight
1222 std::move(pLeft), std::move(pRight)
1236 const std::size_t nPos
1259 const std::size_t nPos,
1260 std::unique_ptr<shell_node_evaluable> &&pLeft,
1261 std::unique_ptr<shell_node_evaluable> &&pRight
1266 std::move(pLeft), std::move(pRight)
1280 const std::size_t nPos
1306 std::unique_ptr<shell_node_expandable> &&pTest
1329 return this->m_pTest.get();
1334 std::unique_ptr<shell_node_expandable> m_pTest;
1357 std::unique_ptr<shell_node_evaluable> &&pCondition,
1358 std::unique_ptr<shell_node_evaluable> &&pCaseIf,
1359 std::unique_ptr<shell_node_evaluable> &&pCaseElse
1382 return this->m_pCondition.get();
1390 return this->m_pCaseIf.get();
1398 return this->m_pCaseElse.get();
1403 std::unique_ptr<shell_node_evaluable> m_pCondition;
1405 std::unique_ptr<shell_node_evaluable> m_pCaseIf;
1407 std::unique_ptr<shell_node_evaluable> m_pCaseElse;
1525 std::string sVariable,
1526 std::unique_ptr<shell_node_expandable> &&pSequence,
1527 std::unique_ptr<shell_node_evaluable> &&pIterative
1550 return this->m_sVariable;
1558 return this->m_pSequence.get();
1566 return this->m_pIterative.get();
1570 std::string m_sVariable;
1571 std::unique_ptr<shell_node_expandable> m_pSequence;
1572 std::unique_ptr<shell_node_evaluable> m_pIterative;
1597 std::unique_ptr<shell_node_evaluable> &&pCondition,
1598 std::unique_ptr<shell_node_evaluable> &&pIterative
1620 return this->m_pCondition.get();
1628 return this->m_pIterative.get();
1633 std::unique_ptr<shell_node_evaluable> m_pCondition;
1635 std::unique_ptr<shell_node_evaluable> m_pIterative;
1657 std::unique_ptr<shell_node_evaluable> &&pCondition,
1658 std::unique_ptr<shell_node_evaluable> &&pIterative
1680 return this->m_pCondition.get();
1688 return this->m_pIterative.get();
1693 std::unique_ptr<shell_node_evaluable> m_pCondition;
1695 std::unique_ptr<shell_node_evaluable> m_pIterative;
1713 std::unique_ptr<shell_node_expandable> &&pName,
1714 std::unique_ptr<shell_node_evaluable> &&pBody
1732 return this->m_pName.get();
1740 return this->m_pBody.get();
1745 std::unique_ptr<shell_node_expandable> m_pName;
1746 std::unique_ptr<shell_node_evaluable> m_pBody;
Logical AND operator node (executes right only if left succeeded).
Definition shell_node.h:1159
shell_status evaluate(shell_session &oSession) const override
Evaluate logical AND semantics.
Definition shell_node_evaluate.cpp:106
shell_node_and(const std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
Construct an AND node.
Definition shell_node.h:1170
Extract positional argument from the session (e.g. $1, $2).
Definition shell_node.h:536
shell_node_arg(const std::size_t nPos, const std::uint64_t nArg)
Construct an argument extractor.
Definition shell_node.h:543
std::string get_value(const shell_session &oSession) const override
Return the argument value from the session.
Definition shell_node_expand.cpp:139
std::uint64_t get_arg() const noexcept
Get the argument index this node references.
Definition shell_node.h:563
Evaluates a subcommand in background semantics (implementation-specific).
Definition shell_node.h:1002
shell_status evaluate(shell_session &oSession) const override
Evaluate the background node (typically launches and returns immediately).
Definition shell_node_evaluate.cpp:102
const shell_node_evaluable * get_command() const noexcept
Get pointer to the underlying command.
Definition shell_node.h:1028
Exception used internally to signal a loop "break".
Definition shell_node.h:1475
break_signal()
Construct a break signal exception.
Definition shell_node.h:1478
Represents a break statement inside a loop.
Definition shell_node.h:1466
shell_status evaluate(shell_session &oSession) const override
Evaluate the break node.
Definition shell_node_evaluate.cpp:179
shell_node_break(const std::size_t nPos)
Construct a break node.
Definition shell_node.h:1500
Command block executed in a subshell (may isolate environment changes).
Definition shell_node.h:960
shell_status evaluate(shell_session &oSession) const override
Evaluate the block in a subshell context.
Definition shell_node_evaluate.cpp:90
const std::vector< std::unique_ptr< shell_node_evaluable > > & get_children() const noexcept
Access the subshell's subcommands.
Definition shell_node.h:988
shell_node_command_block_subshell(const std::size_t nPos, std::vector< std::unique_ptr< shell_node_evaluable > > &&vSubCommands)
Construct a subshell command block.
Definition shell_node.h:967
A sequence of evaluable nodes executed in order (a block).
Definition shell_node.h:920
shell_node_command_block(const std::size_t nPos, std::vector< std::unique_ptr< shell_node_evaluable > > &&vSubCommands)
Construct a command block.
Definition shell_node.h:927
const std::vector< std::unique_ptr< shell_node_evaluable > > & get_children() const noexcept
Access subcommands.
Definition shell_node.h:948
shell_status evaluate(shell_session &oSession) const override
Evaluate each subcommand in order.
Definition shell_node_evaluate.cpp:83
Represents a command expression composed of expandable children.
Definition shell_node.h:229
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand the expression by expanding its children in order. Expand the node into textual tokens....
Definition shell_node_expand.cpp:38
const std::vector< std::unique_ptr< shell_node_expandable > > & get_children() const noexcept
Access the child nodes.
Definition shell_node.h:258
Wraps a command expression and executes it as a command.
Definition shell_node.h:885
const shell_node_command_expression * get_command() const noexcept
Get pointer to the underlying command expression.
Definition shell_node.h:908
shell_status evaluate(shell_session &oSession) const override
Evaluate (execute) the command expression.
Definition shell_node_evaluate.cpp:39
Exception used internally to signal a loop "continue".
Definition shell_node.h:1427
continue_signal()
Construct a continue signal exception.
Definition shell_node.h:1430
Represents a continue statement inside a loop.
Definition shell_node.h:1418
shell_status evaluate(shell_session &oSession) const override
Evaluate the continue node.
Definition shell_node_evaluate.cpp:175
shell_node_continue(const std::size_t nPos)
Construct a continue node.
Definition shell_node.h:1453
Dollar-argument with "double-hop" semantics (implementation-specific).
Definition shell_node.h:696
std::uint64_t get_arg() const noexcept
Get the argument index.
Definition shell_node.h:723
std::string get_value(const shell_session &oSession) const override
Get the value for this double-hop argument.
Definition shell_node_expand.cpp:171
shell_node_dollar_arg_dhop(const std::size_t nPos, const std::uint64_t nArg)
Construct a double-hop dollar argument node.
Definition shell_node.h:703
Extract an argument referenced with a leading $ (e.g. $@, $* or $1).
Definition shell_node.h:657
shell_node_dollar_arg(const std::size_t nPos, const std::uint64_t nArg)
Construct a dollar-argument extractor.
Definition shell_node.h:664
std::uint64_t get_arg() const noexcept
Get referenced argument index.
Definition shell_node.h:684
std::string get_value(const shell_session &oSession) const override
Retrieve the argument value via the session.
Definition shell_node_expand.cpp:145
Command-substitution node used in $() or backticks when appearing inside other contexts.
Definition shell_node.h:776
const shell_node_evaluable * get_command() const noexcept
Get non-owning pointer to the subcommand.
Definition shell_node.h:804
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand by executing the subcommand and inserting its textual output. Expand the node into textual tok...
Definition shell_node_expand.cpp:202
Special dollar items such as $?, $#, $$, etc. (implementation-specific).
Definition shell_node.h:816
shell_node_dollar_special(const std::size_t nPos, const char cItem)
Construct a dollar-special node.
Definition shell_node.h:823
std::string get_value(const shell_session &oSession) const override
Return the special item's textual value.
Definition shell_node_expand.cpp:223
char get_item() const noexcept
Get the identifying character for this special item.
Definition shell_node.h:844
Dollar-variable with double-hop lookup semantics.
Definition shell_node.h:735
std::string get_value(const shell_session &oSession) const override
Retrieve the variable's double-hop value.
Definition shell_node_expand.cpp:184
std::string get_variable() const noexcept
Get the referenced variable name.
Definition shell_node.h:762
shell_node_dollar_variable_dhop(const std::size_t nPos, std::string sVariable)
Construct a double-hop dollar variable node.
Definition shell_node.h:742
Dollar-prefixed variable node (may have different semantics).
Definition shell_node.h:618
std::string get_variable() const noexcept
Return the referenced variable name.
Definition shell_node.h:645
shell_node_dollar_variable(const std::size_t nPos, std::string sVariable)
Construct a dollar-variable extractor.
Definition shell_node.h:625
std::string get_value(const shell_session &oSession) const override
Get the value for this dollar-variable from the session.
Definition shell_node_expand.cpp:161
Base interface for nodes that can be evaluated (executed).
Definition shell_node.h:164
shell_node_evaluable(const shell_node_type nType, const std::size_t nPos)
Construct an evaluable node.
Definition shell_node.h:171
virtual shell_status evaluate(shell_session &oSession) const =0
Evaluate (execute) the node.
Base interface for nodes that expand to tokens (strings).
Definition shell_node.h:194
virtual void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const =0
Expand the node into textual tokens.
shell_node_expandable(const shell_node_type nType, const std::size_t nPos)
Construct an expandable node.
Definition shell_node.h:201
Iterative 'for' loop node that iterates over an expandable sequence.
Definition shell_node.h:1513
const shell_node_expandable * get_sequence() const noexcept
Get the sequence expandable.
Definition shell_node.h:1557
shell_status evaluate(shell_session &oSession) const override
Evaluate the for-loop.
Definition shell_node_evaluate.cpp:183
const shell_node_evaluable * get_iterative() const noexcept
Get the iterative block executed on each element.
Definition shell_node.h:1565
const std::string & get_variable() const noexcept
Get the loop variable name.
Definition shell_node.h:1549
Create function and adds to the shell session.
Definition shell_node.h:1702
shell_status evaluate(shell_session &oSession) const override
Adds function to the shell session vtable.
Definition shell_node_evaluate.cpp:226
const shell_node_expandable * get_name() const noexcept
Get the function name node.
Definition shell_node.h:1731
const shell_node_evaluable * get_body() const noexcept
Get the function body node.
Definition shell_node.h:1739
Conditional execution node (if-then-else).
Definition shell_node.h:1345
shell_status evaluate(shell_session &oSession) const override
Evaluate the if statement.
Definition shell_node_evaluate.cpp:162
const shell_node_evaluable * get_condition() const noexcept
Get the condition node.
Definition shell_node.h:1381
const shell_node_evaluable * get_case_if() const noexcept
Get the 'if' branch node.
Definition shell_node.h:1389
const shell_node_evaluable * get_case_else() const noexcept
Get the 'else' branch node.
Definition shell_node.h:1397
Exception thrown when a node is constructed with invalid args.
Definition shell_node.h:98
shell_node_invalid_argument(const std::string &sMessage)
Construct the exception with a descriptive message.
Definition shell_node.h:104
Represents a no-op command node (useful as placeholder).
Definition shell_node.h:856
shell_node_null_command(const std::size_t nPos)
Construct a null command node.
Definition shell_node.h:862
shell_status evaluate(shell_session &oSession) const override
Evaluate the null command (typically returns success).
Definition shell_node_evaluate.cpp:77
Base class for binary operator nodes (pipe, and, or) with priority handling.
Definition shell_node.h:1043
static std::unique_ptr< shell_node_evaluable > make(shell_node_type nType, std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
Makes an operator node.
Definition shell_node.cpp:157
std::unique_ptr< shell_node_evaluable > swap_right(std::unique_ptr< shell_node_evaluable > &&pRight)
Swap-in a new right operand, returning the old one.
Definition shell_node.cpp:231
std::unique_ptr< shell_node_evaluable > swap_left(std::unique_ptr< shell_node_evaluable > &&pLeft)
Swap-in a new left operand, returning the old one.
Definition shell_node.cpp:222
int get_priority() const noexcept
Get the operator priority.
Definition shell_node.h:1113
const shell_node_evaluable * get_right() const noexcept
Get (non-owning) pointer to the right operand.
Definition shell_node.h:1129
static constexpr int PRIORITY_OR
Priority for operator or.
Definition shell_node.h:1050
static constexpr int PRIORITY_PIPE
Priority for operator pipe.
Definition shell_node.h:1046
const shell_node_evaluable * get_left() const noexcept
Get (non-owning) pointer to the left operand.
Definition shell_node.h:1121
static constexpr int PRIORITY_AND
Priority for operator and.
Definition shell_node.h:1048
Logical OR operator node (executes right only if left failed).
Definition shell_node.h:1247
shell_node_or(const std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
Construct an OR node.
Definition shell_node.h:1258
shell_status evaluate(shell_session &oSession) const override
Evaluate logical OR semantics.
Definition shell_node_evaluate.cpp:113
Pipe operator node (connects stdout of left to stdin of right).
Definition shell_node.h:1203
shell_status evaluate(shell_session &oSession) const override
Evaluate pipe semantics (setup streams and execute both sides).
Definition shell_node_evaluate.cpp:120
shell_node_pipe(const std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
Construct a pipe node.
Definition shell_node.h:1214
Command-substitution string node (backticks or $(...)).
Definition shell_node.h:362
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand by executing the subcommand and inserting its output. Expand the node into textual tokens....
Definition shell_node_expand.cpp:109
const shell_node_evaluable * get_command() const noexcept
Get the underlying evaluable subcommand.
Definition shell_node.h:390
Double-quoted string node.
Definition shell_node.h:339
shell_node_str_double(const std::size_t nPos, std::vector< std::unique_ptr< shell_node_expandable > > &&vChildren)
Construct a double-quoted string node.
Definition shell_node.h:346
Simple (unquoted) string node.
Definition shell_node.h:317
shell_node_str_simple(const std::size_t nPos, std::vector< std::unique_ptr< shell_node_expandable > > &&vChildren)
Construct an unquoted string node.
Definition shell_node.h:324
Base for string-like nodes composed of expandable fragments.
Definition shell_node.h:273
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand by concatenating child fragments into one token. Expand the node into textual tokens....
Definition shell_node_expand.cpp:94
const std::vector< std::unique_ptr< shell_node_expandable > > & get_children() const noexcept
Get the children fragments.
Definition shell_node.h:303
Node that evaluates an expandable expression as a test/condition.
Definition shell_node.h:1296
shell_status evaluate(shell_session &oSession) const override
Evaluate the test.
Definition shell_node_evaluate.cpp:129
const shell_node_expandable * get_test() const noexcept
Get the underlying expandable test node.
Definition shell_node.h:1328
A single Unicode codepoint node.
Definition shell_node.h:450
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand by converting the codepoint into UTF-8 and appending it.
Definition shell_node_expand.cpp:85
char32_t get_character() const noexcept
Returns the stored UTF-32 codepoint.
Definition shell_node.h:480
shell_node_unicode(const std::size_t nPos, const char32_t cCharacter)
Construct a unicode codepoint node.
Definition shell_node.h:457
'Until' loop node that executes the iterative block until the condition succeeds.
Definition shell_node.h:1646
shell_status evaluate(shell_session &oSession) const override
Evaluate the until-loop.
Definition shell_node_evaluate.cpp:212
const shell_node_evaluable * get_condition() const noexcept
Get the stopping condition node.
Definition shell_node.h:1679
const shell_node_evaluable * get_iterative() const noexcept
Get the iterative block executed while the condition fails.
Definition shell_node.h:1687
Extract a named shell variable from the session environment.
Definition shell_node.h:577
std::string get_value(const shell_session &oSession) const override
Get the variable's value from the session.
Definition shell_node_expand.cpp:151
std::string get_variable() const noexcept
Name of the referenced variable.
Definition shell_node.h:604
shell_node_variable(const std::size_t nPos, std::string sVariable)
Construct a variable extractor.
Definition shell_node.h:584
While-loop node executing the iterative block while the condition succeeds.
Definition shell_node.h:1586
const shell_node_evaluable * get_iterative() const noexcept
Get the iterative block node.
Definition shell_node.h:1627
shell_status evaluate(shell_session &oSession) const override
Evaluate the while-loop.
Definition shell_node_evaluate.cpp:198
const shell_node_evaluable * get_condition() const noexcept
Get the condition node.
Definition shell_node.h:1619
A plain word token node.
Definition shell_node.h:404
void expand(std::vector< std::string > &vTokens, shell_session &oSession, bool bSplit) const override
Expand by appending the literal text as a token. Expand the node into textual tokens....
Definition shell_node_expand.cpp:78
shell_node_word(const std::size_t nPos, std::string sText)
Construct a word node.
Definition shell_node.h:411
std::string get_text() const noexcept
Get the stored text.
Definition shell_node.h:435
Base class for all parser nodes.
Definition shell_node.h:116
std::size_t get_pos() const noexcept
Get node position in the original input stream.
Definition shell_node.h:148
virtual ~shell_node()=default
Virtual default destructor for polymorphic deletion.
shell_node_type get_type() const noexcept
Get the node type.
Definition shell_node.h:140
const std::size_t m_nPos
Position in the input stream.
Definition shell_node.h:154
const shell_node_type m_nType
Node type.
Definition shell_node.h:153
shell_node(const shell_node_type nType, const std::size_t nPos)
Protected constructor used by derived classes.
Definition shell_node.h:127
Represents an execution environment for a shell instance.
Definition shell_session.h:57
BashSpark main namespace.
Definition command.h:39
shell_node_type
Types of nodes recognized by the shell parser.
Definition shell_node.h:56
shell_status
Shell status codes.
Definition shell_status.h:47
Defines status codes for the shell.