Commit 7308a143 authored by Samuel Newbold's avatar Samuel Newbold

Argfunctions are part of prototypes

Also,
 * give an error for the currently unsupported fixed arguments
   (not useful until you can use them to distinguish multi-bodied
   functions and .scopes)
 * handle errors in prototype instantiation in parallel so I don't
   lose functionality in the next step.
parent 3e3e2ec2
......@@ -6,13 +6,13 @@ call stack .source .try_catch_recursive(body)
.signal_handler &{.internal_functions}$ {&&* {.argfunction}}
.mapped_argfunction {&&* {.argfunction}}
&&* {.argfunction}}
.function_all_flags .before_command -- args ... {.nop $args}
.function_all_flags .after_command -- args ... {.nop $args}
.function_all_flags .before_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .after_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .prompt {.echo \$}
.function_all_flags .vars {.internal_vars}
.source /etc/rwshrc-basic
.function_all_flags # -- [ignored ...] {.nop $ignored$}
.function_all_flags fn -- prototype ... {
.function_all_flags # -- [ignored ...] [.{argfunction}] {.nop $ignored$}
.function_all_flags fn -- prototype ... .{argfunction} {
.function_all_flags $prototype$ {.argfunction}}
# set up environment
......@@ -111,6 +111,9 @@ call stack .source .try_catch_recursive(body)
.function_all_flags .file_open_failure -- file stack ... {
echo could not open file $file
echo call stack $stack}
.function_all_flags .fixed_argument -- arg stack ... {
echo $arg : fixed arguments are not supported at this time
echo call stack $stack}
.function_all_flags .flag_in_elipsis -- flag stack ... {
echo found flag $flag while collecting arguments for elipsis
echo call stack $stack$}
......@@ -260,10 +263,10 @@ call stack .source .try_catch_recursive(body)
.function_all_flags ! args ... {
.if $args$ {.throw .false ${.echo ! $args}}
.else {.nop}}
.function_all_flags af -- [argv ...] {.argfunction}
.function_all_flags af -- [argv ...] .{argfunction} {.argfunction}
.function_all_flags c -- text ... {.combine $text$}
.function_all_flags e -- text ... {.echo $text}
.function_all_flags do_while argv ... {
.function_all_flags do_while argv ... .{argfunction} {
.try_catch_recursive .break {
.nop $argv
.try_catch_recursive .continue {.argfunction}
......@@ -272,16 +275,17 @@ call stack .source .try_catch_recursive(body)
.function_all_flags echo-comments cmd ... {
.stepwise $cmd$ {if_only .test_in $1 .nop # #! ## {echo &&&*}}}
.function_all_flags exec -- argv ... {.exec $argv$}
.function_all_flags elif command ... {.else_if $command$ {.argfunction}}
.function_all_flags else {.else {.argfunction}}
.function_all_flags elif command ... .{argfunction} {
.else_if $command$ {.argfunction}}
.function_all_flags else .{argfunction} {.else {.argfunction}}
fn false {.try_catch_recursive .return_code {${whichp false}}}
.function_all_flags fns -- name args ... {
.function_all_flags fns -- name args ... .{argfunction} {
.function_all_flags $name [-*] $args$ {.argfunction}}
.function_all_flags if_only -- args ... {
.function_all_flags if_only -- args ... .{argfunction} {
.if $args$ {.argfunction}; .else {.nop}}
.function_all_flags if_only_not -- args ... {
.function_all_flags if_only_not -- args ... .{argfunction} {
.if $args$ {.nop}; .else {.argfunction}}
fn ntimes n {
fn ntimes n .{argfunction} {
.while test_var_greater n 0 {
.mapped_argfunction {.argfunction}
.var_subtract n 1}}
......@@ -289,14 +293,14 @@ fn ntimes n {
.replace_exception .break $stack$}
.function_all_flags outer_continue stack ... {
.replace_exception .continue $stack$}
.function_all_flags scope_for var vals ... {
.function_all_flags scope_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {.argfunction}}}
.function_all_flags outer_for var vals ... {
.function_all_flags outer_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {
.try_catch_recursive outer_break outer_continue {.argfunction}}}}
.function_all_flags outer_while argv ... {
.function_all_flags outer_while argv ... .{argfunction} {
.while $argv$ {
.try_catch_recursive outer_break outer_continue {.argfunction}}}
.function_all_flags setf var value {
......@@ -307,16 +311,16 @@ fn test -- args ... {
.try_catch_recursive .return_code {${whichp test} $args$}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
fn type [-t] args ... [.{argfunction}] {
.for $args$ {
.try_catch_recursive .function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.type &&&1 {.argfunction}}}}
fn whence command {
fn whence command [.{argfunction}] {
.try_catch_recursive .function_not_found {
.whence_function $command {.argfunction}}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags while_and_one_more argv ... {
.function_all_flags while_and_one_more argv ... .{argfunction} {
.try_catch_recursive .break {
.while $argv$ {.argfunction}
.try_catch_recursive .continue {.argfunction}}}
......@@ -371,24 +375,25 @@ $.echo $nl $nl $nl $nl
$.function_all_flags # [args ...] {.nop $args$}
$.function_all_flags fw {
.function_all_flags f1 name {.argfunction}
$.function_all_flags fw .{argfunction} {
.function_all_flags f1 name .{argfunction} {.argfunction}
.whence_function f1; .echo $nl
f1 f2 {.argfunction}
.whence_function f2; .echo $nl
.rm_executable f1; .rm_executable f2}
$fw {.echo hi $nl; .function_all_flags $name {.argfunction}}
.function_all_flags f1 name {.echo hi $nl; .function_all_flags $name {.argfunction}}
$fw {.echo hi $nl; .function_all_flags $name .{argfunction} {.argfunction}}
.function_all_flags f1 name {.echo hi $nl; .function_all_flags $name .{argfunction} {.argfunction}}
hi
.function_all_flags f2 {.echo hi $nl; .function_all_flags $name {.argfunction}}
.function_all_flags f2 {.echo hi $nl; .function_all_flags $name .{argfunction} {.argfunction}}
$fw {.while .throw .false {.function_all_flags &&name {.argfunction}}}
.function_all_flags f1 name {.while .throw .false {.function_all_flags &name {.argfunction}}}
$fw {.while .throw .false {
.function_all_flags &&name .{argfunction} {.argfunction}}}
.function_all_flags f1 name {.while .throw .false {
.function_all_flags &name .{argfunction} {.argfunction}}}
f2 : command not found ( f2 .whence_function fw )
$.function_all_flags f1 name {
$.function_all_flags f1 name .{argfunction} {
.echo function name $name $nl
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}
......@@ -697,15 +702,17 @@ function name f2
end of function body
f2 : command not found ( f2 .whence_function fw )
$fw {.mapped_argfunction {.function_all_flags $name {.argfunction}}}
.function_all_flags f1 name {.mapped_argfunction {.function_all_flags $name {.argfunction}}}
$fw {.mapped_argfunction {
.function_all_flags $name .{argfunction} {.argfunction}}}
.function_all_flags f1 name {.mapped_argfunction {
.function_all_flags $name .{argfunction} {.argfunction}}}
.function_all_flags f2 {.mapped_argfunction {.function_all_flags $name {.function_all_flags $name {.mapped_argfunction {.function_all_flags $name {.argfunction}}}}}}
.function_all_flags f2 {.mapped_argfunction {
.function_all_flags $name .{argfunction} {
.function_all_flags $name .{argfunction} {.mapped_argfunction {
.function_all_flags $name .{argfunction} {.argfunction}}}}}}
$.nop $A $FIGNORE
$.function_all_flags .shutdown -- args ... {
.nop $args
.combine $nl (now terminating normally) $nl}
$.exit 0
now terminating normally
.echo $nl $nl $nl $nl
.function_all_flags # [args ...] {.nop $args$}
.function_all_flags fw {
.function_all_flags f1 name {.argfunction}
.function_all_flags fw .{argfunction} {
.function_all_flags f1 name .{argfunction} {.argfunction}
.whence_function f1; .echo $nl
f1 f2 {.argfunction}
.whence_function f2; .echo $nl
.rm_executable f1; .rm_executable f2}
fw {.echo hi $nl; .function_all_flags $name {.argfunction}}
fw {.while .throw .false {.function_all_flags &&name {.argfunction}}}
.function_all_flags f1 name {
fw {.echo hi $nl; .function_all_flags $name .{argfunction} {.argfunction}}
fw {.while .throw .false {
.function_all_flags &&name .{argfunction} {.argfunction}}}
.function_all_flags f1 name .{argfunction} {
.echo function name $name $nl
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}
......@@ -61,10 +61,8 @@ fw {.mapped_argfunction $name {.for a b {
.echo function name &&name $nl
.whence_function .argfunction {.argfunction}
.echo $nl end of function body $nl}}}
fw {.mapped_argfunction {.function_all_flags $name {.argfunction}}}
fw {.mapped_argfunction {
.function_all_flags $name .{argfunction} {.argfunction}}}
.nop $A $FIGNORE
.function_all_flags .shutdown -- args ... {
.nop $args
.combine $nl (now terminating normally) $nl}
.exit 0
......@@ -59,6 +59,7 @@ class Argm {
False,
File_open_failure,
File_not_found,
Fixed_argument,
Flag_in_elipsis,
Function_not_found,
Global_would_be_masked,
......
......@@ -654,7 +654,9 @@ void b_stepwise(const Argm& argm, Error_list& exceptions) {
Function* f = dynamic_cast<Function*>(e);
if (!f) return; //throw Exception(Argm::Not_a_function, argm[1]);
// this must be caught and handled to use .stepwise recursively
Variable_map locals(f->arg_to_param(lookup));
Variable_map locals(lookup.parent_map());
f->arg_to_param(lookup, locals, exceptions);
if (global_stack.unwind_stack()) return;
Argm params(lookup.argv(), lookup.argfunction(), &locals,
lookup.input, lookup.output, lookup.error);
for (auto j: f->body) {
......
......@@ -2,7 +2,7 @@
// arguments passed to an executable and/or tie several other executables into
// a single executable.
//
// Copyright (C) 2006-2018 Samuel Newbold
// Copyright (C) 2006-2019 Samuel Newbold
#include <algorithm>
#include <iterator>
......@@ -55,11 +55,18 @@ void Command_block::execute(const Argm& src_argm,
void Command_block::prototype_execute(const Argm& argm,
const Prototype& prototype,
Error_list& exceptions) const {
Variable_map locals(prototype.arg_to_param(argm));
Argm params(argm.argv(), argm.argfunction(), &locals,
argm.input, argm.output, argm.error);
Variable_map locals(argm.parent_map());
prototype.arg_to_param(argm, locals, exceptions);
if (prototype.non_prototype);
else if (argm.argfunction() && prototype.exclude_argfunction)
exceptions.add_error(Exception(Argm::Excess_argfunction));
else if (!argm.argfunction() && prototype.required_argfunction)
exceptions.add_error(Exception(Argm::Missing_argfunction));
try {
execute(params, exceptions);
if (!global_stack.unwind_stack()) {
Argm params(argm.argv(), argm.argfunction(), &locals,
argm.input, argm.output, argm.error);
execute(params, exceptions);}
prototype.unused_var_check(&locals, exceptions);}
catch (Exception error) {
prototype.unused_var_check(&locals, exceptions);
......
// Copyright (C) 2005-2017 Samuel Newbold
// Copyright (C) 2005-2019 Samuel Newbold
class Command_block : public Base_executable, public std::vector<Arg_script> {
typedef std::vector<Arg_script> Base;
......@@ -49,8 +49,9 @@ class Function : public Named_executable {
const Command_block& src);
Function(const Function& src) :
name_v(src.name_v), prototype(src.prototype), body(src.body) {}
Variable_map arg_to_param(const Argm& invoking_argm) const {
return prototype.arg_to_param(invoking_argm);}
void arg_to_param(const Argm& invoking_argm, Variable_map& locals,
Error_list& exceptions) const {
return prototype.arg_to_param(invoking_argm, locals, exceptions);}
Function* copy_pointer(void) const {
if (!this) return 0;
else return new Function(*this);};
......
This diff is collapsed.
// Copyright (C) 2015-2017 Samuel Newbold
// Copyright (C) 2015-2019 Samuel Newbold
enum Flag_type {ALL, SOME};
enum Dash_dash_type {UNSEEN, BRACKET, BARE};
struct Parameter_group {
typedef std::vector<std::string> Base;
bool required;
Base::difference_type elipsis;
bool has_argfunction;
Base names;
Parameter_group() : required(true), elipsis(-2), names() {};
Parameter_group(bool required_i): required(required_i),elipsis(-2),names() {};
bool required;
Parameter_group() : has_argfunction(false), required(true), elipsis(-2),
names() {};
Parameter_group(bool required_i): has_argfunction(false),
required(required_i), elipsis(-2), names() {};
Parameter_group(Argm::const_iterator& fp, Argm::const_iterator end,
std::set<std::string>& parameter_names);
void arg_to_param(Variable_map& locals, int& available, int& needed,
std::string& missing,
void arg_to_param(int& available, int& needed, std::string& missing,
Argm::const_iterator& f_arg,
const Argm::const_iterator end,
const std::string* flag,
const std::string& elipsis_var,
enum Dash_dash_type dash_dash) const;
const std::string* flag, const std::string& elipsis_var,
enum Dash_dash_type dash_dash,
Variable_map& locals, Error_list& exceptions) const;
void add_undefined_params(Variable_map& locals) const;
std::string str() const;
void bless_unused_vars(Variable_map* vars) const;
......@@ -29,20 +31,24 @@ struct Parameter_group {
class Prototype {
bool bare_dash_dash;
int dash_dash_position;
Flag_type flags;
unsigned required_argc;
std::string elipsis_var;
std::map<std::string, Parameter_group> flag_options;
Flag_type flags;
std::set<std::string> parameter_names;
std::vector<Parameter_group> positional;
unsigned required_argc;
public:
bool non_prototype;
bool exclude_argfunction;
bool required_argfunction;
Prototype(bool non_prototype);
Prototype(Argm::const_iterator first_parameter,
Argm::const_iterator parameter_end, bool non_prototype_i);
Variable_map arg_to_param(const Argm& invoking_argm) const;
Argm bad_args(std::string& missing, const Variable_map& locals,
void arg_to_param(const Argm& invoking_argm, Variable_map& locals,
Error_list& exceptions) const;
void bad_args(std::string& missing, const Variable_map& locals,
Argm::const_iterator f_arg, Argm::const_iterator end,
std::vector<Parameter_group>::const_iterator param) const;
std::vector<Parameter_group>::const_iterator param,
Error_list& exceptions) const;
std::string str() const;
void unused_var_check(Variable_map* vars, Error_list& exceptions) const; };
// The main function for rwsh
//
// Copyright (C) 2005-2018 Samuel Newbold
// Copyright (C) 2005-2019 Samuel Newbold
#include <cstdlib>
#include <iostream>
......@@ -65,6 +65,7 @@ std::string Argm::exception_names[Argm::Exception_count] = {
".false",
".file_open_failure",
".file_not_found",
".fixed_argument",
".flag_in_elipsis",
".function_not_found",
".global_would_be_masked",
......
.function_all_flags # -- [ignored ...] {.nop $ignored$}
.function_all_flags fn -- prototype ... {
.function_all_flags # -- [ignored ...] [.{argfunction}] {.nop $ignored$}
.function_all_flags fn -- prototype ... .{argfunction} {
.function_all_flags $prototype$ {.argfunction}}
# set up environment
......@@ -98,6 +98,9 @@
.function_all_flags .file_open_failure -- file stack ... {
echo could not open file $file
echo call stack $stack}
.function_all_flags .fixed_argument -- arg stack ... {
echo $arg : fixed arguments are not supported at this time
echo call stack $stack}
.function_all_flags .flag_in_elipsis -- flag stack ... {
echo found flag $flag while collecting arguments for elipsis
echo call stack $stack$}
......@@ -247,10 +250,10 @@
.function_all_flags ! args ... {
.if $args$ {.throw .false ${.echo ! $args}}
.else {.nop}}
.function_all_flags af -- [argv ...] {.argfunction}
.function_all_flags af -- [argv ...] .{argfunction} {.argfunction}
.function_all_flags c -- text ... {.combine $text$}
.function_all_flags e -- text ... {.echo $text}
.function_all_flags do_while argv ... {
.function_all_flags do_while argv ... .{argfunction} {
.try_catch_recursive .break {
.nop $argv
.try_catch_recursive .continue {.argfunction}
......@@ -259,16 +262,17 @@
.function_all_flags echo-comments cmd ... {
.stepwise $cmd$ {if_only .test_in $1 .nop # #! ## {echo &&&*}}}
.function_all_flags exec -- argv ... {.exec $argv$}
.function_all_flags elif command ... {.else_if $command$ {.argfunction}}
.function_all_flags else {.else {.argfunction}}
.function_all_flags elif command ... .{argfunction} {
.else_if $command$ {.argfunction}}
.function_all_flags else .{argfunction} {.else {.argfunction}}
fn false {.try_catch_recursive .return_code {${whichp false}}}
.function_all_flags fns -- name args ... {
.function_all_flags fns -- name args ... .{argfunction} {
.function_all_flags $name [-*] $args$ {.argfunction}}
.function_all_flags if_only -- args ... {
.function_all_flags if_only -- args ... .{argfunction} {
.if $args$ {.argfunction}; .else {.nop}}
.function_all_flags if_only_not -- args ... {
.function_all_flags if_only_not -- args ... .{argfunction} {
.if $args$ {.nop}; .else {.argfunction}}
fn ntimes n {
fn ntimes n .{argfunction} {
.while test_var_greater n 0 {
.mapped_argfunction {.argfunction}
.var_subtract n 1}}
......@@ -276,14 +280,14 @@ fn ntimes n {
.replace_exception .break $stack$}
.function_all_flags outer_continue stack ... {
.replace_exception .continue $stack$}
.function_all_flags scope_for var vals ... {
.function_all_flags scope_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {.argfunction}}}
.function_all_flags outer_for var vals ... {
.function_all_flags outer_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {
.try_catch_recursive outer_break outer_continue {.argfunction}}}}
.function_all_flags outer_while argv ... {
.function_all_flags outer_while argv ... .{argfunction} {
.while $argv$ {
.try_catch_recursive outer_break outer_continue {.argfunction}}}
.function_all_flags setf var value {
......@@ -294,16 +298,16 @@ fn test -- args ... {
.try_catch_recursive .return_code {${whichp test} $args$}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
fn type [-t] args ... [.{argfunction}] {
.for $args$ {
.try_catch_recursive .function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.type &&&1 {.argfunction}}}}
fn whence command {
fn whence command [.{argfunction}] {
.try_catch_recursive .function_not_found {
.whence_function $command {.argfunction}}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags while_and_one_more argv ... {
.function_all_flags while_and_one_more argv ... .{argfunction} {
.try_catch_recursive .break {
.while $argv$ {.argfunction}
.try_catch_recursive .continue {.argfunction}}}
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,8 +8,8 @@
.signal_handler &{.internal_functions}$ {&&* {.argfunction}}
.mapped_argfunction {&&* {.argfunction}}
&&* {.argfunction}}
.function_all_flags .before_command -- args ... {.nop $args}
.function_all_flags .after_command -- args ... {.nop $args}
.function_all_flags .before_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .after_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .prompt {.echo \$}
.function_all_flags .vars {.internal_vars}
.source /etc/rwshrc-basic
......@@ -48,9 +48,9 @@ line continuation (or it was supposed to be)
# rwshrc-basic
.function e {.echo $*}
.function om {.argfunction}
.function_all_flags sa [args ...] {
.function_all_flags sa [args ...] .{argfunction} {
.scope $args$ ([args ...]) {.argfunction}}
.function_all_flags se {.scope () {.argfunction}}
.function_all_flags se .{argfunction} {.scope () {.argfunction}}
.whence_function e
.whence_function om
.whence_function sa
......@@ -63,7 +63,7 @@ echo text that does not have a prompt appended
se {echo again}
if_only .test_is_number false {echo not printed}
if_only .test_is_number 0 {echo printed without error}
.function_all_flags for -- [items ...] {
.function_all_flags for -- [items ...] .{argfunction} {
.if .var_exists items {.for $items$ {.argfunction}}
.else {.nop}}
for {echo skipped without error}
......@@ -345,7 +345,7 @@ se {se >outfile {e line 1 $nl; e line 2 longer $nl; .echo $nl; echo ending}}
.global A 0
.global OLD_NESTING ${.get_max_nesting}
.set_max_nesting 46
fn x {.var_add A 1
fn x .{argfunction} {.var_add A 1
se {.var_add A 1
se {.var_add A 1
se {.var_add A 1
......@@ -502,7 +502,7 @@ a 1 2
a
a 1
a 1 2
fn g name {.function_all_flags $name name {
fn g name .{argfunction} {.function_all_flags $name name {
.function_all_flags $name {.argfunction}}}
g a {e 3 2 1 $nl}
whence a
......@@ -586,7 +586,7 @@ a 1 2 3
for ${.list_locals}$ {.combine $1 \( $$1 \) \ }; .echo $nl}
whence a
a --long-opt -xx over-long flag
a -xx --long-opt over-long flag
a -xx --long-opt over-long flag extra excess
a --long-op short flag
a - --long-op short flag
a no flags
......@@ -599,9 +599,9 @@ a tardy flags_last - -x
a -x -- - flag_made_fixed_argument
a -- - flag_again_made_fixed_argument
a -x -- flag_and_fixed-x -x
a -x just flags-x --long-opt
a -x just flags-x --long-opt -x
a -x just flags-x -- --long-opt
a -x just flags-x --other
a -x just flags-x --other --also-wrong
a -x just flags-x -- --other
a -x with one excess argument
a - with flag
......@@ -673,16 +673,14 @@ whence a
.function_all_flags a -? x ... y {
for ${.list_locals}$ {.combine $1 \( $$1 \) \ }; .echo $nl}
whence a
a -c -a -b first second third
a -c first -a second -b third
.function_all_flags a -* x ... y {
for ${.list_locals}$ {.combine $1 \( $$1 \) \ }; .echo $nl}
whence a
a -c -a -b first second third
a -c first -a second -b third
.function_all_flags a [-?] x ... y {
for ${.list_locals}$ {.combine $1 \( $$1 \) \ }; .echo $nl}
whence a
a -c -a -b first second third
a -c first -a second -b third
a
a first
a first (se cond)
......@@ -1049,13 +1047,17 @@ e $x
.try_catch_recursive echo {silent_throw $text$}}
silent_throw on its own
caught_silent_throw on its own
fn if_true {.if .test_not_empty ( ) {.argfunction}}
fn if_false {.if .test_not_empty () {.argfunction}}
fn else_if_true {.else_if .test_string_unequal q w {.argfunction}}
fn else_if_false {.else_if .test_string_unequal q q {.argfunction}}
fn else_if_not_true {.else_if_not .test_string_equal x x {.argfunction}}
fn else_if_not_false {.else_if_not .test_string_equal y z {.argfunction}}
fn obscured_else {.scope () {.scope () {.else {.argfunction}}}}
fn if_true .{argfunction} {.if .test_not_empty ( ) {.argfunction}}
fn if_false .{argfunction} {.if .test_not_empty () {.argfunction}}
fn else_if_true .{argfunction} {
.else_if .test_string_unequal q w {.argfunction}}
fn else_if_false .{argfunction} {
.else_if .test_string_unequal q q {.argfunction}}
fn else_if_not_true .{argfunction} {
.else_if_not .test_string_equal x x {.argfunction}}
fn else_if_not_false .{argfunction} {
.else_if_not .test_string_equal y z {.argfunction}}
fn obscured_else .{argfunction} {.scope () {.scope () {.else {.argfunction}}}}
fn if_with_body args ... {.if $args$ {echo the afore-mentioned body}}
fn if_else_if_not_with_body args ... {
.if $args$ {echo the first body}
......@@ -1326,7 +1328,7 @@ se {.is_default_error}
.try_catch_recursive .replace_exception {
.throw .replace_exception echo now in exception handler}
# .scope
# .scope prototype.cc
.scope {e $foo}
.scope () {.scope foo}
.scope a (y y) {echo illegal duplicate required parameter}
......@@ -1344,6 +1346,7 @@ se {.is_default_error}
.scope a ([arg -- foo]) {echo -- cannot be an argument}
.scope -x -y a b ([-?] args ...) {
for ${.list_locals}$ {.combine $1 = $$1 \ }; .echo $nl}
.scope .foo {echo fixed arguments not yet supported}
.scope a ([-? bad] arg) {e -? cannot currently take arguments}
.scope a ([-* bad] arg) {e -* (aka -?) cannot currently take arguments}
.scope -a -* -b a ([-?] a) {
......@@ -1354,6 +1357,20 @@ se {.is_default_error}
.scope foo bar baz bax (args ...) {echo aa $args$2 bb $args$1 cc}
.scope single ([-x] [--long-opt y] second) {
var_val ${.list_locals}$; .echo $nl}
fn arg_req .{argfunction} {
echo before argfunction
.scope () {.argfunction}}
arg_req {echo the argfunction}
arg_req not an argfunction
fn arg_opt [.{argfunction}] {
.test_executable_exists .argfunction {.argfunction}
.scope () {.argfunction}}
arg_opt {echo the argfunction}
arg_opt
arg_opt not an argfunction
fn arg_none {echo argfunction will not be accepted}
arg_none bad arguments {echo will not print}
arg_none
.function_all_flags a [-x] [--long-opt y] second {
for ${.list_locals}$ {.combine $1 \( $$1 \) \ }
.combine $nl}
......@@ -1448,7 +1465,7 @@ echo $A
# .try_catch_recursive .get_max_extra_exceptions .set_max_extra_exceptions
.try_catch_recursive .function_not_found
.try_catch_recursive {.test_less 0 A}
fn e_after {se {.argfunction}; echo after}
fn e_after .{argfunction} {se {.argfunction}; echo after}
e_after {.try_catch_recursive .not_a_number .function_not_found {
.test_less 0 A}}
e_after {
......@@ -1617,7 +1634,7 @@ whence .mapped_argfunction {>dummy_file}
.whence_function .mapped_argfunction {{&&{&&x &&{e}}$$$ ${&&x ${e}}$$$ {&&&x &&&{e} {&&&&x &&&&{e}}}}}
whence .mapped_argfunction {$A $$A $0 $$$1 $# $* $*2 $A$$$ $A$10 $$*$ $$$*12$}
.whence_function .mapped_argfunction {&&A &&0 &&* &&*3 &&$A$$$ &&$A$10 &&*$ &&*6$ {&&&A$ &&&A$10}}
.function_all_flags wm [args ...] {
.function_all_flags wm [args ...] .{argfunction} {
.whence_function .mapped_argfunction {.argfunction}
.scope $args$ (a1 a2 a3) {.argfunction}}
wm (aa ab ac) bb cc {
......@@ -1630,7 +1647,7 @@ wm (aa ab ac) bb cc {
sa $args {echo $args$ $#}
sa $args$ {echo $args$ $#}
sa $more$ {echo $args$ $#}}}
.function_all_flags wm [args ...] {
.function_all_flags wm [args ...] .{argfunction} {
whence .mapped_argfunction {.argfunction}
.nop $args
se {.argfunction}
......@@ -1907,7 +1924,7 @@ not_a_thing
# .escaped_argfunction
.mapped_argfunction 1 2 3 {echo a $* a}
.mapped_argfunction
fn g {.whence_function .argfunction {.unescaped_argfunction}
fn g .{argfunction} {.whence_function .argfunction {.unescaped_argfunction}
.whence_function .argfunction {.argfunction}
.whence_function .argfunction {.escaped_argfunction}}
g {}
......
......@@ -6,13 +6,13 @@ call stack .source .try_catch_recursive(body)
.signal_handler &{.internal_functions}$ {&&* {.argfunction}}
.mapped_argfunction {&&* {.argfunction}}
&&* {.argfunction}}
.function_all_flags .before_command -- args ... {.nop $args}
.function_all_flags .after_command -- args ... {.nop $args}
.function_all_flags .before_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .after_command -- args ... [.{argfunction}] {.nop $args}
.function_all_flags .prompt {.echo \$}
.function_all_flags .vars {.internal_vars}
.source /etc/rwshrc-basic
.function_all_flags # -- [ignored ...] {.nop $ignored$}
.function_all_flags fn -- prototype ... {
.function_all_flags # -- [ignored ...] [.{argfunction}] {.nop $ignored$}
.function_all_flags fn -- prototype ... .{argfunction} {
.function_all_flags $prototype$ {.argfunction}}
# set up environment
......@@ -111,6 +111,9 @@ call stack .source .try_catch_recursive(body)
.function_all_flags .file_open_failure -- file stack ... {
echo could not open file $file
echo call stack $stack}
.function_all_flags .fixed_argument -- arg stack ... {
echo $arg : fixed arguments are not supported at this time
echo call stack $stack}
.function_all_flags .flag_in_elipsis -- flag stack ... {
echo found flag $flag while collecting arguments for elipsis
echo call stack $stack$}
......@@ -260,10 +263,10 @@ call stack .source .try_catch_recursive(body)
.function_all_flags ! args ... {
.if $args$ {.throw .false ${.echo ! $args}}
.else {.nop}}
.function_all_flags af -- [argv ...] {.argfunction}
.function_all_flags af -- [argv ...] .{argfunction} {.argfunction}
.function_all_flags c -- text ... {.combine $text$}
.function_all_flags e -- text ... {.echo $text}
.function_all_flags do_while argv ... {
.function_all_flags do_while argv ... .{argfunction} {
.try_catch_recursive .break {
.nop $argv
.try_catch_recursive .continue {.argfunction}
......@@ -272,16 +275,17 @@ call stack .source .try_catch_recursive(body)
.function_all_flags echo-comments cmd ... {
.stepwise $cmd$ {if_only .test_in $1 .nop # #! ## {echo &&&*}}}
.function_all_flags exec -- argv ... {.exec $argv$}
.function_all_flags elif command ... {.else_if $command$ {.argfunction}}
.function_all_flags else {.else {.argfunction}}
.function_all_flags elif command ... .{argfunction} {
.else_if $command$ {.argfunction}}
.function_all_flags else .{argfunction} {.else {.argfunction}}
fn false {.try_catch_recursive .return_code {${whichp false}}}
.function_all_flags fns -- name args ... {
.function_all_flags fns -- name args ... .{argfunction} {
.function_all_flags $name [-*] $args$ {.argfunction}}
.function_all_flags if_only -- args ... {
.function_all_flags if_only -- args ... .{argfunction} {
.if $args$ {.argfunction}; .else {.nop}}
.function_all_flags if_only_not -- args ... {
.function_all_flags if_only_not -- args ... .{argfunction} {
.if $args$ {.nop}; .else {.argfunction}}
fn ntimes n {
fn ntimes n .{argfunction} {
.while test_var_greater n 0 {
.mapped_argfunction {.argfunction}
.var_subtract n 1}}
......@@ -289,14 +293,14 @@ fn ntimes n {
.replace_exception .break $stack$}
.function_all_flags outer_continue stack ... {
.replace_exception .continue $stack$}
.function_all_flags scope_for var vals ... {
.function_all_flags scope_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {.argfunction}}}
.function_all_flags outer_for var vals ... {
.function_all_flags outer_for var vals ... .{argfunction} {
.for $vals$ {
.scope $1 $var {
.try_catch_recursive outer_break outer_continue {.argfunction}}}}
.function_all_flags outer_while argv ... {
.function_all_flags outer_while argv ... .{argfunction} {
.while $argv$ {
.try_catch_recursive outer_break outer_continue {.argfunction}}}
.function_all_flags setf var value {
......@@ -307,16 +311,16 @@ fn test -- args ... {
.try_catch_recursive .return_code {${whichp test} $args$}}
fn test_var_not_equal var value {.test_string_unequal $$var $value}
fn test_var_greater -- var value {.test_greater $$var $value}
fn type [-t] args ... {
fn type [-t] args ... [.{argfunction}] {
.for $args$ {
.try_catch_recursive .function_not_found {
if_only_not .var_exists -t {.echo &&&1 is ()}
.type &&&1 {.argfunction}}}}
fn whence command {
fn whence command [.{argfunction}] {
.try_catch_recursive .function_not_found {
.whence_function $command {.argfunction}}}
fn whichp binary {.which_path $binary $PATH}
.function_all_flags while_and_one_more argv ... {
.function_all_flags while_and_one_more argv ... .{argfunction} {
.try_catch_recursive .break {
.while $argv$ {.argfunction}
.try_catch_recursive .continue {.argfunction}}}
......
......@@ -38,6 +38,11 @@ void Variable_map::bless_unused_vars() {
if (!usage_checked) usage_checked = true;
else throw Exception(Argm::Internal_error,
"variable map usage checked multiple times");
bless_unused_vars_without_usage();}
void Variable_map::bless_unused_vars_without_usage() {
for (auto i: undefined_vars) if (checked_vars.find(i) == checked_vars.end())
checked_vars.insert(i);
for (auto i: *this) if (used_vars.find(i.first) == used_vars.end())
used_vars.insert(i.first);}
......
......@@ -23,6 +23,7 @@ public:
Variable_map(Variable_map* parent);
void bless_unused_vars();
void bless_unused_vars_without_usage();
~Variable_map();
const_iterator begin(void) const {return Base::begin();};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment