toRecognizer

Universal function to turn an object into a recognizer. This function returns a token recognizer.

x may be:

  • A String, in which case the returned recognizer will attempt to match the string exactly. (Pseudo-recognizer)

  • A Char, which is identical to a String with a single character.

  • A CharRange, in which case the recognizer will attempt to match a single character from the given range. (Pseudo-recognizer)

  • A recognizer, in which case x will be returned directly. This is useful for having one-fits-all methods that can accommodate both directly taking in a recognizer and a pseudo-recognizer. (Recognizer)

If x does not match any of the previous types, a NiwenLexerException is thrown.

Return

A recognizer that matches the behaviors stated in the description of this function.

Parameters

x

An object, which can be either a String, a CharRange, or a TokenRecognizer