PreviousUpNext

15.4.828  src/lib/prettyprint/big/src/base-prettyprinter-g.pkg

## base-prettyprinter-g.pkg
#
# The core prettyprint mill code is located in

#     src/lib/prettyprint/big/src/core-prettyprinter-g.pkg
#
# Our job in this file is to wrap the core prettyprint mill up
# in an API more convenient for code clients, thus allowing the
# core prettyprint mill to stay focussed on task.
#
# Our most important code client (by far) is
#
#     src/lib/prettyprint/big/src/standard-prettyprinter-g.pkg
# +   src/lib/prettyprint/big/src/standard-prettyprinter.pkg
#
# which is the prettyprint mill used pervasively throughout the
# Mythryl compiler and associated support code.
#
# For historical reasons we also have a number of other code
# clients, which mostly should be phased out over time in favor
# of standard-prettyprinter.pkg:
#
#     src/lib/prettyprint/big/src/old-prettyprinter.pkg
#     src/lib/prettyprint/big/src/plain-file-prettyprinter.pkg
#     src/lib/prettyprint/big/src/ansi-terminal-prettyprinter.pkg
#     src/lib/prettyprint/big/src/plain-file-prettyprinter-avoiding-pointless-file-rewrites.pkg

# Compiled by:
#     src/lib/prettyprint/big/prettyprinter.lib


###            "The gods too are fond of a joke."
###
###                            -- Aristotle



stipulate
    package fil =  file__premicrothread;                                        # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    # This generic is invoked most importantly from from
    #
    #     src/lib/prettyprint/big/src/standard-prettyprinter-g.pkg
    #
    # but (currently -- these should mostly go away) also
    #
    #    src/lib/prettyprint/big/src/base-prettyprinter.pkg
    #    src/lib/prettyprint/big/src/old-prettyprinter.pkg
    #    src/lib/prettyprint/big/src/plain-file-prettyprinter.pkg
    #    src/lib/prettyprint/big/src/ansi-terminal-prettyprinter.pkg
    #    src/lib/prettyprint/big/src/plain-file-prettyprinter-avoiding-pointless-file-rewrites.pkg
    #
    generic package   base_prettyprinter_g   (
        #             ======================= 
        #
        package tt:     Traitful_Text;                                          # Traitful_Text                                                         is from   src/lib/prettyprint/big/src/traitful-text.api
        package out:    Prettyprint_Output_Stream;                              # Prettyprint_Output_Stream                                             is from   src/lib/prettyprint/big/src/out/prettyprint-output-stream.api
                                                                                # out will be something like html_prettyprint_output_stream                from   src/lib/prettyprint/big/src/out/html-prettyprint-output-stream.pkg
        sharing tt::Texttraits == out::Texttraits;
    )
    : (weak)  Base_Prettyprinter
    {
        package pp
            =
            core_prettyprinter_g (                                              # core_prettyprinter_g          is from   src/lib/prettyprint/big/src/core-prettyprinter-g.pkg
                #
                package tt  =  tt;                                              # traitless_text                is from   src/lib/prettyprint/big/src/traitless-text.pkg
                package out =  out;
            );

        include package   pp;

        fun shut_box                            pp              =  finalize_and_pop_current_box   pp;

        fun lit    pp s =  add_lit    (pp, s);
        fun endlit pp s =  add_endlit (pp, s);

        stipulate
            default_width = 100;

            indent4 = { blanks => 1, tab_to => 0, tabstops_are_every => 4 };
            indent0 = { blanks => 0, tab_to => 0, tabstops_are_every => 4 };
        herein

            fun break                           pp arg          =  prettyprint_break (pp, arg);
            fun blank                           pp n            =  break pp { blanks => n, indent_on_wrap => 0 };
            fun cut                             pp              =  break pp { blanks => 0, indent_on_wrap => 0 };
            fun newline                         pp              =  add_token (pp, typ::NEWLINE );
            fun nonbreakable_blanks             pp n            =  add_token (pp, typ::BLANKS n);
            fun tab                             pp arg          =  add_token (pp, typ::TAB arg );

            fun control                         pp control_fn   =  add_token (pp, typ::CONTROL control_fn);
        end;


    };                                                                                                                                  # generic package base_prettyprinter_g
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext