restyle parser module to match project style

Reduces lint errors from 72 to 44 (-43%). Line count from 1698 to 1313 (-23%).

Another step in resolving issue #2902.
This commit is contained in:
Kurtis Rader 2016-05-02 17:22:44 -07:00
parent ca912f157e
commit 80250c0729
5 changed files with 596 additions and 1026 deletions

View file

@ -268,49 +268,4 @@ void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt);
#define ERROR_BAD_COMMAND_ASSIGN_ERR_MSG \ #define ERROR_BAD_COMMAND_ASSIGN_ERR_MSG \
_(L"Unsupported use of '='. In fish, please use 'set %ls %ls'.") _(L"Unsupported use of '='. In fish, please use 'set %ls %ls'.")
/// While block description.
#define WHILE_BLOCK N_(L"'while' block")
/// For block description.
#define FOR_BLOCK N_(L"'for' block")
/// Breakpoint block.
#define BREAKPOINT_BLOCK N_(L"Block created by breakpoint")
/// If block description.
#define IF_BLOCK N_(L"'if' conditional block")
/// Function definition block description.
#define FUNCTION_DEF_BLOCK N_(L"function definition block")
/// Function invocation block description.
#define FUNCTION_CALL_BLOCK N_(L"function invocation block")
/// Function invocation block description.
#define FUNCTION_CALL_NO_SHADOW_BLOCK N_(L"function invocation block with no variable shadowing")
/// Switch block description.
#define SWITCH_BLOCK N_(L"'switch' block")
/// Fake block description.
#define FAKE_BLOCK N_(L"unexecutable block")
/// Top block description.
#define TOP_BLOCK N_(L"global root block")
/// Command substitution block description.
#define SUBST_BLOCK N_(L"command substitution block")
/// Begin block description.
#define BEGIN_BLOCK N_(L"'begin' unconditional block")
/// Source block description.
#define SOURCE_BLOCK N_(L"Block created by the . builtin")
/// Source block description.
#define EVENT_BLOCK N_(L"event handler block")
/// Unknown block description.
#define UNKNOWN_BLOCK N_(L"unknown/invalid block")
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -1,428 +1,348 @@
/** \file parser.h // The fish parser.
The fish parser.
*/
#ifndef FISH_PARSER_H #ifndef FISH_PARSER_H
#define FISH_PARSER_H #define FISH_PARSER_H
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <list> #include <list>
#include <vector> #include <vector>
#include <stdbool.h>
#include "common.h" #include "common.h"
#include "proc.h"
#include "event.h" #include "event.h"
#include "parse_tree.h"
#include "parse_constants.h"
#include "expand.h" #include "expand.h"
#include "parse_constants.h"
#include "parse_tree.h"
#include "proc.h"
class io_chain_t; class io_chain_t;
/** /// event_blockage_t represents a block on events of the specified type.
event_blockage_t represents a block on events of the specified type struct event_blockage_t {
*/ /// The types of events to block. This is interpreted as a bitset whete the value is 1 for every
struct event_blockage_t /// bit corresponding to a blocked event type. For example, if EVENT_VARIABLE type events should
{ /// be blocked, (type & 1<<EVENT_BLOCKED) should be set.
/** ///
The types of events to block. This is interpreted as a bitset /// Note that EVENT_ANY can be used to specify any event.
whete the value is 1 for every bit corresponding to a blocked
event type. For example, if EVENT_VARIABLE type events should
be blocked, (type & 1<<EVENT_BLOCKED) should be set.
Note that EVENT_ANY can be used to specify any event.
*/
unsigned int typemask; unsigned int typemask;
}; };
typedef std::list<event_blockage_t> event_blockage_list_t; typedef std::list<event_blockage_t> event_blockage_list_t;
inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls, int type) inline bool event_block_list_blocks_type(const event_blockage_list_t &ebls, int type) {
{ for (event_blockage_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); ++iter) {
for (event_blockage_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); ++iter) if (iter->typemask & (1 << EVENT_ANY)) return true;
{ if (iter->typemask & (1 << type)) return true;
if (iter->typemask & (1<<EVENT_ANY))
return true;
if (iter->typemask & (1<<type))
return true;
} }
return false; return false;
} }
/// Types of blocks.
/** enum block_type_t {
Types of blocks WHILE, /// While loop block
*/ FOR, /// For loop block
enum block_type_t IF, /// If block
{ FUNCTION_DEF, /// Function definition block
WHILE, /**< While loop block */ FUNCTION_CALL, /// Function invocation block
FOR, /**< For loop block */ FUNCTION_CALL_NO_SHADOW, /// Function invocation block with no variable shadowing
IF, /**< If block */ SWITCH, /// Switch block
FUNCTION_DEF, /**< Function definition block */ FAKE, /// Fake block
FUNCTION_CALL, /**< Function invocation block */ SUBST, /// Command substitution scope
FUNCTION_CALL_NO_SHADOW, /**< Function invocation block with no variable shadowing */ TOP, /// Outermost block
SWITCH, /**< Switch block */ BEGIN, /// Unconditional block
FAKE, /**< Fake block */ SOURCE, /// Block created by the . (source) builtin
SUBST, /**< Command substitution scope */ EVENT, /// Block created on event notifier invocation
TOP, /**< Outermost block */ BREAKPOINT, /// Breakpoint block
BEGIN, /**< Unconditional block */
SOURCE, /**< Block created by the . (source) builtin */
EVENT, /**< Block created on event notifier invocation */
BREAKPOINT, /**< Breakpoint block */
}; };
/** Possible states for a loop */ /// Possible states for a loop.
enum loop_status_t enum loop_status_t {
{ LOOP_NORMAL, /// current loop block executed as normal
LOOP_NORMAL, /**< Current loop block executed as normal */ LOOP_BREAK, /// current loop block should be removed
LOOP_BREAK, /**< Current loop block should be removed */ LOOP_CONTINUE, /// current loop block should be skipped
LOOP_CONTINUE, /**< Current loop block should be skipped */
}; };
/** /// block_t represents a block of commands.
block_t represents a block of commands. struct block_t {
*/ protected:
struct block_t /// Protected constructor. Use one of the subclasses below.
{
protected:
/** Protected constructor. Use one of the subclasses below. */
explicit block_t(block_type_t t); explicit block_t(block_type_t t);
private: private:
const block_type_t block_type; /**< Type of block. */ /// Type of block.
const block_type_t block_type;
public: public:
block_type_t type() const /// Whether execution of the commands in this block should be skipped.
{ bool skip;
return this->block_type; /// The start index of the block.
} int tok_pos;
/// Offset of the node.
/** Description of the block, for debugging */ node_offset_t node_offset;
wcstring description() const; /// Status for the current loop block. Can be any of the values from the loop_status enum.
bool skip; /**< Whether execution of the commands in this block should be skipped */
int tok_pos; /**< The start index of the block */
node_offset_t node_offset; /* Offset of the node */
/** Status for the current loop block. Can be any of the values from the loop_status enum. */
enum loop_status_t loop_status; enum loop_status_t loop_status;
/// The job that is currently evaluated in the specified block.
/** The job that is currently evaluated in the specified block. */
job_t *job; job_t *job;
/// Name of file that created this block. This string is intern'd.
/** Name of file that created this block. This string is intern'd. */
const wchar_t *src_filename; const wchar_t *src_filename;
/// Line number where this block was created.
/** Line number where this block was created */
int src_lineno; int src_lineno;
/// Whether we should pop the environment variable stack when we're popped off of the block
/** Whether we should pop the environment variable stack when we're popped off of the block stack */ /// stack.
bool wants_pop_env; bool wants_pop_env;
/** List of event blocks. */ block_type_t type() const { return this->block_type; }
/// Description of the block, for debugging.
wcstring description() const;
/// List of event blocks.
event_blockage_list_t event_blocks; event_blockage_list_t event_blocks;
/** Destructor */ /// Destructor
virtual ~block_t(); virtual ~block_t();
}; };
struct if_block_t : public block_t struct if_block_t : public block_t {
{
if_block_t(); if_block_t();
}; };
struct event_block_t : public block_t struct event_block_t : public block_t {
{
event_t const event; event_t const event;
explicit event_block_t(const event_t &evt); explicit event_block_t(const event_t &evt);
}; };
struct function_block_t : public block_t struct function_block_t : public block_t {
{
const process_t *process; const process_t *process;
wcstring name; wcstring name;
function_block_t(const process_t *p, const wcstring &n, bool shadows); function_block_t(const process_t *p, const wcstring &n, bool shadows);
}; };
struct source_block_t : public block_t struct source_block_t : public block_t {
{ const wchar_t *const source_file;
const wchar_t * const source_file;
explicit source_block_t(const wchar_t *src); explicit source_block_t(const wchar_t *src);
}; };
struct for_block_t : public block_t struct for_block_t : public block_t {
{
for_block_t(); for_block_t();
}; };
struct while_block_t : public block_t struct while_block_t : public block_t {
{
while_block_t(); while_block_t();
}; };
struct switch_block_t : public block_t struct switch_block_t : public block_t {
{
switch_block_t(); switch_block_t();
}; };
struct fake_block_t : public block_t struct fake_block_t : public block_t {
{
fake_block_t(); fake_block_t();
}; };
struct scope_block_t : public block_t struct scope_block_t : public block_t {
{ explicit scope_block_t(block_type_t type); // must be BEGIN, TOP or SUBST
explicit scope_block_t(block_type_t type); //must be BEGIN, TOP or SUBST
}; };
struct breakpoint_block_t : public block_t struct breakpoint_block_t : public block_t {
{
breakpoint_block_t(); breakpoint_block_t();
}; };
/** /// Errors that can be generated by the parser.
Errors that can be generated by the parser enum parser_error {
*/ /// No error.
enum parser_error NO_ERR = 0,
{ /// An error in the syntax.
/**
No error
*/
NO_ERR=0,
/**
An error in the syntax
*/
SYNTAX_ERROR, SYNTAX_ERROR,
/** /// Error occured while evaluating commands.
Error occured while evaluating commands
*/
EVAL_ERROR, EVAL_ERROR,
/** /// Error while evaluating cmdsubst.
Error while evaluating cmdsubst
*/
CMDSUBST_ERROR, CMDSUBST_ERROR,
}; };
struct profile_item_t struct profile_item_t {
{ /// Time spent executing the specified command, including parse time for nested blocks.
/** Time spent executing the specified command, including parse time for nested blocks. */
int exec; int exec;
/// Time spent parsing the specified command, including execution time for command
/** Time spent parsing the specified command, including execution time for command substitutions. */ /// substitutions.
int parse; int parse;
/// The block level of the specified command. nested blocks and command substitutions both
/** The block level of the specified command. nested blocks and command substitutions both increase the block level. */ /// increase the block level.
size_t level; size_t level;
/// If the execution of this command was skipped.
/** If the execution of this command was skipped. */
bool skipped; bool skipped;
/// The command string.
/** The command string. */
wcstring cmd; wcstring cmd;
}; };
class parse_execution_context_t; class parse_execution_context_t;
class completion_t; class completion_t;
class parser_t class parser_t {
{
friend class parse_execution_context_t; friend class parse_execution_context_t;
private:
/** Indication that we should skip all blocks */ private:
/// Indication that we should skip all blocks.
bool cancellation_requested; bool cancellation_requested;
/// Indicates that we are within the process of initializing fish.
/** Indicates that we are within the process of initializing fish */
bool is_within_fish_initialization; bool is_within_fish_initialization;
/// Stack of execution contexts. We own these pointers and must delete them.
/** Stack of execution contexts. We own these pointers and must delete them */
std::vector<parse_execution_context_t *> execution_contexts; std::vector<parse_execution_context_t *> execution_contexts;
/// List of called functions, used to help prevent infinite recursion.
/** List of called functions, used to help prevent infinite recursion */
wcstring_list_t forbidden_function; wcstring_list_t forbidden_function;
/// The jobs associated with this parser.
/** The jobs associated with this parser */
job_list_t my_job_list; job_list_t my_job_list;
/// The list of blocks, allocated with new. It's our responsibility to delete these.
/** The list of blocks, allocated with new. It's our responsibility to delete these */
std::vector<block_t *> block_stack; std::vector<block_t *> block_stack;
/** Gets a description of the block stack, for debugging */ /// Gets a description of the block stack, for debugging.
wcstring block_stack_description() const; wcstring block_stack_description() const;
/** List of profile items, allocated with new */ /// List of profile items, allocated with new.
std::vector<profile_item_t *> profile_items; std::vector<profile_item_t *> profile_items;
/* No copying allowed */ // No copying allowed.
parser_t(const parser_t&); parser_t(const parser_t &);
parser_t& operator=(const parser_t&); parser_t &operator=(const parser_t &);
/** Adds a job to the beginning of the job list. */ /// Adds a job to the beginning of the job list.
void job_add(job_t *job); void job_add(job_t *job);
/** /// Returns the name of the currently evaluated function if we are currently evaluating a
Returns the name of the currently evaluated function if we are /// function, null otherwise. This is tested by moving down the block-scope-stack, checking
currently evaluating a function, null otherwise. This is tested by /// every block if it is of type FUNCTION_CALL.
moving down the block-scope-stack, checking every block if it is of
type FUNCTION_CALL.
*/
const wchar_t *is_function() const; const wchar_t *is_function() const;
/* Helper for stack_trace() */ /// Helper for stack_trace().
void stack_trace_internal(size_t block_idx, wcstring *out) const; void stack_trace_internal(size_t block_idx, wcstring *out) const;
public: public:
/// Get the "principal" parser, whatever that is.
/** Get the "principal" parser, whatever that is */
static parser_t &principal_parser(); static parser_t &principal_parser();
/** Indicates that execution of all blocks in the principal parser should stop. /// Indicates that execution of all blocks in the principal parser should stop. This is called
This is called from signal handlers! /// from signal handlers!
*/
static void skip_all_blocks(); static void skip_all_blocks();
/** Create a parser */ /// Create a parser.
parser_t(); parser_t();
/** Global event blocks */ /// Global event blocks.
event_blockage_list_t global_event_blocks; event_blockage_list_t global_event_blocks;
/** /// Evaluate the expressions contained in cmd.
Evaluate the expressions contained in cmd. ///
/// \param cmd the string to evaluate
\param cmd the string to evaluate /// \param io io redirections to perform on all started jobs
\param io io redirections to perform on all started jobs /// \param block_type The type of block to push on the block stack
\param block_type The type of block to push on the block stack ///
/// \return 0 on success, 1 otherwise
\return 0 on success, 1 otherwise
*/
int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type); int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type);
/**
Evaluate the expressions contained in cmd, which has been parsed into the given parse tree. This takes ownership of the tree.
*/
int eval_acquiring_tree(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type, moved_ref<parse_node_tree_t> t);
/** Evaluates a block node at the given node offset in the topmost execution context */ /// Evaluate the expressions contained in cmd, which has been parsed into the given parse tree.
/// This takes ownership of the tree.
int eval_acquiring_tree(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type,
moved_ref<parse_node_tree_t> t);
/// Evaluates a block node at the given node offset in the topmost execution context.
int eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum block_type_t block_type); int eval_block_node(node_offset_t node_idx, const io_chain_t &io, enum block_type_t block_type);
/** /// Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and
Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and cmdsubst execution on the tokens. /// cmdsubst execution on the tokens. The output is inserted into output. Errors are ignored.
The output is inserted into output. ///
Errors are ignored. /// \param arg_src String to evaluate as an argument list
/// \param flags Some expand flags to use
/// \param output List to insert output into
static void expand_argument_list(const wcstring &arg_src, expand_flags_t flags,
std::vector<completion_t> *output);
\param arg_src String to evaluate as an argument list /// Returns a string describing the current parser pisition in the format 'FILENAME (line
\param flags Some expand flags to use /// LINE_NUMBER): LINE'. Example:
\param output List to insert output into ///
*/ /// init.fish (line 127): ls|grep pancake
static void expand_argument_list(const wcstring &arg_src, expand_flags_t flags, std::vector<completion_t> *output);
/**
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
Example:
init.fish (line 127): ls|grep pancake
*/
wcstring current_line(); wcstring current_line();
/** Returns the current line number */ /// Returns the current line number.
int get_lineno() const; int get_lineno() const;
/** Returns the block at the given index. 0 corresponds to the innermost block. Returns NULL when idx is at or equal to the number of blocks. */ /// Returns the block at the given index. 0 corresponds to the innermost block. Returns NULL
/// when idx is at or equal to the number of blocks.
const block_t *block_at_index(size_t idx) const; const block_t *block_at_index(size_t idx) const;
block_t *block_at_index(size_t idx); block_t *block_at_index(size_t idx);
/** Returns the current (innermost) block */ /// Returns the current (innermost) block.
const block_t *current_block() const; const block_t *current_block() const;
block_t *current_block(); block_t *current_block();
/** Count of blocks */ /// Count of blocks.
size_t block_count() const size_t block_count() const { return block_stack.size(); }
{
return block_stack.size();
}
/** Get the list of jobs */ /// Get the list of jobs.
job_list_t &job_list() job_list_t &job_list() { return my_job_list; }
{
return my_job_list;
}
/* Hackish. In order to correctly report the origin of code with no associated file, we need to know whether it's run during initialization or not. */ // Hackish. In order to correctly report the origin of code with no associated file, we need to
// know whether it's run during initialization or not.
void set_is_within_fish_initialization(bool flag); void set_is_within_fish_initialization(bool flag);
/** Pushes the block. pop_block will call delete on it. */ /// Pushes the block. pop_block will call delete on it.
void push_block(block_t *newv); void push_block(block_t *newv);
/** Remove the outermost block namespace */ /// Remove the outermost block namespace.
void pop_block(); void pop_block();
/** Remove the outermost block, asserting it's the given one */ /// Remove the outermost block, asserting it's the given one.
void pop_block(const block_t *b); void pop_block(const block_t *b);
/** Return a description of the given blocktype */ /// Return a description of the given blocktype.
const wchar_t *get_block_desc(int block) const; const wchar_t *get_block_desc(int block) const;
/** Removes a job */ /// Removes a job.
bool job_remove(job_t *job); bool job_remove(job_t *job);
/** Promotes a job to the front of the list */ /// Promotes a job to the front of the list.
void job_promote(job_t *job); void job_promote(job_t *job);
/** Return the job with the specified job id. If id is 0 or less, return the last job used. */ /// Return the job with the specified job id. If id is 0 or less, return the last job used.
job_t *job_get(int job_id); job_t *job_get(int job_id);
/** Returns the job with the given pid */ /// Returns the job with the given pid.
job_t *job_get_from_pid(int pid); job_t *job_get_from_pid(int pid);
/* Returns a new profile item if profiling is active. The caller should fill it in. The parser_t will clean it up. */ /// Returns a new profile item if profiling is active. The caller should fill it in. The
/// parser_t will clean it up.
profile_item_t *create_profile_item(); profile_item_t *create_profile_item();
/** /// Test if the specified string can be parsed, or if more bytes need to be read first. The
Test if the specified string can be parsed, or if more bytes need /// result will have the PARSER_TEST_ERROR bit set if there is a syntax error in the code, and
to be read first. The result will have the PARSER_TEST_ERROR bit /// the PARSER_TEST_INCOMPLETE bit set if the code contains unclosed blocks.
set if there is a syntax error in the code, and the ///
PARSER_TEST_INCOMPLETE bit set if the code contains unclosed /// \param buff the text buffer to test
blocks. /// \param block_level if non-null, the block nesting level will be filled out into this array
/// \param out if non-null, any errors in the command will be filled out into this buffer
/// \param prefix the prefix string to prepend to each error message written to the \c out
/// buffer.
void get_backtrace(const wcstring &src, const parse_error_list_t &errors,
wcstring *output) const;
\param buff the text buffer to test /// Detect errors in the specified string when parsed as an argument list. Returns true if an
\param block_level if non-null, the block nesting level will be filled out into this array /// error occurred.
\param out if non-null, any errors in the command will be filled out into this buffer bool detect_errors_in_argument_list(const wcstring &arg_list_src, wcstring *out_err,
\param prefix the prefix string to prepend to each error message written to the \c out buffer const wchar_t *prefix);
*/
void get_backtrace(const wcstring &src, const parse_error_list_t &errors, wcstring *output) const;
/** /// Tell the parser that the specified function may not be run if not inside of a conditional
Detect errors in the specified string when parsed as an argument list. Returns true if an error occurred. /// block. This is to remove some possibilities of infinite recursion.
*/
bool detect_errors_in_argument_list(const wcstring &arg_list_src, wcstring *out_err, const wchar_t *prefix);
/**
Tell the parser that the specified function may not be run if not
inside of a conditional block. This is to remove some possibilities
of infinite recursion.
*/
void forbid_function(const wcstring &function); void forbid_function(const wcstring &function);
/** /// Undo last call to parser_forbid_function().
Undo last call to parser_forbid_function().
*/
void allow_function(); void allow_function();
/** /// Output profiling data to the given filename.
Output profiling data to the given filename
*/
void emit_profiling(const char *path) const; void emit_profiling(const char *path) const;
/** /// Returns the file currently evaluated by the parser. This can be different than
Returns the file currently evaluated by the parser. This can be /// reader_current_filename, e.g. if we are evaulating a function defined in a different file
different than reader_current_filename, e.g. if we are evaulating a /// than the one curently read.
function defined in a different file than the one curently read.
*/
const wchar_t *current_filename() const; const wchar_t *current_filename() const;
/** /// Return a string representing the current stack trace.
Return a string representing the current stack trace
*/
wcstring stack_trace() const; wcstring stack_trace() const;
}; };

View file

@ -1,56 +1,22 @@
/** \file parser_keywords.c // Functions having to do with parser keywords, like testing if a function is a block command.
Functions having to do with parser keywords, like testing if a function is a block command.
*/
#include "fallback.h" // IWYU pragma: keep
#include "common.h"
#include "parser_keywords.h" #include "parser_keywords.h"
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
bool parser_keywords_skip_arguments(const wcstring &cmd) bool parser_keywords_skip_arguments(const wcstring &cmd) {
{ return contains(cmd, L"else", L"begin");
return contains(cmd,
L"else",
L"begin");
} }
bool parser_keywords_is_subcommand(const wcstring &cmd) {
bool parser_keywords_is_subcommand(const wcstring &cmd)
{
return parser_keywords_skip_arguments(cmd) || return parser_keywords_skip_arguments(cmd) ||
contains(cmd, contains(cmd, L"command", L"builtin", L"while", L"exec", L"if", L"and", L"or", L"not");
L"command",
L"builtin",
L"while",
L"exec",
L"if",
L"and",
L"or",
L"not");
} }
bool parser_keywords_is_block(const wcstring &word) bool parser_keywords_is_block(const wcstring &word) {
{ return contains(word, L"for", L"while", L"if", L"function", L"switch", L"begin");
return contains(word,
L"for",
L"while",
L"if",
L"function",
L"switch",
L"begin");
} }
bool parser_keywords_is_reserved(const wcstring &word) bool parser_keywords_is_reserved(const wcstring &word) {
{ return parser_keywords_is_block(word) || parser_keywords_is_subcommand(word) ||
return parser_keywords_is_block(word) || contains(word, L"end", L"case", L"else", L"return", L"continue", L"break");
parser_keywords_is_subcommand(word) ||
contains(word,
L"end",
L"case",
L"else",
L"return",
L"continue",
L"break");
} }

