The KeywordFn functor

The KeywordFn functor provides a simple way to support a table of keyword (or reserved) identifiers in a scanner.

Synopsis

functor KeywordFn ()

Functor Argument Interface

type token
type pos
val ident : (Atom.atom * pos * pos) -> token
val keywords : (string * ((pos * pos) -> token)) list

Functor Argument Description

type token

The type of tokens in the scanner.

type pos

The type of source file positions used by the scanner (e.g., character positions in the source file).

val ident : (Atom.atom * pos * pos) -> token

ident (id, pos, pos) is used to create an identifier token (i.e., non-keyword) for the given string, and start and end file positions.

val keywords : (string * pos * pos) -> token list

A list of string-function pairs, where the strings are the keywords and the functions are used to create the corresponding scanner tokens from start and end file positions.

Interface

    type token
    type pos
    val keyword : (string * pos * pos) -> token

Interface Description

type token

The type of tokens in the scanner.

type pos

The type of source file positions used by the scanner.

val keyword : (string * pos * pos) → token

keyword (id, p1, p2) returns the token for the identifier id, which is either one of the keyword tokens from the keywords list or otherwise is an identifier token created using the ident function.

Discussion

This functor was designed for the ml-yacc scanner interface, where tokens contain their file position. It is not clear that it adds much utility over just using the atom type, but is maintained for backward compatibility.