Commit Graph

69 Commits

Author SHA1 Message Date
ridiculousfish
71a8eb0aa4 parsed_source_t to hold an ast directly instead of through unique_ptr
We have untangled the dependency loop and so now parsed_source_t no longer
requires indirection.
2020-07-07 16:16:45 -07:00
ridiculousfish
5308223212 Migrate next_parse_token into token_stream_t
Cleaning up parse_tree.cpp with an eye to remove it.
2020-07-07 14:01:01 -07:00
ridiculousfish
72e35af381 Remove preceding_escaped_nl
It's no longer necessary for fish_indent
2020-07-07 13:48:35 -07:00
ridiculousfish
0c22f67bde Remove the old parser bits
Now that everything has been migrated to the new AST, remove as much of
the parse_tree bits as possible
2020-07-04 14:58:05 -07:00
ridiculousfish
3534c07584 Adopt the new AST in parse_execution
parse_execution is what turns a parsed tree into jobs, etc. Switch it from
parse_tree to the new AST.
2020-07-04 14:58:05 -07:00
ridiculousfish
202fdfa54a Adopt the new AST in parse_util_detect_errors
This switches parse_util_detect_errors from parsing with parse_tree to
the new ast.
2020-07-04 14:58:05 -07:00
ridiculousfish
4d4455007d Introduce a new fish ast
This is the first commit of a series intended to replace the existing
"parse tree" machinery. It adds a new abstract syntax tree and uses a more
normal recursive descent parser.

Initially there are no users of the new ast. The following commits will
replace parse_tree -> ast for all usages.
2020-07-04 14:58:02 -07:00
ridiculousfish
45c9e3b0f1 parsed_source_ref to always make a job_list
Removed an unnecessary param in preparation for more changes.
2020-07-04 14:51:15 -07:00
ridiculousfish
269f907f2f Use inline ivar initialization in parse_node_t 2020-06-09 15:16:31 -07:00
ridiculousfish
19293ec2d6 Make parse_keyword_t an enum class 2020-06-09 15:13:02 -07:00
Johannes Altmanninger
ebde9a6a44 move variable_assignment_equal_pos to tokenizer
we'll need it for tok_command
2020-02-24 00:14:39 +01:00
Johannes Altmanninger
f36705bb66 Fix error messages for "and" and "or" after pipe
Fixes #6347
2019-11-26 14:03:53 +01:00
Rosen Penev
5ca80a61e3 [clang-tidy] Fix inconsistent declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
Johannes Altmanninger
7d5b44e828 Support FOO=bar syntax for passing variables to individual commands
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:

a=1 b=$a echo $b        # outputs 1

Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping).  Array indexing
(PATH[1]=/bin ls $PATH) is *not* yet supported, but can be added fairly
easily.

The right hand side may be any valid string token, like a command
substitution, or a brace expansion.

Since `a=* foo` is equivalent to `begin set -lx a *; foo; end`,
the assignment, like `set`, uses nullglob behavior, e.g. below command
can safely be used to check if a directory is empty.

x=/nothing/{,.}* test (count $x) -eq 0

Generic file completion is done after the equal sign, so for example
pressing tab after something like `HOME=/` completes files in the
root directory
Subcommand completion works, so something like
`GIT_DIR=repo.git and command git ` correctly calls git completions
(but the git completion does not use the variable as of now).

The variable assignment is highlighted like an argument.

Closes #6048
2019-11-25 09:20:51 +01:00
Johannes Altmanninger
6fb7f9b6b8 Fix completion for builtins (with subcommands)
Presently the completion engine ignores builtins that are part of the
fish syntax. This can be a problem when completing a string that was
based on the output of `commandline -p`.  This changes completions to
treat these builtins like any other command.

This also disables generic (filename) completion inside comments and
after strings that do not tokenize.

Additionally, comments are stripped off the output of `commandline -p`.

Fixes #5415
Fixes #2705
2019-11-04 16:44:51 +01:00
ridiculousfish
151e75d141 Autosuggestions to validate the first command, not the last command
When considering an autosuggestion from history, we attempt to validate the
command to ensure that we don't suggest invalid (e.g. path-dependent)
commands. Prior to this fix, we would validate the last command in the
command line (e.g. in `cd /bin && ./stuff` we would validate "./stuff".
This doesn't really make sense; we should be validating the first command
because it has the potential to change the PWD. Switch to validating the
first command.

Also remove some helper functions that became dead through this change.
2019-11-02 13:40:31 -07:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
dd007c29f4 Revert "parser: try to avoid some strings being copied"
This reverts commit 7a74198aa3.

Believe it or not this commit actually increased copying. When accepting
a value you know you're going to take ownership of, just accept it by
value; then temporaries can invoke the move ctor and blah blah blah.

We really need a lightweight refcounted pass-by-value string to make this
less error prone.
2019-04-01 20:22:02 -07:00
Aaron Gyes
7a74198aa3 parser: try to avoid some strings being copied 2019-03-23 12:34:48 -07:00
ridiculousfish
6f57fef8f8 Teach the tokenizer to report escaped newlines
Add fields and flags so that escaped newlines can be reported, for the
benefit of fish_indent.
2018-05-07 21:39:30 -07:00
ridiculousfish
f83742d579 Highlight && and || as operators
This also switches 'and' and 'or' to operators as well.
2018-03-05 13:51:05 -08:00
ridiculousfish
fd2a0dffa9 Reflect newlines after pipes in fish grammar
The previous attempt to support newlines after pipes changed the lexer to
swallow newlines after encountering a pipe. This has two problems that are
difficult to fix:

1. comments cannot be placed after the pipe
2. fish_indent won't know about the newlines, so it will erase them

Address these problems by removing the lexer behavior, and replacing it
with a new parser symbol "optional_newlines" allowing the newlines to be
reflected directly in the fish grammar.
2018-02-18 14:44:08 -08:00
ridiculousfish
04162b05ea Remove the giant 'Fish grammar' comment
The fish grammar is now captured more precisely in parse_grammar.h
2018-01-20 14:09:40 -08:00
ridiculousfish
094e853a20 Migrate tnode_t into new header tnode.h 2018-01-20 12:15:28 -08:00
ridiculousfish
1c2943bd8b Make statement_is_in_pipeline a free typesafe function 2018-01-20 11:45:43 -08:00
ridiculousfish
194f7f34d9 Eliminate parse_node_tree::find_nodes 2018-01-20 11:45:43 -08:00
ridiculousfish
242512f0df Migrate argument_list_is_root out of parse_node_tree_t 2018-01-20 11:45:43 -08:00
ridiculousfish
c1b60fa8e1 Remove header_node_for_block_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
d7c28c9316 Eliminate job_should_be_backgrounded 2018-01-20 11:45:43 -08:00
ridiculousfish
3e7e92dfff Remove specific_statements_for_job 2018-01-20 11:45:43 -08:00
ridiculousfish
05e8cf13f7 Eliminate parse_execution_context_t::get_child 2018-01-20 11:45:43 -08:00
ridiculousfish
fa0f552fe9 Convert populate_block_process to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
2bf96493fc Continued adoption of tnode in parse_execution.cpp 2018-01-20 11:45:43 -08:00
ridiculousfish
298db6e11a Convert populate_plain_process to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
8a14a4a5ff Continued adoption of tnode_t in parse_execution
Migrate boolean statements
2018-01-20 11:45:43 -08:00
ridiculousfish
4768c42f5d Early adoption of tnode_t in parse_execution.cpp 2018-01-20 11:45:40 -08:00
ridiculousfish
6f4db9f8ad Add type safety to tnode_t::try_get_child
Detect when no options in an alternation type match the requested type,
and ensure such cases do not compile.
2018-01-20 11:31:40 -08:00
ridiculousfish
f0f56a6910 Teach decoration_for_plain_statement about tnode, rename it get_decoration 2018-01-20 11:31:40 -08:00
ridiculousfish
d4f9fcc7c7 Adopt tnode_t in detect_errors_in_backgrounded_job 2018-01-20 11:31:40 -08:00
ridiculousfish
539e9bf970 Continued adoption of tnode_t in highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
18a120d00e Migrate command_for_plain_statement to tnode_t 2018-01-20 11:31:40 -08:00
ridiculousfish
f16ae9348f Continued adoption of tnode_t in complete.cpp and highlight.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
baa0c73d81 Adopt tnode_t in autosuggest_parse_command() 2018-01-20 11:31:40 -08:00
ridiculousfish
f69055b5e9 Adopt tnode_t in parse_util_detect_errors 2018-01-20 11:31:40 -08:00
ridiculousfish
4d68877f51 tnode_t adoption of find_nodes 2018-01-20 11:31:40 -08:00
ridiculousfish
618996a166 Some adopton of tnode_t in complete.cpp 2018-01-20 11:31:40 -08:00
ridiculousfish
cfe355554c Adopt tnode in reader_expand_abbreviation_in_command 2018-01-20 11:31:40 -08:00
ridiculousfish
3d4dd4abef Introduce tnode 2018-01-20 11:31:40 -08:00
ridiculousfish
aa22c744d2 Mark parsed_source_ref_t as storing a const pointer 2017-12-22 15:44:14 -08:00
ridiculousfish
a99eecfad8 Wrap up source code and a parse tree into a new type parsed_source_ref_t
This will make it unnecessary to carry around the parse tree and source
separately, and enable some simplifications.
2017-12-22 14:40:15 -08:00