Skip to content

Commit

Permalink
Refactor command regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Dec 9, 2023
1 parent c5484c0 commit 23c1d67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,13 @@ def each_top_level_statement
end
end

SIMPLE_COMMAND_REGEXP = /^(?<cmd_name>\S+)$/
COMMAND_WITH_ARGS_REGEXP = /^(?<cmd_name>\S+) +(?<cmd_arg>[^-]\S*)$/
COMMAND_WITH_FLAGS_REGEXP = /^(?<cmd_name>\S+) +(?<cmd_flag>-[a-zA-Z]+( +\S+)*)$/
COMMAND_WITH_ARGS_AND_FLAGS_REGEXP = /^(?<cmd_name>\S+) +(?<cmd_arg>[^-]\S*) +(?<cmd_flag>-[a-zA-Z]+( +\S+)*)$/
COMMAND_FLAG_REGEXP = /(?<cmd_flag>-[a-zA-Z]+( +\S+)*)/
COMMAND_ARG_REGEXP = /(?<cmd_arg>[^-]\S*)/
COMMAND_NAME_REGEXP = /(?<cmd_name>\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,
Expand Down

0 comments on commit 23c1d67

Please sign in to comment.