View file

@ -1,7 +1,4 @@
/** \file parser_keywords.h // Functions having to do with parser keywords, like testing if a function is a block command.
Functions having to do with parser keywords, like testing if a function is a block command.
*/
#ifndef FISH_PARSER_KEYWORD_H #ifndef FISH_PARSER_KEYWORD_H
#define FISH_PARSER_KEYWORD_H #define FISH_PARSER_KEYWORD_H
@ -9,38 +6,27 @@ Functions having to do with parser keywords, like testing if a function is a blo
#include "common.h" #include "common.h"
/** /// Tests if the specified commands parameters should be interpreted as another command, which will
Tests if the specified commands parameters should be interpreted as another command, which will be true if the command is either 'command', 'exec', 'if', 'while', or 'builtin'. This does not handle "else if" which is more complicated. /// be true if the command is either 'command', 'exec', 'if', 'while', or 'builtin'. This does not
/// handle "else if" which is more complicated.
\param cmd The command name to test ///
\return 1 of the command parameter is a command, 0 otherwise /// \param cmd The command name to test
*/ /// \return 1 of the command parameter is a command, 0 otherwise
bool parser_keywords_is_subcommand(const wcstring &cmd); bool parser_keywords_is_subcommand(const wcstring &cmd);
/** /// Tests if the specified command is a reserved word, i.e. if it is the name of one of the builtin
Tests if the specified command is a reserved word, i.e. if it is /// functions that change the block or command scope, like 'for', 'end' or 'command' or 'exec'.
the name of one of the builtin functions that change the block or /// These functions may not be overloaded, so their names are reserved.
command scope, like 'for', 'end' or 'command' or 'exec'. These ///
functions may not be overloaded, so their names are reserved. /// \param word The command name to test
/// \return 1 of the command parameter is a command, 0 otherwise
\param word The command name to test
\return 1 of the command parameter is a command, 0 otherwise
*/
bool parser_keywords_is_reserved(const wcstring &word); bool parser_keywords_is_reserved(const wcstring &word);
/** /// Test if the specified string is command that opens a new block.
Test if the specified string is command that opens a new block
*/
bool parser_keywords_is_block(const wcstring &word); bool parser_keywords_is_block(const wcstring &word);
/** /// Check if the specified command is one of the builtins that cannot have arguments, any followin
Check if the specified command is one of the builtins that cannot /// argument is interpreted as a new command.
have arguments, any followin argument is interpreted as a new
command
*/
bool parser_keywords_skip_arguments(const wcstring &cmd); bool parser_keywords_skip_arguments(const wcstring &cmd);
#endif #endif