## html-parser-g.pkg
# Compiled by:
#
src/lib/html/html.lib# This glues the lexer and parser together.
stipulate
package has = html_abstract_syntax; # html_abstract_syntax is from
src/lib/html/html-abstract-syntax.pkgherein
generic package html_parser_g (err: Html_Error) # Html_Error is from
src/lib/html/html-error.api : (weak)
api {
parse_file: String -> has::Html;
}
{
package tio
=
file__premicrothread;
package htmlattrs
=
html_attributes_g( err );
package htmllr_vals
=
html_lr_vals_g(
package token= lr_parser::token; # lr_parser is from
src/app/yacc/lib/parser2.pkg package htmlattrs = htmlattrs;
);
package lex
=
html_lex_g(
package err = err;
package tokens = htmllr_vals::tokens;
package htmlattrs = htmlattrs;
);
package parser
=
make_complete_yacc_parser_with_custom_argument_g(
package lex= lex;
package lr_parser = lr_parser;
package parser_data = htmllr_vals::parser_data;
);
package check_html
=
check_html_g( err );
fun parse_file fname
=
{ # Build a context to hand to the htmlattrs build functions.
#
fun context lnum
=
{ file => THE fname,
line => lnum
};
fun lex_error (msg, lnum, _)
=
err::lex_error
#
{ file => THE fname,
line => lnum
}
#
msg;
fun syntax_error (msg, lnum, _)
=
err::syntax_error
#
{ file => THE fname,
line => lnum
}
#
msg;
input_stream
=
tio::open_for_read fname;
fun close ()
=
tio::close_input input_stream;
lexer
=
parser::make_lexer
#
(\\ n = tio::read_n (input_stream, n))
#
(lex_error, THE fname);
my (result, _)
=
parser::parse (
15, # Lookahead.
lexer,
syntax_error,
context
);
check_html::check (context 0) result
except
x = { close ();
raise exception x;
};
result;
};
};
end;
## COPYRIGHT (c) 1996 AT&T REsearch.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.