1
1
mirror of https://github.com/wader/fq.git synced 2024-12-26 23:15:04 +03:00
fq/pkg/interp/internal.jq

62 lines
1.8 KiB
Plaintext
Raw Normal View History

2021-08-14 20:50:17 +03:00
def print: stdout;
def println: ., "\n" | stdout;
def debug:
( ((["DEBUG", .] | tojson), "\n" | stderr)
, .
);
def debug(f): . as $c | f | debug | $c;
2021-08-14 20:50:17 +03:00
2020-06-08 03:29:51 +03:00
# eval f and finally eval fin even on empty or error
2021-08-19 19:11:37 +03:00
def _finally(f; fin):
2020-06-08 03:29:51 +03:00
( try f // (fin | empty)
catch (fin as $_ | error)
| fin as $_
| .
);
2021-08-19 19:11:37 +03:00
def _repeat_break(f):
try repeat(f)
catch
if . == "break" then empty
else error
end;
2021-08-19 19:11:37 +03:00
2021-08-14 20:50:17 +03:00
def _error_str: "error: \(.)";
def _errorln: ., "\n" | stderr;
2020-06-08 03:29:51 +03:00
def _global_var($k): _global_state[$k];
def _global_var($k; f): _global_state(_global_state | .[$k] |= f) | .[$k];
2020-06-08 03:29:51 +03:00
2021-08-14 20:50:17 +03:00
def _include_paths: _global_var("include_paths");
def _include_paths(f): _global_var("include_paths"; f);
2020-06-08 03:29:51 +03:00
def _default_options: _global_var("default_options");
def _default_options(f): _global_var("default_options"; f);
def _options_stack: _global_var("options_stack");
def _options_stack(f): _global_var("options_stack"; f);
def _cli_last_expr_error: _global_var("cli_last_expr_error");
def _cli_last_expr_error(f): _global_var("cli_last_expr_error"; f);
def _input_filename: _global_var("input_filename");
def _input_filename(f): _global_var("input_filename"; f);
2021-08-14 20:50:17 +03:00
def _input_filenames: _global_var("input_filenames");
def _input_filenames(f): _global_var("input_filenames"; f);
def _input_strings: _global_var("input_strings");
def _input_strings(f): _global_var("input_strings"; f);
def _input_strings_lines: _global_var("input_strings_lines");
def _input_strings_lines(f): _global_var("input_strings_lines"; f);
2020-06-08 03:29:51 +03:00
def _input_io_errors: _global_var("input_io_errors");
def _input_io_errors(f): _global_var("input_io_errors"; f);
def _input_decode_errors: _global_var("input_decode_errors");
def _input_decode_errors(f): _global_var("input_decode_errors"; f);
2021-08-15 18:11:34 +03:00
def _variables: _global_var("variables");
def _variables(f): _global_var("variables"; f);