mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Rename expression.h to parse_tree.h and parse_exec.h
This commit is contained in:
parent
0a02e0db4b
commit
048f08080d
9 changed files with 63 additions and 77 deletions
|
@ -95,7 +95,7 @@ FISH_OBJS := function.o builtin.o complete.o env.o exec.o expand.o \
|
|||
env_universal.o env_universal_common.o input_common.o event.o \
|
||||
signal.o io.o parse_util.o common.o screen.o path.o autoload.o \
|
||||
parser_keywords.o iothread.o color.o postfork.o \
|
||||
builtin_test.o expression.o
|
||||
builtin_test.o parse_tree.o parse_exec.o
|
||||
|
||||
FISH_INDENT_OBJS := fish_indent.o print_help.o common.o \
|
||||
parser_keywords.o wutil.o tokenizer.o
|
||||
|
|
|
@ -72,10 +72,10 @@
|
|||
D07D266D15E33B86009E43F6 /* functions in Copy Files */ = {isa = PBXBuildFile; fileRef = D025C02815D1FEA100B9DB63 /* functions */; };
|
||||
D07D266E15E33B86009E43F6 /* tools in Copy Files */ = {isa = PBXBuildFile; fileRef = D025C02915D1FEA100B9DB63 /* tools */; };
|
||||
D07D267215E34171009E43F6 /* config.fish in Copy Files */ = {isa = PBXBuildFile; fileRef = D0CBD580159EE48F0024809C /* config.fish */; };
|
||||
D07FEA311751E6AF003066C3 /* expression.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D07FEA2F1751E6AF003066C3 /* expression.cpp */; };
|
||||
D0879AC816BF9AAB00E98E56 /* fish_term_icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = D0879AC616BF9A1A00E98E56 /* fish_term_icon.icns */; };
|
||||
D0A564FE168D23D800AF6161 /* man in CopyFiles */ = {isa = PBXBuildFile; fileRef = D0A564F1168D0BAB00AF6161 /* man */; };
|
||||
D0A56501168D258300AF6161 /* man in Copy Files */ = {isa = PBXBuildFile; fileRef = D0A564F1168D0BAB00AF6161 /* man */; };
|
||||
D0C52F371765284C00BFAB82 /* parse_tree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0C52F351765284C00BFAB82 /* parse_tree.cpp */; };
|
||||
D0CBD587159EF0E10024809C /* launch_fish.scpt in Resources */ = {isa = PBXBuildFile; fileRef = D0CBD586159EF0E10024809C /* launch_fish.scpt */; };
|
||||
D0D02A67159837AD008E62BD /* complete.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0A0853713B3ACEE0099B651 /* complete.cpp */; };
|
||||
D0D02A69159837B2008E62BD /* env.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0A0853A13B3ACEE0099B651 /* env.cpp */; };
|
||||
|
@ -337,8 +337,6 @@
|
|||
D03EE83814DF88B200FC7150 /* lru.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lru.h; sourceTree = "<group>"; };
|
||||
D07B247215BCC15700D4ADB4 /* add-shell */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "add-shell"; path = "build_tools/osx_package_scripts/add-shell"; sourceTree = "<group>"; };
|
||||
D07B247515BCC4BE00D4ADB4 /* install.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = install.sh; path = osx/install.sh; sourceTree = "<group>"; };
|
||||
D07FEA2F1751E6AF003066C3 /* expression.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = expression.cpp; sourceTree = "<group>"; };
|
||||
D07FEA301751E6AF003066C3 /* expression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = expression.h; sourceTree = "<group>"; };
|
||||
D0879AC616BF9A1A00E98E56 /* fish_term_icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = fish_term_icon.icns; path = osx/fish_term_icon.icns; sourceTree = "<group>"; };
|
||||
D09B1C1914FC7B5B00F91077 /* postfork.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = postfork.cpp; sourceTree = "<group>"; };
|
||||
D09B1C1A14FC7B5B00F91077 /* postfork.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = postfork.h; sourceTree = "<group>"; };
|
||||
|
@ -444,6 +442,10 @@
|
|||
D0B6B0FE14E88BA400AD6C10 /* color.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = color.cpp; sourceTree = "<group>"; };
|
||||
D0B6B0FF14E88BA400AD6C10 /* color.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = color.h; sourceTree = "<group>"; };
|
||||
D0C4FD9415A7D7EE00212EF1 /* config.fish */ = {isa = PBXFileReference; lastKnownFileType = text; name = config.fish; path = etc/config.fish; sourceTree = "<group>"; };
|
||||
D0C52F331765281F00BFAB82 /* parse_exec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_exec.cpp; sourceTree = "<group>"; };
|
||||
D0C52F341765281F00BFAB82 /* parse_exec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse_exec.h; sourceTree = "<group>"; };
|
||||
D0C52F351765284C00BFAB82 /* parse_tree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_tree.cpp; sourceTree = "<group>"; };
|
||||
D0C52F361765284C00BFAB82 /* parse_tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse_tree.h; sourceTree = "<group>"; };
|
||||
D0C6FCC914CFA4B0004CE8AD /* autoload.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = autoload.cpp; sourceTree = "<group>"; };
|
||||
D0C6FCCB14CFA4B7004CE8AD /* autoload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = autoload.h; sourceTree = "<group>"; };
|
||||
D0C861EA16CC7054003B5A04 /* builtin_set_color.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = builtin_set_color.cpp; sourceTree = "<group>"; };
|
||||
|
@ -585,8 +587,10 @@
|
|||
D0A0853C13B3ACEE0099B651 /* exec.cpp */,
|
||||
D0A0850C13B3ACEE0099B651 /* expand.h */,
|
||||
D0A0853D13B3ACEE0099B651 /* expand.cpp */,
|
||||
D07FEA301751E6AF003066C3 /* expression.h */,
|
||||
D07FEA2F1751E6AF003066C3 /* expression.cpp */,
|
||||
D0C52F361765284C00BFAB82 /* parse_tree.h */,
|
||||
D0C52F351765284C00BFAB82 /* parse_tree.cpp */,
|
||||
D0C52F341765281F00BFAB82 /* parse_exec.h */,
|
||||
D0C52F331765281F00BFAB82 /* parse_exec.cpp */,
|
||||
D0A0850D13B3ACEE0099B651 /* fallback.h */,
|
||||
D0A0853E13B3ACEE0099B651 /* fallback.cpp */,
|
||||
D0A0850E13B3ACEE0099B651 /* function.h */,
|
||||
|
@ -1107,7 +1111,7 @@
|
|||
D0D02A7A15983916008E62BD /* env_universal.cpp in Sources */,
|
||||
D0D02A7B15983928008E62BD /* env_universal_common.cpp in Sources */,
|
||||
D0D02A89159839DF008E62BD /* fish.cpp in Sources */,
|
||||
D07FEA311751E6AF003066C3 /* expression.cpp in Sources */,
|
||||
D0C52F371765284C00BFAB82 /* parse_tree.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
#include "postfork.h"
|
||||
#include "signal.h"
|
||||
#include "highlight.h"
|
||||
#include "expression.h"
|
||||
#include "parse_tree.h"
|
||||
#include "parse_exec.h"
|
||||
|
||||
/**
|
||||
The number of tests to run
|
||||
|
|
1
parse_exec.cpp
Normal file
1
parse_exec.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "parse_exec.h"
|
11
parse_exec.h
Normal file
11
parse_exec.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
/**\file parse_exec.h
|
||||
|
||||
Programmatic execution of a parse tree
|
||||
*/
|
||||
|
||||
#ifndef FISH_PARSE_TREE_H
|
||||
#define FISH_PARSE_TREE_H
|
||||
|
||||
#include "parse_tree.h"
|
||||
|
||||
#endif
|
|
@ -2,47 +2,9 @@
|
|||
#include "tokenizer.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
/* Fish grammar:
|
||||
|
||||
# A statement_list is a list of statements, separated by semicolons or newlines
|
||||
|
||||
statement_list = <empty> |
|
||||
statement statement_list
|
||||
|
||||
# A statement is a normal job, or an if / while / and etc.
|
||||
|
||||
statement = boolean_statement | block_statement | decorated_statement
|
||||
|
||||
# A block is a conditional, loop, or begin/end
|
||||
|
||||
block_statement = block_header statement_list END arguments_or_redirections_list
|
||||
block_header = if_header | for_header | while_header | function_header | begin_header
|
||||
if_header = IF statement
|
||||
for_header = FOR var_name IN arguments_or_redirections_list STATEMENT_TERMINATOR
|
||||
while_header = WHILE statement
|
||||
begin_header = BEGIN STATEMENT_TERMINATOR
|
||||
function_header = FUNCTION arguments_or_redirections_list STATEMENT_TERMINATOR
|
||||
|
||||
# A boolean statement is AND or OR or NOT
|
||||
|
||||
boolean_statement = AND statement | OR statement | NOT statement
|
||||
|
||||
# A decorated_statement is a command with a list of arguments_or_redirections, possibly with "builtin" or "command"
|
||||
|
||||
decorated_statement = COMMAND plain_statement | BUILTIN plain_statement | plain_statement
|
||||
plain_statement = command arguments_or_redirections_list terminator
|
||||
|
||||
arguments_or_redirections_list = <empty> |
|
||||
argument_or_redirection arguments_or_redirections_list
|
||||
argument_or_redirection = redirection | <TOK_STRING>
|
||||
redirection = <TOK_REDIRECTION>
|
||||
|
||||
terminator = <TOK_END> | <TOK_BACKGROUND>
|
||||
|
||||
*/
|
||||
|
||||
struct parse_node_t;
|
||||
typedef size_t node_offset_t;
|
||||
typedef std::vector<parse_node_t> parse_node_tree_t;
|
||||
|
||||
#define PARSE_ASSERT(a) assert(a)
|
||||
|
||||
|
@ -208,7 +170,7 @@ class parse_node_t
|
|||
}
|
||||
};
|
||||
|
||||
static void dump_tree_recursive(const std::vector<parse_node_t> &nodes, const wcstring &src, size_t start, size_t indent, wcstring *result, size_t *line)
|
||||
static void dump_tree_recursive(const parse_node_tree_t &nodes, const wcstring &src, size_t start, size_t indent, wcstring *result, size_t *line)
|
||||
{
|
||||
assert(start < nodes.size());
|
||||
const parse_node_t &node = nodes.at(start);
|
||||
|
@ -234,7 +196,7 @@ static void dump_tree_recursive(const std::vector<parse_node_t> &nodes, const wc
|
|||
}
|
||||
}
|
||||
|
||||
static wcstring dump_tree(const std::vector<parse_node_t> &nodes, const wcstring &src)
|
||||
static wcstring dump_tree(const parse_node_tree_t &nodes, const wcstring &src)
|
||||
{
|
||||
if (nodes.empty())
|
||||
return L"(empty!)";
|
||||
|
@ -245,7 +207,6 @@ static wcstring dump_tree(const std::vector<parse_node_t> &nodes, const wcstring
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct parse_stack_element_t
|
||||
{
|
||||
enum parse_token_type_t type;
|
||||
|
@ -261,12 +222,36 @@ struct parse_stack_element_t
|
|||
}
|
||||
};
|
||||
|
||||
class parse_execution_context_t
|
||||
{
|
||||
wcstring src;
|
||||
const parse_node_tree_t nodes;
|
||||
size_t node_idx;
|
||||
|
||||
public:
|
||||
parse_execution_context_t(const parse_node_tree_t &n, const wcstring &s) : src(s), nodes(n), node_idx(0)
|
||||
{
|
||||
}
|
||||
|
||||
wcstring simulate(void);
|
||||
};
|
||||
|
||||
wcstring parse_execution_context_t::simulate()
|
||||
{
|
||||
if (nodes.empty())
|
||||
return L"(empty!");
|
||||
|
||||
PARSE_ASSERT(node_idx < nodes.size());
|
||||
PARSE_ASSERT(nodes.at(node_idx).type == symbol_statement_list);
|
||||
|
||||
}
|
||||
|
||||
class parse_ll_t
|
||||
{
|
||||
friend class parse_t;
|
||||
|
||||
std::vector<parse_stack_element_t> symbol_stack; // LL parser stack
|
||||
std::vector<parse_node_t> nodes;
|
||||
parse_node_tree_t nodes;
|
||||
bool errored;
|
||||
|
||||
// Constructor
|
||||
|
@ -642,7 +627,6 @@ void parse_ll_t::accept_token(parse_token_t token)
|
|||
bool consumed = false;
|
||||
while (! consumed && ! this->errored)
|
||||
{
|
||||
fprintf(stderr, "Top type %ls\n", token_type_description(stack_top_type()).c_str());
|
||||
if (top_node_match_token(token))
|
||||
{
|
||||
consumed = true;
|
||||
|
@ -785,5 +769,5 @@ void parse_t::parse(const wcstring &str)
|
|||
}
|
||||
wcstring result = dump_tree(this->parser->nodes, str);
|
||||
fprintf(stderr, "Tree (%ld nodes):\n%ls", this->parser->nodes.size(), result.c_str());
|
||||
fprintf(stderr, "node size %ld", sizeof(parse_node_t));
|
||||
fprintf(stderr, "node size %ld\n", sizeof(parse_node_t));
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
/**\file expression.h
|
||||
/**\file parse_tree.h
|
||||
|
||||
Programmatic representation of fish code.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef FISH_EXPRESSION_H
|
||||
#define FISH_EXPRESSION_H
|
||||
#ifndef FISH_PARSE_TREE_H
|
||||
#define FISH_PARSE_TREE_H
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
|
@ -65,17 +64,6 @@ class parse_t
|
|||
|
||||
terminator = <TOK_END> | <TOK_BACKGROUND>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* fish Shift-Reduce grammar:
|
||||
|
||||
|
||||
IF <- if_statement
|
||||
FOR <- for_statement
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
|
@ -722,7 +722,7 @@ void parser_t::print_errors_stderr()
|
|||
|
||||
}
|
||||
|
||||
int parser_t::eval_args(const wchar_t *line, std::vector<completion_t> &args)
|
||||
void parser_t::eval_args(const wchar_t *line, std::vector<completion_t> &args)
|
||||
{
|
||||
|
||||
expand_flags_t eflags = 0;
|
||||
|
@ -731,10 +731,9 @@ int parser_t::eval_args(const wchar_t *line, std::vector<completion_t> &args)
|
|||
if (this->parser_type != PARSER_TYPE_GENERAL)
|
||||
eflags |= EXPAND_SKIP_CMDSUBST;
|
||||
|
||||
int do_loop=1;
|
||||
bool do_loop=1;
|
||||
|
||||
CHECK(line, 1);
|
||||
// CHECK( args, 1 );
|
||||
if (! line) return;
|
||||
|
||||
// PCA we need to suppress calling proc_push_interactive off of the main thread. I'm not sure exactly what it does.
|
||||
if (this->parser_type == PARSER_TYPE_GENERAL)
|
||||
|
@ -803,8 +802,6 @@ int parser_t::eval_args(const wchar_t *line, std::vector<completion_t> &args)
|
|||
|
||||
if (this->parser_type == PARSER_TYPE_GENERAL)
|
||||
proc_pop_interactive();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void parser_t::stack_trace(block_t *b, wcstring &buff)
|
||||
|
|
4
parser.h
4
parser.h
|
@ -396,7 +396,7 @@ public:
|
|||
|
||||
/**
|
||||
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.
|
||||
The output is inserted into output.
|
||||
|
||||
\param line Line to evaluate
|
||||
\param output List to insert output to
|
||||
|
@ -405,7 +405,7 @@ public:
|
|||
\param line Line to evaluate
|
||||
\param output List to insert output to
|
||||
*/
|
||||
int eval_args(const wchar_t *line, std::vector<completion_t> &output);
|
||||
void eval_args(const wchar_t *line, std::vector<completion_t> &output);
|
||||
|
||||
/**
|
||||
Sets the current evaluation error. This function should only be used by libraries that are called by
|
||||
|
|
Loading…
Reference in a new issue