A classifier is a mechanism that enables CM to infer a member's class from its name. Classifiers are invoked if no explicit class was given. CM supports two kinds of classifiers: suffix classifiers and general classifiers.
datatype classifier =
SFX_CLASSIFIER of string -> class option
| GEN_CLASSIFIER of { name: string, mkfname: unit -> string } ->
class option
Most of the time classifiers look at the file name suffix as their only clue. This idea is captured by SFX_CLASSIFIER which carries a partial function from suffixes to class names. The function should return NONE if it does not know about the given argument suffix.
The GEN_CLASSIFIER constructor carries a similar function--the difference being that the entire member name is passed to it. Moreover, the function can also invoke the mkfname argument to obtain a native filename string. This string can at this point be used to perform actual filesystem operations.
Invocation of mkfname may raise exceptions, usually due to syntax errors in name that prevent it from being interpreted as a filename. Tools that use mkfname should therefore be prepared to handle such exceptions.
Moreover, it is advisable not to over-use this feature, and not to perform extensive filesystem processing in order to perform classification. Otherwise the presence of this classifier might cause considerable overhead.
By the way, suffix classifiers could be implemented as general classifiers, but using SFX_CLASSIFIER for them is slightly more efficient. CM extracts the suffix from the name only once and applies all suffix classifier before ever considering any generic classifier. If some suffix classifier succeeds, there will be no overhead caused by any generic classifier.
Function Tools.stdSfxClassifier is a simple wrapper around SFX_CLASSIFIER and produces a classifier that looks for precisely one suffix string.
val stdSfxClassifier : { sfx: string , class: class } -> classifier
Classifiers are registered with CM by invoking Tools.registerClassifier:
val registerClassifier : classifier -> unit