PreviousUpNext

15.4.137  src/app/yacc/lib/make-complete-yacc-parser-with-custom-argument-g.pkg

## make-complete-yacc-parser-with-custom-argument-g.pkg

# Compiled by:
#     src/lib/std/standard.lib

# See also:
#     src/app/yacc/lib/make-complete-yacc-parser-g.pkg


###                      "Call no man unhappy until he is married."
###
###                                  -- Socrates (470 - 399 BCE)



# Like 
# generic make_complete_yacc_parser_with_custom_argument_g
# creates a user parser by putting together a Lexer package,
# an LrValues package, and a typeagnostic parser package.  Note that
# the Lexer and LrValues package must share the type Source_Position (i.e. the type
# of line numbers), the type Semantic_Value, and the type of tokens.

# In this case, the make_lexer take an additional
# argument before yielding a value of type
#
#     Void -> Token (Semantic_Value, Source_Position) 

# This generic is invoked from:
#
#     src/lib/compiler/front/parser/main/mythryl-parser-guts.pkg
#     src/app/makelib/parse/libfile-parser-g.pkg
#     src/lib/html/html-parser-g.pkg
#     src/lib/compiler/back/low/tools/parser/architecture-description-language-parser-g.pkg
#
generic package make_complete_yacc_parser_with_custom_argument_g (

    package lex:          Arg_Lexer;                    # Arg_Lexer     is from   src/app/yacc/lib/base.api
    package parser_data:  Parser_Data;                  # Parser_Data   is from   src/app/yacc/lib/base.api
    package lr_parser:    Lr_Parser;                    # Lr_Parser     is from   src/app/yacc/lib/base.api

    sharing parser_data::lr_table ==  lr_parser::lr_table;
    sharing parser_data::token    ==  lr_parser::token;

    sharing lex::user_declarations::Semantic_Value  ==  parser_data::Semantic_Value;
    sharing lex::user_declarations::Source_Position ==  parser_data::Source_Position;
    sharing lex::user_declarations::Token           ==  parser_data::token::Token;
)

: (weak)  Arg_Parser                                            # Arg_Parser    is from   src/app/yacc/lib/base.api

{
    package token  =  parser_data::token;
    package stream =  lr_parser::stream;

    exception PARSE_ERROR
        =
        lr_parser::PARSE_ERROR;

    Lex_Arg         = lex::user_declarations::Arg;

    Arg             = parser_data::Arg;
    Source_Position = parser_data::Source_Position;
    Result          = parser_data::Result;
    Semantic_Value  = parser_data::Semantic_Value;

    fun make_lexer  s  arg
        =
        lr_parser::stream::streamify
            (lex::make_lexer s arg);

    fun parse (lookahead, lexer, error, arg)
        =
        (\\ (a, b) = (parser_data::actions::extract a, b))
        (lr_parser::parse
            { lexer,
              lookahead,
              arg,
              table          =>  parser_data::table,
              saction        =>  parser_data::actions::actions,
              void           =>  parser_data::actions::void,
              error_recovery =>  { error,
                                   is_keyword       =>  parser_data::error_recovery::is_keyword,
                                   no_shift         =>  parser_data::error_recovery::no_shift,
                                   preferred_change =>  parser_data::error_recovery::preferred_change,
                                   errtermvalue     =>  parser_data::error_recovery::errtermvalue,
                                   show_terminal    =>  parser_data::error_recovery::show_terminal,
                                   terms            =>  parser_data::error_recovery::terms
                                 }
            }
        );

    same_token = token::same_token;

};



## Mythryl-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi 
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext