BashSpark
Loading...
Searching...
No Matches
bs Namespace Reference

BashSpark main namespace. More...

Classes

class  basic_ifakestream
 A class for input stream behavior with a character type. More...
 
class  basic_iinullstream
 A null input stream that provides no input. More...
 
class  basic_nullbuffer
 A null stream buffer that ignores all input and output. More...
 
class  basic_ofakestream
 A class for output stream behavior with a character type. More...
 
class  basic_onullstream
 A null output stream that discards all output. More...
 
class  command
 Abstract base class for all shell commands. More...
 
class  command_echo
 Built-in command that prints all arguments to stdout. More...
 
class  command_eval
 Built-in command that evaluates its arguments as a shell command. More...
 
class  command_fcall
 Calls a function. More...
 
class  command_getenv
 Retrieves the value of an environment variable. More...
 
class  command_getvar
 Retrieves the value of an local variable. More...
 
class  command_math
 Prints on stdout the result of a mathematical operation. More...
 
class  command_seq
 Prints a sequence on stdout. Supports negative numbers and decreasing sequences. More...
 
class  command_setenv
 Sets the value of an environment variable. More...
 
class  command_setvar
 Sets the value of a local variable. More...
 
class  command_test
 Performs a test. Returns through status code. More...
 
struct  math_error
 Exception representing a math-related error during expression evaluation. More...
 
struct  math_parser
 Structure to help class command_math parse it's parameters. More...
 
class  shell
 A simplified shell environment inspired by Bash. More...
 
class  shell_arg
 Represents a command line argument list for shell commands. More...
 
class  shell_env
 Represents an environment for shell commands. More...
 
struct  shell_hash
 Custom hash functor for strings using the 64-bit FNV-1a algorithm. More...
 
struct  shell_hash_view
 Custom hash functor for strings using the 64-bit FNV-1a algorithm. More...
 
class  shell_node
 Base class for all parser nodes. More...
 
class  shell_node_and
 Logical AND operator node (executes right only if left succeeded). More...
 
class  shell_node_arg
 Extract positional argument from the session (e.g. $1, $2). More...
 
class  shell_node_background
 Evaluates a subcommand in background semantics (implementation-specific). More...
 
class  shell_node_break
 Represents a break statement inside a loop. More...
 
class  shell_node_command
 Wraps a command expression and executes it as a command. More...
 
class  shell_node_command_block
 A sequence of evaluable nodes executed in order (a block). More...
 
class  shell_node_command_block_subshell
 Command block executed in a subshell (may isolate environment changes). More...
 
class  shell_node_command_expression
 Represents a command expression composed of expandable children. More...
 
class  shell_node_continue
 Represents a continue statement inside a loop. More...
 
class  shell_node_dollar_arg
 Extract an argument referenced with a leading $ (e.g. $@, $* or $1). More...
 
class  shell_node_dollar_arg_dhop
 Dollar-argument with "double-hop" semantics (implementation-specific). More...
 
class  shell_node_dollar_command
 Command-substitution node used in $() or backticks when appearing inside other contexts. More...
 
class  shell_node_dollar_special
 Special dollar items such as $?, $#, $$, etc. (implementation-specific). More...
 
class  shell_node_dollar_variable
 Dollar-prefixed variable node (may have different semantics). More...
 
class  shell_node_dollar_variable_dhop
 Dollar-variable with double-hop lookup semantics. More...
 
class  shell_node_evaluable
 Base interface for nodes that can be evaluated (executed). More...
 
class  shell_node_expandable
 Base interface for nodes that expand to tokens (strings). More...
 
class  shell_node_for
 Iterative 'for' loop node that iterates over an expandable sequence. More...
 
class  shell_node_function
 Create function and adds to the shell session. More...
 
class  shell_node_if
 Conditional execution node (if-then-else). More...
 
class  shell_node_invalid_argument
 Exception thrown when a node is constructed with invalid args. More...
 
class  shell_node_null_command
 Represents a no-op command node (useful as placeholder). More...
 
class  shell_node_operator
 Base class for binary operator nodes (pipe, and, or) with priority handling. More...
 
class  shell_node_or
 Logical OR operator node (executes right only if left failed). More...
 
class  shell_node_pipe
 Pipe operator node (connects stdout of left to stdin of right). More...
 
class  shell_node_session_extractor
 Base for nodes that extract values from the session (args/vars/etc.). More...
 
class  shell_node_str
 Base for string-like nodes composed of expandable fragments. More...
 
class  shell_node_str_back
 Command-substitution string node (backticks or $(...)). More...
 
class  shell_node_str_double
 Double-quoted string node. More...
 
class  shell_node_str_simple
 Simple (unquoted) string node. More...
 
class  shell_node_test
 Node that evaluates an expandable expression as a test/condition. More...
 
class  shell_node_unicode
 A single Unicode codepoint node. More...
 
class  shell_node_until
 'Until' loop node that executes the iterative block until the condition succeeds. More...
 
class  shell_node_variable
 Extract a named shell variable from the session environment. More...
 
class  shell_node_visitor
 Generic visitor for shell AST nodes. More...
 
class  shell_node_visitor_json
 Visitor that converts shell nodes into JSON. More...
 
class  shell_node_while
 While-loop node executing the iterative block while the condition succeeds. More...
 
class  shell_node_word
 A plain word token node. More...
 
class  shell_parser
 Parses tokens into an evaluable shell AST. More...
 
class  shell_parser_exception
 Exception class for handling shell-specific errors. More...
 
class  shell_session
 Represents an execution environment for a shell instance. More...
 
struct  shell_token
 Represents a token generated during command parsing. More...
 
class  shell_tokenizer
 
class  shell_var
 Represents a variable map for shell commands. More...
 
class  shell_vtable
 Represents an environment for shell commands. More...
 
struct  test_error
 Exception representing a test-related error during expression evaluation. More...
 
struct  test_parser
 Structure to help class command_test parse it's parameters. More...
 
class  token_holder
 A class that manages a collection of shell tokens for processing. More...
 

Typedefs

using ifakestream = basic_ifakestream< char >
 Alias for basic_ifakestream with char.
 
using wifakestream = basic_ifakestream< wchar_t >
 Alias for basic_ifakestream with wchar_t.
 
using u8ifakestream = basic_ifakestream< char8_t >
 Alias for basic_ifakestream with char8_t.
 
using u16ifakestream = basic_ifakestream< char16_t >
 Alias for basic_ifakestream with char16_t.
 
using u32ifakestream = basic_ifakestream< char32_t >
 Alias for basic_ifakestream with char32_t.
 
using ofakestream = basic_ofakestream< char >
 Alias for basic_ofakestream with char.
 
using wofakestream = basic_ofakestream< wchar_t >
 Alias for basic_ofakestream with wchar_t.
 
using u8ofakestream = basic_ofakestream< char8_t >
 Alias for basic_ofakestream with char8_t.
 
using u16ofakestream = basic_ofakestream< char16_t >
 Alias for basic_ofakestream with char16_t.
 
using u32ofakestream = basic_ofakestream< char32_t >
 Alias for basic_ofakestream with char32_t.
 
using onullstream = basic_onullstream< char, std::char_traits< char > >
 Type alias for a null output stream using char type.
 
using u8onullstream = basic_onullstream< char8_t, std::char_traits< char8_t > >
 Type alias for a null output stream using char8_t type.
 
using u16onullstream = basic_onullstream< char16_t, std::char_traits< char16_t > >
 Type alias for a null output stream using char16_t type.
 
using u32onullstream = basic_onullstream< char32_t, std::char_traits< char32_t > >
 Type alias for a null output stream using char32_t type.
 
using inullstream = basic_iinullstream< char, std::char_traits< char > >
 Type alias for a null input stream using char type.
 
using u8inullstream = basic_iinullstream< char8_t, std::char_traits< char8_t > >
 Type alias for a null input stream using char8_t type.
 
using u16inullstream = basic_iinullstream< char16_t, std::char_traits< char16_t > >
 Type alias for a null input stream using char16_t type.
 
using u32inullstream = basic_iinullstream< char32_t, std::char_traits< char32_t > >
 Type alias for a null input stream using char32_t type.
 
using safe_int = boost::safe_numerics::safe< std::int64_t >
 Sugar syntax: typedef of boost::safe_numerics::safe<std::int64_t>
 
using visit_type = shell_node_visitor_json::visit_type
 Typedef of shell_node_visitor_json::visit_type (sugar syntax)
 
using evaluable_ptr = shell_parser::evaluable_ptr
 Unique pointer to evaluable node (sugar syntax).
 
using expandable_ptr = shell_parser::expandable_ptr
 Unique pointer to expandable node (sugar syntax).
 

Enumerations

enum class  shell_keyword {
  SK_NONE = 0x0 , SK_FUNCTION = 1 << 0 , SK_IF = 1 << 1 , SK_THEN = 1 << 2 ,
  SK_ELSE = 1 << 3 , SK_ELIF = 1 << 4 , SK_FI = 1 << 5 , SK_FOR = 1 << 6 ,
  SK_IN = 1 << 7 , SK_WHILE = 1 << 8 , SK_UNTIL = 1 << 9 , SK_DO = 1 << 10 ,
  SK_DONE = 1 << 11 , SK_CONTINUE = 1 << 12 , SK_BREAK = 1 << 13 , SK_IF_DELIMITER = SK_ELSE | SK_ELIF | SK_FI
}
 Enumeration of shell keywords for scripting. More...
 
enum class  parse_mode {
  PM_NORMAL = 0x0 , PM_BACKQUOTE = 1 << 0 , PM_LOOP = 1 << 1 , PM_FUNCTION_NAME = 1 << 2 ,
  PM_BACKQUOTE_LOOP = PM_BACKQUOTE & PM_LOOP
}
 Enumeration for different parsing modes. More...
 
enum class  shell_node_type {
  SNT_COMMAND_EXPRESSION , SNT_STR_SIMPLE , SNT_STR_DOUBLE , SNT_STR_BACK ,
  SNT_WORD , SNT_UNICODE , SNT_ARG , SNT_VARIABLE ,
  SNT_DOLLAR_SPECIAL , SNT_DOLLAR_VARIABLE , SNT_DOLLAR_VARIABLE_DHOP , SNT_DOLLAR_ARG ,
  SNT_DOLLAR_ARG_DHOP , SNT_DOLLAR_COMMAND , SNT_BACKGROUND , SNT_AND ,
  SNT_PIPE , SNT_OR , SNT_IF , SNT_TEST ,
  SNT_FOR , SNT_WHILE , SNT_UNTIL , SNT_BREAK ,
  SNT_CONTINUE , SNT_FUNCTION , SNT_NULL_COMMAND , SNT_COMMAND ,
  SNT_COMMAND_BLOCK , SNT_COMMAND_BLOCK_SUBSHELL
}
 Types of nodes recognized by the shell parser. More...
 
enum class  shell_status : std::uint32_t {
  SHELL_SUCCESS = 0 , SHELL_ERROR = 1 , SHELL_ERROR_SYNTAX_ERROR , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SIMPLE_QUOTES ,
  SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_DOUBLE_QUOTES , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_BACK_QUOTES , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_PARENTHESES , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_BRACKETS ,
  SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SQR_BRACKETS , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SUBCOMMAND , SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_VARIABLE , SHELL_ERROR_SYNTAX_ERROR_INVALID_VARIABLE_NAME ,
  SHELL_ERROR_SYNTAX_ERROR_UNEXPECTED_TOKEN , SHELL_ERROR_SYNTAX_ERROR_UNEXPECTED_EOF , SHELL_ERROR_SYNTAX_ERROR_ARG_OUT_OF_RANGE , SHELL_ERROR_SYNTAX_ERROR_EMPTY_BLOCK ,
  SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_IF , SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_THEN , SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_LOOP , SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_FOR ,
  SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_IN , SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_WHILE , SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_UNTIL , SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_DO ,
  SHELL_ERROR_SYNTAX_ERROR_INVALID_FUNCTION_NAME , SHELL_ERROR_SYNTAX_ERROR_INVALID_FUNCTION_BODY , SHELL_ERROR_BAD_ENCODING , SHELL_ERROR_COMMAND_NOT_FOUND ,
  SHELL_ERROR_MAX_DEPTH_REACHED , SHELL_CMD_ERROR_GETENV_PARAM_NUMBER , SHELL_CMD_ERROR_GETENV_VARIABLE_NAME_INVALID , SHELL_CMD_ERROR_GETVAR_PARAM_NUMBER ,
  SHELL_CMD_ERROR_GETVAR_VARIABLE_NAME_INVALID , SHELL_CMD_ERROR_SETENV_PARAM_NUMBER , SHELL_CMD_ERROR_SETENV_VARIABLE_NAME_INVALID , SHELL_CMD_ERROR_SETVAR_PARAM_NUMBER ,
  SHELL_CMD_ERROR_SETVAR_VARIABLE_NAME_INVALID , SHELL_CMD_ERROR_SEQ_PARAM_NUMBER , SHELL_CMD_ERROR_SEQ_INVALID_INT_FORMAT , SHELL_CMD_ERROR_SEQ_INT_OUT_OF_BOUNDS ,
  SHELL_CMD_ERROR_SEQ_ITERATION_LOGIC , SHELL_CMD_ERROR_TEST_UNCLOSED_PARENTHESIS , SHELL_CMD_ERROR_TEST_MALFORMED_EXPRESSION , SHELL_CMD_ERROR_TEST_MALFORMED_REGEX ,
  SHELL_CMD_TEST_FALSE , SHELL_CMD_ERROR_MATH_NOT_AN_INTEGER , SHELL_CMD_ERROR_MATH_OVERFLOW , SHELL_CMD_ERROR_MATH_UNDERFLOW ,
  SHELL_CMD_ERROR_MATH_DIV_BY_ZERO , SHELL_CMD_ERROR_MATH_POW_0_EXP_0 , SHELL_CMD_ERROR_MATH_FACTORIAL_NEGATIVE , SHELL_CMD_ERROR_MATH_MALFORMED_EXPRESSION ,
  SHELL_CMD_ERROR_MATH_MAX_DEPTH_REACHED , SHELL_CMD_ERROR_MATH_INVALID_VARIABLE_NAME , SHELL_CMD_ERROR_MATH_SEQ_ITERATION_LOGIC , SHELL_CMD_ERROR_FCALL_PARAM_NUMBER ,
  SHELL_CMD_ERROR_FCALL_FUNCTION_NOT_FOUND , SHELL_CMD_ERROR = 108
}
 Shell status codes. More...
 
enum class  shell_token_type {
  TK_SPACE , TK_WORD , TK_UNICODE , TK_ESCAPED ,
  TK_QUOTE_SIMPLE , TK_QUOTE_DOUBLE , TK_QUOTE_BACK , TK_DOLLAR ,
  TK_DOLLAR_SPECIAL , TK_EXCLAMATION , TK_CMD_SEPARATOR , TK_OPEN_PARENTHESIS ,
  TK_CLOSE_PARENTHESIS , TK_OPEN_BRACKETS , TK_CLOSE_BRACKETS , TK_OPEN_SQR_BRACKETS ,
  TK_CLOSE_SQR_BRACKETS , TK_PIPE , TK_OR , TK_BACKGROUND ,
  TK_AND , TK_OPERATOR , TK_EOF
}
 Enumeration of types of tokens that can be parsed from shell commands. More...
 
enum class  math_operator {
  MO_NONE , MO_PLUS , MO_MINUS , MO_MULT ,
  MO_DIV , MO_MOD , MO_POW , MO_EOF ,
  MO_FACTORIAL , MO_SIGN , MO_ABS , MO_SUM ,
  MO_PRODUCT , MO_FUNC_ARG_SEP , MO_OPEN_PARENTHESIS , MO_CLOSE_PARENTHESIS
}
 Enumeration of all supported mathematical operators. More...
 
enum class  test_operator {
  TO_NONE , TO_EOF , TO_EQUALS , TO_MATCHES ,
  TO_GREATER_THAN , TO_LESS_THAN , TO_GREATER_THAN_OR_EQUALS , TO_LESS_THAN_OR_EQUALS ,
  TO_NOT_EQUALS , TO_EMPTY , TO_NON_EMPTY , TO_OR ,
  TO_AND , TO_PARENTHESIS_OPEN , TO_PARENTHESIS_CLOSE
}
 An enumeration representing various comparison and logical operators. More...
 

Functions

constexpr bool has (const parse_mode nItem, const parse_mode nSet)
 Checks if the bitwise and of two parse_mode is 0.
 
constexpr bool has (const shell_keyword nItem, const shell_keyword nSet)
 Checks if the bitwise and of two shell_keyword is 0.
 
constexpr shell_status make_user_code (const unsigned int nCode)
 Generates status codes for user use from user codes.
 
constexpr bool is_syntax_error (const shell_status nStatus)
 
constexpr std::uint64_t hash (const char *const pString, const std::size_t nLength)
 Hashes a string.
 
constexpr std::uint64_t hash (const std::string_view sString)
 Hashes a string.
 
std::uint64_t hash (const std::string &sString)
 Hashes a string.
 
constexpr std::uint64_t hash (const char *const pString)
 Hashes a string.
 
constexpr bool is_arg (const std::string_view &sArg)
 Check whether a std::string represents a valid unsigned integer argument.
 
bool is_arg (const std::string &sArg)
 Check whether a std::string represents a valid unsigned integer argument.
 
constexpr bool is_var (const std::string_view &sVar)
 Internal helper: check whether the given string_view is a valid variable name.
 
bool is_var (const std::string &sVar)
 Internal helper: check whether the given string_view is a valid variable name.
 
constexpr bool is_number (const std::string_view &sArg)
 Checks if the provided string is a valid representation of a number.
 
constexpr char32_t combine_surrogates (const char16_t high, const char16_t low)
 Combines high and low UTF-16 surrogates into a UTF-32 code point.
 
std::string to_hex_string (const char32_t cChar, const std::size_t nLength)
 Converts a UTF-32 character to a hexadecimal string representation.
 
void write_char32_t (ofakestream &oStream, const char32_t cChar)
 Writes a UTF-32 character to an output stream in UTF-8 encoding.
 
std::string write_char32_t (const char32_t cChar)
 Converts a UTF-32 character to a UTF-8 encoded string.
 
bool parse_utf (ifakestream &oIstream, const std::size_t nCount, char32_t &cResult)
 Parses a UTF-n encoded character from an input stream.
 
std::vector< std::string > split_string (const std::string_view &oString)
 Splits a string into a vector.
 
void split_string (std::vector< std::string > &vStrings, const std::string_view &oString)
 Splits a string into a vector.
 
void insert_vector (std::vector< std::string > &vDestiny, std::vector< std::string > vOrigin)
 Moves appends the contents of the origin vector into the destination vector.
 
void concat_vector (ofakestream &oOstream, const std::vector< std::string > &vOrigin)
 Writes the contents of a vector<string> on an output stream.
 
std::int64_t get_pid ()
 Gets the PID process of the shell On non recognized platforms returns 0.
 
shell_keyword get_keyword_id (const std::string_view &oString)
 Identifies shell special keywords.
 
shell_keyword get_keyword_id (const std::string &oString)
 Identifies shell special keywords.
 

Variables

constexpr std::size_t SHELL_MAX_DEPTH = 16
 Maximum depth allowed for shell.
 
constexpr std::uint64_t FNV_OFFSET_BASIS = 2166136261
 FVN-1 offset basis.
 
constexpr std::uint64_t FNVPrime = 16777619
 FVN-1 prime number.
 

Detailed Description

BashSpark main namespace.

Typedef Documentation

◆ onullstream

using bs::onullstream = typedef basic_onullstream<char, std::char_traits<char> >

Type alias for a null output stream using char type.

Type definitions for simple streams

Enumeration Type Documentation

◆ math_operator

enum class bs::math_operator
strong

Enumeration of all supported mathematical operators.

Enumerator
MO_NONE 

No operator.

MO_PLUS 

Addition.

MO_MINUS 

Subtraction.

MO_MULT 

Multiplication.

MO_DIV 

Division.

MO_MOD 

Modulo.

MO_POW 

Power.

MO_EOF 

End of formula/input.

MO_FACTORIAL 

Factorial.

MO_SIGN 

Unary sign (+/-)

MO_ABS 

Absolute value.

MO_SUM 

Summation.

MO_PRODUCT 

Product.

MO_FUNC_ARG_SEP 

Function argument separator (e.g., comma)

MO_OPEN_PARENTHESIS 

'(' token

MO_CLOSE_PARENTHESIS 

')' token

◆ parse_mode

enum class bs::parse_mode
strong

Enumeration for different parsing modes.

This enum defines various modes for the parsing process, allowing for specific behaviors depending on the mode set.

Enumerator
PM_NORMAL 

Normal parsing mode.

PM_BACKQUOTE 

Backquote parsing mode.

PM_LOOP 

Loop parsing mode.

PM_BACKQUOTE_LOOP 

Combined mode for handling both backquote and looping.

◆ shell_keyword

enum class bs::shell_keyword
strong

Enumeration of shell keywords for scripting.

Enumerator
SK_NONE 

No keyword (default value).

SK_FUNCTION 

Start of a function definition.

SK_IF 

Beginning of an if conditional statement.

SK_THEN 

Block that executes if the 'if' condition is true.

SK_ELSE 

Alternative block for when the 'if' condition is false.

SK_ELIF 

Additional condition in an if-else chain.

SK_FI 

End of an if-else construct.

SK_FOR 

Start of a for loop.

SK_IN 

Collection specified in a for loop.

SK_WHILE 

Start of a while loop.

SK_UNTIL 

Loop continues until a condition is met.

SK_DO 

Beginning of a block for loops and conditionals.

SK_DONE 

End of a do block or loop.

SK_CONTINUE 

Continue statement.

SK_BREAK 

Break staement.

SK_IF_DELIMITER 

End of a if block.

◆ shell_node_type

enum class bs::shell_node_type
strong

Types of nodes recognized by the shell parser.

Values include language constructs (IF/FOR/WHILE), tokens (WORD, ARG), expansion tokens ($VAR, command substitution) and executable nodes (COMMAND, COMMAND_BLOCK, etc.).

◆ shell_status

enum class bs::shell_status : std::uint32_t
strong

Shell status codes.

Warning
Defining command error codes below bs::shell_status::SHELL_CMD_ERROR results in undefined behaviour.
Enumerator
SHELL_SUCCESS 

Indicates successful execution.

SHELL_ERROR 

Indicates a generic error occurred.

SHELL_ERROR_SYNTAX_ERROR 

Indicates a syntax error in the command.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SIMPLE_QUOTES 

Indicates a syntax error in the command, unclosed simple quotes.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_DOUBLE_QUOTES 

Indicates a syntax error in the command, unclosed double quotes.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_BACK_QUOTES 

Indicates a syntax error in the command, unclosed back quotes.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_PARENTHESES 

Indicates a syntax error in the command, unclosed parentheses.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_BRACKETS 

Indicates a syntax error in the command, unclosed brackets.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SQR_BRACKETS 

Indicates a syntax error in the command, unclosed square brackets.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_SUBCOMMAND 

Indicates a syntax error in the command, unclosed back quotes.

SHELL_ERROR_SYNTAX_ERROR_UNCLOSED_VARIABLE 

Indicates a syntax error in the command, unclosed back variable.

SHELL_ERROR_SYNTAX_ERROR_INVALID_VARIABLE_NAME 

Indicates a syntax error in the command, invalid variable name.

SHELL_ERROR_SYNTAX_ERROR_UNEXPECTED_TOKEN 

Indicates a syntax error in the command, unexpected token.

SHELL_ERROR_SYNTAX_ERROR_UNEXPECTED_EOF 

Indicates a syntax error in the command, unexpected eof.

SHELL_ERROR_SYNTAX_ERROR_ARG_OUT_OF_RANGE 

Indicates a syntax error in the command, an argument out of range.

SHELL_ERROR_SYNTAX_ERROR_EMPTY_BLOCK 

Indicates a syntax error in the command, an empty block.

SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_IF 

Indicates a syntax error in the command, the keyword "if" is not finished.

SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_THEN 

Indicates a syntax error in the command, the keyword "then" is missing.

SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_LOOP 

Indicates a syntax error in the command, the keyword "loop" is not finished.

SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_FOR 

Indicates a syntax error in the command, the keyword "for" is not finished.

SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_IN 

Indicates a syntax error in the command, the keyword "in" is missing.

SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_WHILE 

Indicates a syntax error in the command, the keyword "while" is not finished.

SHELL_ERROR_SYNTAX_ERROR_UNFINISHED_KEYWORD_UNTIL 

Indicates a syntax error in the command, the keyword "until" is not finished.

SHELL_ERROR_SYNTAX_ERROR_MISSING_KEYWORD_DO 

Indicates a syntax error in the command, the keyword "do" is missing.

SHELL_ERROR_SYNTAX_ERROR_INVALID_FUNCTION_NAME 

Indicates a syntax error in the command, invalid function name.

SHELL_ERROR_SYNTAX_ERROR_INVALID_FUNCTION_BODY 

Indicates a syntax error in the command, the function body definition is wrong.

SHELL_ERROR_BAD_ENCODING 

Indicates a syntax error in encoding.

SHELL_ERROR_COMMAND_NOT_FOUND 

Indicates the command was not found.

SHELL_ERROR_MAX_DEPTH_REACHED 

Indicates the maximum depth for command nesting has been reached.

SHELL_CMD_ERROR_GETENV_PARAM_NUMBER 

Indicates an error with the number of parameters for command getenv.

SHELL_CMD_ERROR_GETENV_VARIABLE_NAME_INVALID 

Indicates that the variable name passed to getenv is not valid.

SHELL_CMD_ERROR_GETVAR_PARAM_NUMBER 

Indicates an error with the number of parameters for command getenv.

SHELL_CMD_ERROR_GETVAR_VARIABLE_NAME_INVALID 

Indicates that the variable name passed to getenv is not valid.

SHELL_CMD_ERROR_SETENV_PARAM_NUMBER 

Indicates an error with the number of parameters for command setenv.

SHELL_CMD_ERROR_SETENV_VARIABLE_NAME_INVALID 

Indicates that the variable name passed to setenv is not valid.

SHELL_CMD_ERROR_SETVAR_PARAM_NUMBER 

Indicates an error with the number of parameters for command setenv.

SHELL_CMD_ERROR_SETVAR_VARIABLE_NAME_INVALID 

Indicates that the variable name passed to setenv is not valid.

SHELL_CMD_ERROR_SEQ_PARAM_NUMBER 

Indicates an error with the number of parameters for command seq.

SHELL_CMD_ERROR_SEQ_INVALID_INT_FORMAT 

Indicates that the parameter seq received is not a number.

SHELL_CMD_ERROR_SEQ_INT_OUT_OF_BOUNDS 

Indicates that the parameter seq received a number out of bounds.

SHELL_CMD_ERROR_SEQ_ITERATION_LOGIC 

Command seq: error indicating that the sequence can not be iterated.

SHELL_CMD_ERROR_TEST_UNCLOSED_PARENTHESIS 

Command test: error indicating that opened parenthesis have not been closed.

SHELL_CMD_ERROR_TEST_MALFORMED_EXPRESSION 

Command test: error indicating that the expression is malformed.

SHELL_CMD_ERROR_TEST_MALFORMED_REGEX 

Command test: error indicating that a regex comparation is using an invalid regex.

SHELL_CMD_TEST_FALSE 

Command test: status code indicating that the test is false.

SHELL_CMD_ERROR_MATH_NOT_AN_INTEGER 

Command math: error indicating that the input is not an integer.

SHELL_CMD_ERROR_MATH_OVERFLOW 

Command math: error indicating that the result of a mathematical operation has exceeded the maximum limit.

SHELL_CMD_ERROR_MATH_UNDERFLOW 

Command math: error indicating that the result of a mathematical operation has fallen below the minimum limit.

SHELL_CMD_ERROR_MATH_DIV_BY_ZERO 

Command math: error indicating an attempt to divide by zero, which is undefined.

SHELL_CMD_ERROR_MATH_POW_0_EXP_0 

Command math: error indicating that the calculation of 0 raised to the power of 0 is not defined.

SHELL_CMD_ERROR_MATH_FACTORIAL_NEGATIVE 

Command math: error indicating an attempt to compute the factorial of a negative number, which is not possible.

SHELL_CMD_ERROR_MATH_MALFORMED_EXPRESSION 

Command math: error indicating that the mathematical expression provided is improperly formatted.

SHELL_CMD_ERROR_MATH_MAX_DEPTH_REACHED 

Command math: error indicating that the maximum recursion or computation depth has been reached.

SHELL_CMD_ERROR_MATH_INVALID_VARIABLE_NAME 

Command math: error indicating that the specified variable name does not conform to valid naming conventions.

SHELL_CMD_ERROR_MATH_SEQ_ITERATION_LOGIC 

Command math: error indicating that the sequence can not be iterated.

SHELL_CMD_ERROR_FCALL_PARAM_NUMBER 

Indicates an error with the number of parameters for command fcall.

SHELL_CMD_ERROR_FCALL_FUNCTION_NOT_FOUND 

Command fcall: Indicates the function was not found.

SHELL_CMD_ERROR 

Indicates base error value for commands.

Warning
Defining command error codes below this value results in undefined behaviour.

◆ shell_token_type

enum class bs::shell_token_type
strong

Enumeration of types of tokens that can be parsed from shell commands.

This enum categorizes various components of shell commands to facilitate tokenization and parsing.

Enumerator
TK_SPACE 

Represents whitespace in the command.

TK_WORD 

Represents a word in the command.

TK_UNICODE 

Represents Unicode characters.

TK_ESCAPED 

Represents escaped characters.

TK_QUOTE_SIMPLE 

Represents simple quotes (e.g., 'text').

TK_QUOTE_DOUBLE 

Represents double quotes (e.g., "text").

TK_QUOTE_BACK 

Represents back quotes (e.g., command).

TK_DOLLAR 

Represents a dollar sign ($).

TK_DOLLAR_SPECIAL 

Represents special dollar sign usages (e.g., $?, $).

TK_EXCLAMATION 

Represents an exclamation mark (!).

TK_CMD_SEPARATOR 

Represents command separators (e.g., ;).

TK_OPEN_PARENTHESIS 

Represents an open parenthesis ('(').

TK_CLOSE_PARENTHESIS 

Represents a close parenthesis (')').

TK_OPEN_BRACKETS 

Represents an open bracket ('{').

TK_CLOSE_BRACKETS 

Represents a close bracket ('}').

TK_OPEN_SQR_BRACKETS 

Represents an open square bracket ('[').

TK_CLOSE_SQR_BRACKETS 

Represents a close square bracket (']').

TK_PIPE 

Represents a pipe (|).

TK_OR 

Represents a logical OR (||).

TK_BACKGROUND 

Represents background execution (&).

TK_AND 

Represents logical AND (&&).

TK_OPERATOR 

Represents various operators.

TK_EOF 

Represents the end of the file/input.

◆ test_operator

enum class bs::test_operator
strong

An enumeration representing various comparison and logical operators.

This enum class defines a set of operators that can be used in expressions to perform comparisons, checks, or logical operations.

Enumerator
TO_NONE 

Represents no operation.

TO_EOF 

Represents the end of a file condition.

TO_EQUALS 

Represents equality comparison.

TO_MATCHES 

Represents matching condition.

TO_GREATER_THAN 

Represents greater than comparison.

TO_LESS_THAN 

Represents less than comparison.

TO_GREATER_THAN_OR_EQUALS 

Represents greater than or equal to comparison.

TO_LESS_THAN_OR_EQUALS 

Represents less than or equal to comparison.

TO_NOT_EQUALS 

Represents not equal comparison.

TO_EMPTY 

Represents an empty condition.

TO_NON_EMPTY 

Represents a non-empty condition.

TO_OR 

Represents logical OR operation.

TO_AND 

Represents logical AND operation.

TO_PARENTHESIS_OPEN 

Represents an opening parenthesis.

TO_PARENTHESIS_CLOSE 

Represents a closing parenthesis.

Function Documentation

◆ combine_surrogates()

constexpr char32_t bs::combine_surrogates ( const char16_t  high,
const char16_t  low 
)
constexpr

Combines high and low UTF-16 surrogates into a UTF-32 code point.

Parameters
highThe high surrogate (in the range 0xD800 to 0xDBFF).
lowThe low surrogate (in the range 0xDC00 to 0xDFFF).
Returns
The corresponding UTF-32 code point.

◆ concat_vector()

void bs::concat_vector ( ofakestream oOstream,
const std::vector< std::string > &  vOrigin 
)
inline

Writes the contents of a vector<string> on an output stream.

Parameters
oOstreamOutput stream to write
vOriginVector to write

◆ get_keyword_id() [1/2]

shell_keyword bs::get_keyword_id ( const std::string &  oString)
inline

Identifies shell special keywords.

Parameters
oStringKeyword to identify
Returns
Keyword code

◆ get_keyword_id() [2/2]

shell_keyword bs::get_keyword_id ( const std::string_view &  oString)
inline

Identifies shell special keywords.

Parameters
oStringKeyword to identify
Returns
Keyword code

◆ get_pid()

std::int64_t bs::get_pid ( )
inline

Gets the PID process of the shell On non recognized platforms returns 0.

Returns
PID process of the shell

◆ has() [1/2]

constexpr bool bs::has ( const parse_mode  nItem,
const parse_mode  nSet 
)
constexpr

Checks if the bitwise and of two parse_mode is 0.

Parameters
nItemLeft parse mode
nSetRight parse mode
Returns
Whether the intersection is null

◆ has() [2/2]

constexpr bool bs::has ( const shell_keyword  nItem,
const shell_keyword  nSet 
)
constexpr

Checks if the bitwise and of two shell_keyword is 0.

Parameters
nItemLeft keyword
nSetRight keyword
Returns
Whether the intersection is null

◆ hash() [1/4]

constexpr std::uint64_t bs::hash ( const char *const  pString)
constexpr

Hashes a string.

See hash function implementation details for implementation details.

Parameters
pStringString to hash (C null terminated)
Returns
String hash

◆ hash() [2/4]

constexpr std::uint64_t bs::hash ( const char *const  pString,
const std::size_t  nLength 
)
constexpr

Hashes a string.

This function is the base implementation of all other hashing variant funtions. Currently hashes with FNV-1a.

Parameters
pStringString to hash (C null terminated)
nLengthLength of text to hash
Returns
Hash result

◆ hash() [3/4]

std::uint64_t bs::hash ( const std::string &  sString)
inline

Hashes a string.

See hash function implementation details for implementation details.

Parameters
sStringString to hash
Returns
String hash

◆ hash() [4/4]

constexpr std::uint64_t bs::hash ( const std::string_view  sString)
constexpr

Hashes a string.

See hash function implementation details for implementation details.

Parameters
sStringString to hash
Returns
String hash

◆ insert_vector()

