## keyword-g.pkg
# Compiled by:
#
src/lib/std/standard.lib# This generic is meant to be used as part of a scanner, where identifiers
# and keywords are scanned using the same lexical rules and are then
# further analyzed.
### "We want to make a machine
### that will be proud of us."
###
### -- Danny Hillis
generic package keyword_g (kw: api {
Token;
Source_Position;
ident: ((quickstring__premicrothread::Quickstring, Source_Position, Source_Position)) -> Token;
keywords: List( (String, (((Source_Position, Source_Position)) -> Token)) );
}
)
: (weak)
api {
Token;
Source_Position;
keyword: ((String, Source_Position, Source_Position)) -> Token;
}
{
package qs = quickstring__premicrothread; # quickstring__premicrothread is from
src/lib/src/quickstring--premicrothread.pkg package qht = quickstring_hashtable; # quickstring_hashtable is from
src/lib/src/quickstring-hashtable.pkg Token = kw::Token;
Source_Position = kw::Source_Position;
# The keyword hashtable
#
exception KEYWORD;
my kw_table: qht::Hashtable((Source_Position, Source_Position) -> Token)
= qht::make_hashtable { size_hint => list::length kw::keywords, not_found_exception => KEYWORD };
# Insert the reserved words into the keyword hashtable
#
my _ = {
set = qht::set kw_table;
fun ins (s, item) = set (qs::from_string s, item);
apply ins kw::keywords;
};
fun keyword (s, p1, p2)
=
{
name = qs::from_string s;
case (qht::find kw_table name)
#
THE tok_g => tok_g (p1, p2);
NULL => kw::ident (name, p1, p2);
esac;
};
};
## COPYRIGHT (c) 1997 AT&T Labs Research.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.