From fdf33c69b73e8c1ea95337566d0e0dc0a3370341 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 2 Nov 2022 21:23:22 -0400 Subject: [PATCH] token support for regular expression strings /.../ and \...\. Also tokenizer support for =~ and !~ operators. --- error.h | 17 ++++++++++++++++- mpw-shell-token.rl | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/error.h b/error.h index 407c5a0..ec7326b 100644 --- a/error.h +++ b/error.h @@ -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 \ No newline at end of file +#endif diff --git a/mpw-shell-token.rl b/mpw-shell-token.rl index e5c739f..0a6d5c3 100644 --- a/mpw-shell-token.rl +++ b/mpw-shell-token.rl @@ -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;