PreviousUpNext

15.4.1368  src/lib/x-kit/widget/fancy/graphviz/text/ml-keywords.pkg

# ml-keywords.pkg
#
#
# This package implements a hashtable for mapping identifiers to
# unique names (and parser tokens).

# Compiled by:
#     src/lib/x-kit/widget/xkit-widget.sublib

###              "The eternal mystery of the world is its comprehensibility."
###
###                                        -- Immanuel Kant

stipulate
    package vb =  view_buffer;                          # view_buffer                   is from   src/lib/x-kit/widget/fancy/graphviz/text/view-buffer.pkg
    package qh =  quickstring_hashtable;                # quickstring_hashtable         is from   src/lib/src/quickstring-hashtable.pkg
    package qs =  quickstring__premicrothread;          # quickstring__premicrothread   is from   src/lib/src/quickstring--premicrothread.pkg
herein

    package ml_keywords:  api {

        make_token
            :
            { space:  Int,
              text:   String
            }
            ->
            { space:  Int,
              kind:   view_buffer::Token_Kind,
              text:   String
            };

    }{

        # The keyword hashtable:
        #
        exception KEYWORD;
        #
        my keywords:  qh::Hashtable( vb::Token_Kind )
            =
            qh::make_hashtable  { size_hint =>64,  not_found_exception => KEYWORD };

        # Insert the reserved words into
        # the keyword hashtable:
        #
                                    my _ =
        {
            insert = qh::set  keywords;

            fun ins (s, item)
                =
                insert (qs::from_string s, item);

            # Insert SML reserved words:
            # 
            apply ins
                  [
                    ("*",           vb::SYMBOL),
                    ("|",           vb::SYMBOL),
                    (":",           vb::SYMBOL),
                    ("=",           vb::SYMBOL),
                    ("#",           vb::SYMBOL),
                    ("->",          vb::SYMBOL),
                    ("=>",          vb::SYMBOL),
                    #
                    ("also",        vb::KEYWORD),
                    ("abstype",     vb::KEYWORD),
                    ("as",          vb::KEYWORD),
                    ("case",        vb::KEYWORD),
                    ("enum",        vb::KEYWORD),
                    ("else",        vb::KEYWORD),
                    ("end",         vb::KEYWORD),
                    ("exception",   vb::KEYWORD),
                    ("fn",          vb::KEYWORD),
                    ("fun",         vb::KEYWORD),
                    ("except",      vb::KEYWORD),
                    ("if",          vb::KEYWORD),
                    ("herein",      vb::KEYWORD),
                    ("infix",       vb::KEYWORD),
                    ("infixr",      vb::KEYWORD),
                    ("stipulate",   vb::KEYWORD),
                    ("local",       vb::KEYWORD),
                    ("nonfix",      vb::KEYWORD),
                    ("of",          vb::KEYWORD),
                    ("op",          vb::KEYWORD),
                    ("use",         vb::KEYWORD),
                    ("raise",       vb::KEYWORD),
                    ("then",        vb::KEYWORD),
                    ("type",        vb::KEYWORD),
                    ("my",          vb::KEYWORD),
                    ("with",        vb::KEYWORD),
                    ("withtype",    vb::KEYWORD),
                    ("or",          vb::KEYWORD),
                    ("and",         vb::KEYWORD),
                    ("abstraction", vb::KEYWORD),
                    ("do",          vb::KEYWORD),
                    ("eqtype",      vb::KEYWORD),
                    ("funsig",      vb::KEYWORD),
                    ("generic",     vb::KEYWORD),
                    ("include",     vb::KEYWORD),
                    ("overload",    vb::KEYWORD),
                    ("rec",         vb::KEYWORD),
                    ("REF",         vb::KEYWORD),
                    ("sharing",     vb::KEYWORD),
                    ("sig",         vb::KEYWORD),
                    ("api",         vb::KEYWORD),
                    ("struct",      vb::KEYWORD),
                    ("package",     vb::KEYWORD),
                    ("while",       vb::KEYWORD)
                  ];
        };

        peek = qh::find keywords;

        fun make_token { space, text }
            =
            {   name = qs::from_string  text;

                kind = case (peek name)
                           #
                           THE k =>  k;
                           _     =>  vb::IDENT;
                       esac;

                { space, kind, text => qs::to_string name };
            };

    };                          # package keywords 

end;


# COPYRIGHT (c) 1992 AT&T Bell Laboratories
# Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
# released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext