token support for regular expression strings /.../ and \...\. Also tokenizer support for =~ and !~ operators.

This commit is contained in:
Kelvin Sherlock 2022-11-02 21:23:22 -04:00
parent 6f2b59c4d6
commit fdf33c69b7
2 changed files with 30 additions and 1 deletions

17
error.h
View File

@ -67,6 +67,21 @@ public:
{}
};
class fsstring_error: public mpw_error {
public:
fsstring_error(int status = -3) :
mpw_error(status, "MPW Shell - /s must occur in pairs.")
{}
};
class bsstring_error: public mpw_error {
public:
bsstring_error(int status = -3) :
mpw_error(status, "MPW Shell - \\s must occur in pairs.")
{}
};
/*
these are used for flow-control.
they do not inherit from std::exception to prevent being caught
@ -78,4 +93,4 @@ struct continue_command_t {};
struct exit_command_t { int value = 0; };
struct quit_command_t {};
#endif
#endif

View File

@ -37,6 +37,13 @@
dchar = escape_seq | (any - escape - ["]);
dstring = ["] dchar** ["] $err{ throw dstring_error(); } ;
# search-forward string
fschar = escape_seq | (any - escape - [/]);
fsstring = [/] fschar** [/] $err{ throw fsstring_error(); } ;
# search-backward string
bschar = escape_seq | (any - escape - [\\]);
bsstring = [\\] bschar** [\\] $err{ throw bsstring_error(); } ;
action eval { eval }
@ -127,9 +134,16 @@
'-=' when eval
%push_token => { tokens.emplace_back("-=", '-='); };
'=~' when eval
%push_token => { tokens.emplace_back("=~", '=~'); };
'!~' when eval
%push_token => { tokens.emplace_back("!~", '!~'); };
sstring => push_string;
dstring => push_string;
fsstring => push_string;
bsstring => push_string;
escape_seq => push_string;
char => push;