Commit Graph

37 Commits

Author SHA1 Message Date
ridiculousfish
865a4647ae Allow variables in commands
Syntax highlighting for these coming in next commit.

Fixes #154
2018-09-01 12:00:56 -07:00
ridiculousfish
4b079e16e5 Execute the conditions of if and while statements outside of their block
Variables set in if and while conditions are in the enclosing block, not
the if/while statement block. For example:

    if set -l var (somecommand) ; end
    echo $var

will now work as expected.

Fixes #4820. Fixes #1212.
2018-03-31 14:57:24 -07:00
ridiculousfish
357d3b8c6d Rework 'and' and 'or' to be "job decorators"
This promotes "and" and "or" from a type of statement to "job
decorators," as a possible prefix on a job. The point is to rationalize
how they interact with && and ||.

In the new world 'and' and 'or' apply to a entire job conjunction, i.e.
they have "lower precedence." Example:

if [ $age -ge 0 ] && [ $age -le 18 ]
   or [ $age -ge 75 ] && [ $age -le 100 ]
   echo "Child or senior"
end
2018-03-05 13:41:36 -08:00
ridiculousfish
8e9670ccd5 Implement execution of && and ||
This adds support for basic constructs. if and while is not yet
supported.
2018-03-05 12:20:56 -08:00
ridiculousfish
5b5a3f78e1 Eliminate parse_execution_context_t::get_offset
This was used to find the index given a pointer to a node. It's now unused.
2018-02-12 10:56:08 -08:00
ridiculousfish
92d5c28730 Move eval_level into parser_t
This avoids the ping-ponging of eval_level through
parse_execution_context. Simply store the global eval level in the
parser_t.
2018-02-12 10:55:31 -08:00
ridiculousfish
8251d949f1 Switch executing_node_idx to storing a tnode_t
Avoids annoying index<->node conversions.
2018-02-12 10:55:20 -08:00
ridiculousfish
41ba0dfadb Evaluate tnode_t instead of parse_node_t
This concerns block nodes with redirections, like
begin ... end | grep ...
Prior to this fix, we passed in a pointer to the node. Switch to passing
in the tnode and parsed source ref. This improves type safety and better
aligns with the function-node plans.
2018-02-12 10:51:39 -08:00
ridiculousfish
de23ce6ac1 Functions to store nodes
Prior to this fix, functions stored a string representation of their
contents. Switch them to storing a parsed source reference and the
tnode of the contents. This is part of an effort to avoid reparsing
a function's contents every time it executes.
2018-02-12 10:49:22 -08:00
ridiculousfish
852cf183a6 Remove some unused parameters 2018-01-20 14:09:36 -08:00
ridiculousfish
05e8cf13f7 Eliminate parse_execution_context_t::get_child 2018-01-20 11:45:43 -08:00
ridiculousfish
5e4e0dab2c Convert run_job_list to tnode_T 2018-01-20 11:45:43 -08:00
ridiculousfish
4c93cece58 Convert run_1_job to tnode_t 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
7a3d5ddeae Convert run_begin_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
6f99c9a904 Adopt tnode_t in run_function_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
edc3d92eda Adopt tnode in run_while_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
554bef93ba Switch run_switch_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
3981accf05 Adopt tnode_t in run_if_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
ce173e86b5 Adopt tnode_t in run_for_statement 2018-01-20 11:45:43 -08:00
ridiculousfish
b23c6ebcba Migrate run_block_statement to tnode_t 2018-01-20 11:45:43 -08:00
ridiculousfish
cdc0167ba1 Switching symbol_job to use tnode_t in parse_execution.cpp 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
18a120d00e Migrate command_for_plain_statement to tnode_t 2018-01-20 11:31:40 -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
Kurtis Rader
905766fca2 Hoist for loop control var to enclosing scope (#4376)
* Hoist `for` loop control var to enclosing scope

It should be possible to reference the last value assigned to a `for`
loop control var when the loop terminates. This makes it easier to detect
if we broke out of the loop among other things.  This change makes fish
`for` loops behave like most other shells.

Fixes #1935

* Remove redundant line
2017-09-08 21:14:26 -07:00
ridiculousfish
fec83fa975 Eliminate moved_ref
Use real rvalue references instead
2017-01-26 15:43:46 -08:00
Aaron Gyes
fa78a7101c Make IWYU output in lint.cpp less messy
And re-run IWYU, adjust #includes.
2016-06-23 17:26:08 -07:00
Kurtis Rader
ea945cc437 restyle parse_execution module to match project style
Reduces lint errors from 184 to 84 (-54%). Line count from 2139 to 1943 (-9%).

Another step in resolving issue #2902.
2016-05-02 13:00:03 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
ridiculousfish
e3970f9cbb Allow parse_execution_context to take ownership of a parse tree
Introduces a new template moved_ref which is like an rvalue reference.
This allows passing around objects while being explicit that the
receiver may acquire ownership. This will help reduce some allocations.
2016-02-28 00:33:11 -08:00
Andreas Nordal
62b76b26b4 Reinstate failglob behaviour for most commands
Expand globs to zero arguments (nullglob) only for set, for and count.

The warning about failing globs, and setting the accompanying $status,
now happens regardless of mode, interactive or not.

It is assumed that the above commands are the common cases where
nullglob behaviour is desirable.
More importantly, doing this with `set` is a real feature enabler,
since the resulting empty array can be passed on to any command.

The previous behaviour was actually all nullglob (since commit
cab115c8b9), but this was undocumented;
the failglob warning was still printed in interactive mode,
and the documentation was bragging about failglob behaviour.
2016-02-15 13:13:28 -08:00
David Adam
3929e9de0e Merge branch 'master' into iwyu 2015-07-26 10:20:13 +08:00
ridiculousfish
b4f53143b0 Migrate source files into src/ directory
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.

Fixes #1866
2015-07-24 00:59:27 -07:00