PreviousUpNext

15.4.34  src/app/future-lex/src/frontends/lex-spec.pkg

## lex-spec.pkg
## John Reppy (http://www.cs.uchicago.edu/~jhr)
## Aaron Turon (adrassi@gmail.com)
## All rights reserved.

# Compiled by:
#     src/app/future-lex/src/lexgen.lib


# Input specification to ml-flex


###                 "Do only what only you can do."
###
###                             -- E.J. Dijkstra



package lex_spec {

    Clamp = CLAMP127 | CLAMP255 | NO_CLAMP;

    Action = String;
    Rule_Spec =  (Null_Or( quickstring_set::Set ), regular_expression::Re);
    Rule = (Rule_Spec, Action);

    Config
        =
        CONF  {
            struct_name:  String,
            header:  String,
            arg:  String,
            start_states:  quickstring_set::Set,
            clamp:  Clamp
          };

     Spec
        =
        SPEC  {
            decls:  String,
            conf:  Config,
            rules:  List( Rule )
          };

    fun make_config ()
        =
        CONF {
            struct_name  => "",
            header       => "",
            arg          => "",
            start_states => quickstring_set::empty,
            clamp        => CLAMP127
        };

    fun upd_start_states (conf, new)
        =
        {   my CONF { struct_name, header, arg, start_states, clamp }
                =
                conf;

            CONF {
                struct_name,
                header,
                arg,
                clamp,
                start_states =>  new
            };
        };

    fun upd_header (conf, new)
        =
        {   my CONF { struct_name, header, start_states, arg, clamp }
                =
                conf;

            if   (string::length_in_bytes struct_name > 0)
                
                 raise exception DIE "Cannot have both %package and %header";
            fi;

            CONF {
                struct_name,
                header      => new,
                arg,
                start_states,
                clamp       => clamp
            };
        };

    fun upd_struct_name (conf, new)
        =
        {   conf ->  CONF { struct_name,
                            header,
                            start_states,
                            arg,
                            clamp
                          };

            if   (string::length_in_bytes header  >  0)
                
                 raise exception DIE "Cannot have both %package and %header";
            fi;

            CONF {
                struct_name  => new,
                header,
                arg,
                start_states,
                clamp
            };
        };

    fun upd_arg (conf, new)
        =
        {   my CONF { struct_name, header, start_states, arg, clamp }
                =
                conf;

            CONF {
                struct_name,
                header,
                arg         => new,
                start_states,
                clamp       => clamp
            };
        };

    fun upd_clamp (conf, new)
        =
        {   my CONF { struct_name, header, arg, start_states, clamp }
                =
                conf;

            CONF {
                struct_name,
                header,
                arg,
                start_states,
                clamp       => new
            };
        };

    fun empty_actions (spec)
        =
        {   my SPEC { decls, conf, rules }
                =
                spec;

            my CONF { struct_name, header, arg, start_states, clamp }
                =
                conf;

            conf' = CONF {
                        struct_name  => "",
                        header      => "",
                        arg         => "",
                        clamp,
                        start_states
                    };

            fun clear_rule (rspec, action)
                =
                (rspec, "()");

            SPEC {
                decls => "fun eof () = ()", 
                conf  => conf', 
                rules => list::map clear_rule rules
            };
        };

};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext