Task
Given a string composed of ASCII printable characters, return how many strings could fit the given pattern with character literals and regex-like ranges.
Pattern string
The pattern string follows this grammar (the | means an option and the * means 0 or more occurrences of whatever was immediately to the left):
pattern := '' | pattern_string pattern_string := (SAFE_CHAR | ASCII_RANGE) pattern_string* ASCII_RANGE := '[' CHAR '-' CHAR ']' where CHAR is any ASCII character in the range [32, 127] and SAFE_CHAR is any CHAR except the three characters [, - and ].
Examples
Examples of pattern strings would be a, [0-*]4fj, [a-z][4-9]D[d-B].
Input
The pattern string. You can assume all ranges are well-formed and that all the second characters in the ranges have their ASCII codepoints >= than the corresponding first characters in the range.
Output
The integer corresponding to the number of strings that match the given pattern string.
Test cases
"" -> 1 "a" -> 1 "[*-0]" -> 7 "[0-9][0-9]" -> 100 "[a-z]d[A-z]" -> 1508 "[<->]" -> 3 "[!-&]" -> 6 "[d-z]abf[d-z]fg" -> 529 "[[-]]" -> 3 "[a-a][b-b]cde[---]" -> 1 "[0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1][0-1]" -> 4096 "[--[][--]]" -> 2303 "[[-[].[]-]]" -> 1 You can check this Python reference implementation that I used to generate the test cases.
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
This is the second challenge of the RGS Golfing Showdown. If you want to participate in the competition, you have 96 hours to submit your eligible answers. Remember there is still 400 reputation in prizes! (See 6 of the rules)
Also, as per section 4 of the rules in the linked meta post, the "restricted languages" for this second challenge are: 05AB1E, W, Jelly, Japt, Gaia, MathGolf and Stax, so submissions in these languages are not eligible for the final prize. But they can still be posted!!
Otherwise, this is still a regular code-golf challenge, so enjoy!