A bracket expression matches one character from a set, like [aeiou] for any vowel. Today matchOne learns to scan a class and test membership - the first token that spans more than one pattern character.
Make a bracket class match one character drawn from the set inside it.
A bracket expression - [abc] - matches exactly one character, drawn from
the set listed between the brackets. It is a ? with a restricted alphabet: h[aeiou]t
matches hat, hit, hot, but not hct, because c is not one of the listed
characters. Like ?, it consumes exactly one character of the name.
This is the first token that spans several pattern characters, which is precisely
why lesson 4 pulled matchOne out into its own helper: it scans from the opening
[ to the closing ], checks whether the name character is one of the members,
and returns the index past the ] so the main scan continues after the whole
class. Today handles a plain list of characters; ranges, negation, and the awkward
edge cases each extend this same scanner in the next few lessons.
// inside matchOne, when the token starts with '['if pat[p] == '[' {j := p + 1matched := falsefor j < len(pat) && pat[j] != ']' {if pat[j] == c { matched = true }j++}return matched, j + 1 // j is at ']'; the token ends after it}