From 23c1d67f1a4a630c249cd454ae405496e5492689 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 7 Dec 2023 17:54:29 +0000 Subject: [PATCH] Refactor command regexps --- lib/irb.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 6e572c0f9..70d5a5cb7 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -595,10 +595,13 @@ def each_top_level_statement end end - SIMPLE_COMMAND_REGEXP = /^(?\S+)$/ - COMMAND_WITH_ARGS_REGEXP = /^(?\S+) +(?[^-]\S*)$/ - COMMAND_WITH_FLAGS_REGEXP = /^(?\S+) +(?-[a-zA-Z]+( +\S+)*)$/ - COMMAND_WITH_ARGS_AND_FLAGS_REGEXP = /^(?\S+) +(?[^-]\S*) +(?-[a-zA-Z]+( +\S+)*)$/ + COMMAND_FLAG_REGEXP = /(?-[a-zA-Z]+( +\S+)*)/ + COMMAND_ARG_REGEXP = /(?[^-]\S*)/ + COMMAND_NAME_REGEXP = /(?\S+)/ + SIMPLE_COMMAND_REGEXP = /^#{COMMAND_NAME_REGEXP}$/ + COMMAND_WITH_ARGS_REGEXP = /^#{COMMAND_NAME_REGEXP} +#{COMMAND_ARG_REGEXP}$/ + COMMAND_WITH_FLAGS_REGEXP = /^#{COMMAND_NAME_REGEXP} +#{COMMAND_FLAG_REGEXP}$/ + COMMAND_WITH_ARGS_AND_FLAGS_REGEXP = /^#{COMMAND_NAME_REGEXP} +#{COMMAND_ARG_REGEXP} +#{COMMAND_FLAG_REGEXP}$/ COMMAND_REGEXP = Regexp.union( SIMPLE_COMMAND_REGEXP,