#include <wchar.h>
#include "proc.h"
#include "util.h"
#include "parser.h"
#include "event.h"
Go to the source code of this file.
Data Structures | |
| struct | event_block |
| event_block_t represents a block on events of the specified type More... | |
| struct | block |
| block_t represents a block of commands. More... | |
Defines | |
| #define | PARSER_TEST_ERROR 1 |
| #define | PARSER_TEST_INCOMPLETE 2 |
Typedefs | |
| typedef struct event_block | event_block_t |
| event_block_t represents a block on events of the specified type | |
| typedef struct block | block_t |
| block_t represents a block of commands. | |
Enumerations | |
| enum | block_type { WHILE, FOR, IF, FUNCTION_DEF, FUNCTION_CALL, FUNCTION_CALL_NO_SHADOW, SWITCH, FAKE, SUBST, TOP, BEGIN, SOURCE, EVENT, BREAKPOINT } |
| Types of blocks. More... | |
| enum | loop_status { LOOP_NORMAL, LOOP_BREAK, LOOP_CONTINUE } |
| Possible states for a loop. More... | |
| enum | while_status { WHILE_TEST_FIRST, WHILE_TEST_AGAIN, WHILE_TESTED } |
| Possible states for a while block. More... | |
| enum | parser_error { NO_ERR = 0, SYNTAX_ERROR, EVAL_ERROR, CMDSUBST_ERROR } |
| Errors that can be generated by the parser. More... | |
Functions | |
| int | eval (const wchar_t *cmd, io_data_t *io, int block_type) |
| Evaluate the expressions contained in cmd. | |
| int | eval_args (const wchar_t *line, array_list_t *output) |
| Evaluate line as a list of parameters, i.e. | |
| void | error (int ec, int p, const wchar_t *str,...) |
| Sets the current evaluation error. | |
| wchar_t * | parser_current_line () |
| Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'. | |
| int | parser_get_lineno () |
| Returns the current line number. | |
| int | parser_get_pos () |
| Returns the current position in the latest string of the tokenizer. | |
| int | parser_get_job_pos () |
| Returns the position where the current job started in the latest string of the tokenizer. | |
| void | parser_set_pos (int p) |
| Set the current position in the latest string of the tokenizer. | |
| const wchar_t * | parser_get_buffer () |
| Get the string currently parsed. | |
| void | parser_push_block (int type) |
| Create block of specified type. | |
| void | parser_pop_block () |
| Remove the outermost block namespace. | |
| const wchar_t * | parser_get_block_desc (int block) |
| Return a description of the given blocktype. | |
| int | parser_test (const wchar_t *buff, int *block_level, string_buffer_t *out, const wchar_t *prefix) |
| Test if the specified string can be parsed, or if more bytes need to be read first. | |
| int | parser_test_args (const wchar_t *buff, string_buffer_t *out, const wchar_t *prefix) |
| Test if the specified string can be parsed as an argument list, e.g. | |
| void | parser_forbid_function (wchar_t *function) |
| Tell the parser that the specified function may not be run if not inside of a conditional block. | |
| void | parser_allow_function () |
| Undo last call to parser_forbid_function(). | |
| void | parser_init () |
| Initialize static parser data. | |
| void | parser_destroy () |
| Destroy static parser data. | |
| int | parser_is_help (wchar_t *s, int min_match) |
| This function checks if the specified string is a help option. | |
| const wchar_t * | parser_current_filename () |
| Returns the file currently evaluated by the parser. | |
| void | parser_stack_trace (block_t *b, string_buffer_t *buff) |
| Write a stack trace starting at the specified block to the specified string_buffer_t. | |
| int | parser_get_block_type (const wchar_t *cmd) |
| const wchar_t * | parser_get_block_command (int type) |
Variables | |
| block_t * | current_block |
| The current innermost block. | |
| event_block_t * | global_event_block |
| Global event blocks. | |
| io_data_t * | block_io |
| Current block level io redirections. | |
| enum block_type |
Types of blocks.
| WHILE | While loop block. |
| FOR | For loop block. |
| IF | If block. |
| FUNCTION_DEF | Function definition block. |
| FUNCTION_CALL | Function invocation block. |
| FUNCTION_CALL_NO_SHADOW | Function invocation block with no variable shadowing. |
| SWITCH | Switch block. |
| FAKE | Fake block. |
| SUBST | Command substitution scope. |
| TOP | Outermost block. |
| BEGIN | Unconditional block. |
| SOURCE |
Block created by the .
(source) builtin |
| EVENT | Block created on event notifier invocation. |
| BREAKPOINT | Breakpoint block. |
| enum loop_status |
| enum parser_error |
| enum while_status |
Possible states for a while block.
| void error | ( | int | ec, | |
| int | p, | |||
| const wchar_t * | str, | |||
| ... | ||||
| ) |
Sets the current evaluation error.
This function should only be used by libraries that are called by
| ec | The new error code | |
| p | The character offset at which the error occured | |
| str | The printf-style error message filter |
References CHECK, err_pos, error_code, global_context, sb_clear(), sb_halloc(), and sb_vprintf().
| int eval | ( | const wchar_t * | cmd, | |
| io_data_t * | io, | |||
| int | block_type | |||
| ) |
Evaluate the expressions contained in cmd.
| cmd | the string to evaluate | |
| io | io redirections to perform on all started jobs | |
| block_type | The type of block to push on the block stack |
References _, al_destroy(), al_get_count(), al_new(), BLOCK_END_ERR_MSG, bugreport(), builtin_help_get(), CHECK_BLOCK, debug(), error_code, eval_job(), eval_level, EVAL_NULL_ERR_MSG, event_fire(), exit_status(), FATAL_EXIT, INVALID_SCOPE_ERR_MSG, job_reap(), parser_allow_function(), parser_current_line(), parser_get_block_desc(), parser_pop_block(), parser_push_block(), print_errors_stderr(), proc_get_last_status(), sanity_check(), SUBST, tok_destroy(), tok_has_next(), tok_init(), TOP, and block::type.
Referenced by event_fire_internal(), exec_subshell(), input_exec_binding(), internal_exec_helper(), main(), read_init(), read_ni(), reader_run_command(), run_pager(), start_fishd(), and test_parser().
| int eval_args | ( | const wchar_t * | line, | |
| array_list_t * | output | |||
| ) |
Evaluate line as a list of parameters, i.e.
tokenize it and perform parameter expansion and cmdsubst execution on the tokens. The output is inserted into output, and should be freed by the caller.
| line | Line to evaluate | |
| output | List to insert output to |
References CHECK, current_tokenizer_pos, DIE_MEM, err_pos, error, error_code, EXPAND_ERROR, expand_string(), print_errors_stderr(), proc_pop_interactive(), proc_push_interactive(), SYNTAX_ERROR, tmp, tok_destroy(), TOK_END, TOK_ERR_MSG, TOK_ERROR, tok_get_desc(), tok_get_pos(), tok_has_next(), tok_init(), tok_last(), tok_last_type(), tok_next(), TOK_STRING, and UNEXPECTED_TOKEN_ERR_MSG.
Referenced by complete_from_args().
| const wchar_t* parser_current_filename | ( | ) |
Returns the file currently evaluated by the parser.
This can be different than reader_current_filename, e.g. if we are evaulating a function defined in a different file than the one curently read.
References FUNCTION_CALL, block::function_call_name, function_get_definition_file(), block::outer, block::param1, reader_current_filename(), and block::type.
Referenced by builtin_status(), parser_current_line(), and parser_push_block().
| wchar_t* parser_current_line | ( | ) |
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.
Example:
init.fish (line 127): ls|grep pancake
If we are not going to print a stack trace, at least print the line number and filename
References _, buffer::buff, current_tokenizer_pos, function_get_definition_offset(), is_function(), is_interactive, my_wcswidth(), parser_current_filename(), parser_stack_trace(), printed_width(), sb_clear(), sb_init(), sb_printf(), and tok_string().
Referenced by builtin_cd(), builtin_print_help(), eval(), parse_job(), parse_job_argument_list(), print_errors(), and print_errors_stderr().
| void parser_forbid_function | ( | wchar_t * | function | ) |
| const wchar_t* parser_get_block_command | ( | int | type | ) |
| int parser_get_block_type | ( | const wchar_t * | cmd | ) |
References block_lookup_entry::desc, block_lookup_entry::name, and block_lookup_entry::type.
Referenced by parser_test().
| int parser_is_help | ( | wchar_t * | s, | |
| int | min_match | |||
| ) |
This function checks if the specified string is a help option.
| s | the string to test | |
| min_match | is the minimum number of characters that must match in a long style option, i.e. the longest common prefix between --help and any other option. If less than 3, 3 will be assumed. |
Referenced by builtin_run(), parse_job_argument_list(), and parser_test().
| int parser_test | ( | const wchar_t * | buff, | |
| int * | block_level, | |||
| string_buffer_t * | out, | |||
| const wchar_t * | prefix | |||
| ) |
Test if the specified string can be parsed, or if more bytes need to be read first.
The result will have the PARSER_TEST_ERROR bit set if there is a syntax error in the code, and the PARSER_TEST_INCOMPLETE bit set if the code contains unclosed blocks.
| buff | the text buffer to test | |
| block_level | if non-null, the block nesting level will be filled out into this array | |
| out | if non-null, any errors in the command will be filled out into this buffer | |
| prefix | the prefix string to prepend to each error message written to the out buffer |
References BLOCK_END_ERR_MSG, BLOCK_ERR_MSG, BLOCK_MAX_COUNT, BUILTIN_FOR_ERR_COUNT, BUILTIN_FOR_ERR_IN, builtin_help_get(), CHECK, CMD_AND_ERR_MSG, CMD_ERR_MSG, CMD_OR_ERR_MSG, COND_ERR_MSG, contains, current_tokenizer_pos, err(), error, error_code, EXEC_ERR_MSG, expand_is_clean(), expand_one(), EXPAND_SKIP_CMDSUBST, EXPAND_SKIP_VARIABLES, FOR, FUNCTION_DEF, halloc(), halloc_free(), IF, ILLEGAL_CMD_ERR_MSG, INVALID_CASE_ERR_MSG, INVALID_ELSE_ERR_MSG, INVALID_END_ERR_MSG, INVALID_LOOP_ERR_MSG, INVALID_REDIRECTION_ERR_MSG, INVALID_RETURN_ERR_MSG, parser_get_block_command(), parser_get_block_type(), parser_is_help(), parser_is_pipe_forbidden(), parser_keywords_is_block(), parser_keywords_is_subcommand(), parser_keywords_skip_arguments(), parser_test_argument(), print_errors(), sb_printf(), SWITCH, SYNTAX_ERROR, TOK_BACKGROUND, tok_destroy(), TOK_END, TOK_ERR_MSG, TOK_ERROR, tok_get_desc(), tok_get_error(), tok_get_pos(), tok_has_next(), tok_init(), tok_last(), tok_last_type(), tok_next(), TOK_PIPE, TOK_REDIRECT_APPEND, TOK_REDIRECT_FD, TOK_REDIRECT_IN, TOK_REDIRECT_NOCLOB, TOK_REDIRECT_OUT, tok_set_pos(), TOK_STRING, wcsvarname(), and WHILE.
Referenced by builtin_complete(), parser_test_argument(), read_ni(), reader_repaint(), reader_shell_test(), and test_parser().
| int parser_test_args | ( | const wchar_t * | buff, | |
| string_buffer_t * | out, | |||
| const wchar_t * | prefix | |||
| ) |
Test if the specified string can be parsed as an argument list, e.g.
sent to eval_args. The result has the first bit set if the string contains errors, and the second bit is set if the string contains an unclosed block.
References CHECK, current_tokenizer_pos, err(), error, error_code, parser_test_argument(), print_errors(), SYNTAX_ERROR, tok_destroy(), TOK_END, TOK_ERR_MSG, TOK_ERROR, tok_get_desc(), tok_get_pos(), tok_has_next(), tok_init(), tok_last(), tok_last_type(), tok_next(), TOK_STRING, and UNEXPECTED_TOKEN_ERR_MSG.
Referenced by builtin_complete().
1.5.6