JSON has exactly three bare words - true, false, and null. Today you scan them as keyword tokens, and introduce the Illegal token the scanner uses to flag anything it cannot make sense of, like a misspelled keyword.
Scan the three literal keywords, and report an unrecognized bare word as an Illegal token.
Beyond punctuation, JSON allows exactly three literal keywords: true,
false, and null. The scanner reads a run of letters and checks it against those
three names. A match becomes the matching keyword token; anything else - a typo like
nul, or extra letters like truex - is not a valid JSON token at all.
That failure case needs a home, so today also introduces the Illegal token. It is how the scanner reports “I found bytes I cannot turn into a valid token” without crashing: it produces an Illegal token carrying a message and the same position fields as any other token, and stops there. Later the parser will turn an Illegal token into a positioned error for the caller. For now, just make sure a good keyword scans to its keyword and a bad one scans to a single Illegal at the right offset.
// add True, False, Null, Illegal to the Kind set; give Token a Msg field// read a run of ascii letters, then decide:// switch word {// case "true": ... case "false": ... case "null": ...// default: Illegal token with Msg like "invalid literal " + word// }// Illegal carries the same Offset/Line/Col as any token