void bs::insert_vector ( std::vector< std::string > &  vDestiny,
std::vector< std::string >  vOrigin 
)
inline

Moves appends the contents of the origin vector into the destination vector.

Parameters
vDestinyDestination vector
vOriginOrigin vector

◆ is_arg() [1/2]

bool bs::is_arg ( const std::string &  sArg)
inline

Check whether a std::string represents a valid unsigned integer argument.

A valid argument:

  • is non-empty
  • contains only digits ('0'–'9')
  • contains at most 19 characters (limits of std::uint64_t)
Parameters
sArgString to validate.
Returns
true if valid; otherwise false.

◆ is_arg() [2/2]

constexpr bool bs::is_arg ( const std::string_view &  sArg)
constexpr

Check whether a std::string represents a valid unsigned integer argument.

A valid argument:

  • is non-empty
  • contains only digits ('0'–'9')
  • contains at most 19 characters (limits of std::uint64_t)
Parameters
sArgString to validate.
Returns
true if valid; otherwise false.

◆ is_number()

constexpr bool bs::is_number ( const std::string_view &  sArg)
constexpr

Checks if the provided string is a valid representation of a number.

This function verifies whether the input string can be interpreted as a numerical value. It checks that the string is not empty, does not exceed a length of 18 digits (limited by std::int64_t range), and contains only digits. It also allows for an optional leading '+' or '-' sign.

Parameters
sArgA string view representing the input string to be checked.
Returns
True if the string is a valid number representation, false otherwise.

◆ is_syntax_error()

constexpr bool bs::is_syntax_error ( const shell_status  nStatus)
constexpr

Check whether a status code represents a syntax error

Parameters
nStatusStatus code to check
Returns
If the status code represents to a syntax error true, false otherwhise

◆ is_var() [1/2]

bool bs::is_var ( const std::string &  sVar)
inline

Internal helper: check whether the given string_view is a valid variable name.

A valid variable name:

  • is non-empty
  • starts with: underscore _ or a letter a–z, A–Z
  • subsequent characters may be:
    • underscore _
    • letters a–z, A–Z
    • digits 0–9
Parameters
sVarString to validate.
Returns
true if the variable name is valid.

◆ is_var() [2/2]

constexpr bool bs::is_var ( const std::string_view &  sVar)
constexpr

Internal helper: check whether the given string_view is a valid variable name.

A valid variable name:

  • is non-empty
  • starts with: underscore _ or a letter a–z, A–Z
  • subsequent characters may be:
    • underscore _
    • letters a–z, A–Z
    • digits 0–9
Parameters
sVarString to validate.
Returns
true if the variable name is valid.

◆ make_user_code()

constexpr shell_status bs::make_user_code ( const unsigned int  nCode)
constexpr

Generates status codes for user use from user codes.

Parameters
nCodeUser code
Returns
Generated status code

◆ parse_utf()

bool bs::parse_utf ( ifakestream oIstream,
const std::size_t  nCount,
char32_t &  cResult 
)
inline

Parses a UTF-n encoded character from an input stream.

Parameters
oIstreamThe input stream to read from.
nCountThe number of hex digits to read (1 for UTF-8, 2 for UTF-16, 4 for UTF-32).
cResultParse UTF-32 character.
Returns
Whether a UTF-32 character could be successfully parsed.

This function reads the specified number of characters, checks for valid hex format, and handles surrogate pairs as needed.

Exceptions
bash_utf_errorIf the input is invalid or not properly encoded.

◆ split_string() [1/2]

std::vector< std::string > bs::split_string ( const std::string_view &  oString)
inline

Splits a string into a vector.

Parameters
oStringString to split
Returns
Vector resulting of string split

◆ split_string() [2/2]

void bs::split_string ( std::vector< std::string > &  vStrings,
const std::string_view &  oString 
)
inline

Splits a string into a vector.

Parameters
vStringsVector of strings where to split
oStringString to split

◆ to_hex_string()

std::string bs::to_hex_string ( const char32_t  cChar,
const std::size_t  nLength 
)
inline

Converts a UTF-32 character to a hexadecimal string representation.

Parameters
cCharThe UTF-32 character to convert.
nLengthThe number of hex digits to include (1 for byte, 2 for UTF-16, 4 for UTF-32).
Returns
A string representing the character in hexadecimal format.

◆ write_char32_t() [1/2]

std::string bs::write_char32_t ( const char32_t  cChar)
inline

Converts a UTF-32 character to a UTF-8 encoded string.

Parameters
cCharThe UTF-32 character to convert.
Returns
A UTF-8 encoded string representation of the character.

◆ write_char32_t() [2/2]

void bs::write_char32_t ( ofakestream oStream,
const char32_t  cChar 
)
inline

Writes a UTF-32 character to an output stream in UTF-8 encoding.

Parameters
oStreamThe output stream to write to.
cCharThe UTF-32 character to encode and write.

This function encodes the character based on its value, handling the appropriate byte sequence for UTF-8.

Variable Documentation

◆ SHELL_MAX_DEPTH

constexpr std::size_t bs::SHELL_MAX_DEPTH = 16
constexpr

Maximum depth allowed for shell.

Surpassing this depth will result in controlled errors.