mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 21:21:15 -03:00
More work on new parser
This commit is contained in:
90
parse_tree.h
90
parse_tree.h
@@ -12,6 +12,10 @@
|
||||
#include "util.h"
|
||||
#include "common.h"
|
||||
#include "tokenizer.h"
|
||||
#include <vector>
|
||||
|
||||
#define PARSE_ASSERT(a) assert(a)
|
||||
#define PARSER_DIE() assert(0)
|
||||
|
||||
|
||||
class parse_ll_t;
|
||||
@@ -25,6 +29,92 @@ class parse_t
|
||||
void parse(const wcstring &str);
|
||||
};
|
||||
|
||||
class parse_node_t;
|
||||
typedef std::vector<parse_node_t> parse_node_tree_t;
|
||||
typedef size_t node_offset_t;
|
||||
|
||||
|
||||
enum parse_token_type_t
|
||||
{
|
||||
token_type_invalid,
|
||||
|
||||
// Non-terminal tokens
|
||||
symbol_statement_list,
|
||||
symbol_statement,
|
||||
symbol_block_statement,
|
||||
symbol_block_header,
|
||||
symbol_if_header,
|
||||
symbol_for_header,
|
||||
symbol_while_header,
|
||||
symbol_begin_header,
|
||||
symbol_function_header,
|
||||
symbol_boolean_statement,
|
||||
symbol_decorated_statement,
|
||||
symbol_plain_statement,
|
||||
symbol_arguments_or_redirections_list,
|
||||
symbol_argument_or_redirection,
|
||||
|
||||
// Terminal types
|
||||
parse_token_type_string,
|
||||
parse_token_type_pipe,
|
||||
parse_token_type_redirection,
|
||||
parse_token_background,
|
||||
parse_token_type_end,
|
||||
parse_token_type_terminate,
|
||||
|
||||
FIRST_PARSE_TOKEN_TYPE = parse_token_type_string
|
||||
};
|
||||
|
||||
enum parse_keyword_t
|
||||
{
|
||||
parse_keyword_none,
|
||||
parse_keyword_if,
|
||||
parse_keyword_else,
|
||||
parse_keyword_for,
|
||||
parse_keyword_in,
|
||||
parse_keyword_while,
|
||||
parse_keyword_begin,
|
||||
parse_keyword_function,
|
||||
parse_keyword_switch,
|
||||
parse_keyword_end,
|
||||
parse_keyword_and,
|
||||
parse_keyword_or,
|
||||
parse_keyword_not,
|
||||
parse_keyword_command,
|
||||
parse_keyword_builtin
|
||||
};
|
||||
|
||||
/** Base class for nodes of a parse tree */
|
||||
class parse_node_t
|
||||
{
|
||||
public:
|
||||
|
||||
/* Type of the node */
|
||||
enum parse_token_type_t type;
|
||||
|
||||
/* Start in the source code */
|
||||
size_t source_start;
|
||||
|
||||
/* Length of our range in the source code */
|
||||
size_t source_length;
|
||||
|
||||
/* Children */
|
||||
node_offset_t child_start;
|
||||
node_offset_t child_count;
|
||||
|
||||
/* Type-dependent data */
|
||||
uint32_t tag;
|
||||
|
||||
|
||||
/* Description */
|
||||
wcstring describe(void) const;
|
||||
|
||||
/* Constructor */
|
||||
explicit parse_node_t(parse_token_type_t ty) : type(ty), source_start(0), source_length(0), child_start(0), child_count(0), tag(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Fish grammar:
|
||||
|
||||
Reference in New Issue
Block a user