2014-06-11 00:02:06 +00:00
/*
2015-06-02 00:53:25 +00:00
Copyright ( c ) 2014 - 2015 Microsoft Corporation . All rights reserved .
2014-06-11 00:02:06 +00:00
Released under Apache 2.0 license as described in the file LICENSE .
Author : Leonardo de Moura
*/
2014-06-13 22:13:32 +00:00
# include <algorithm>
2014-10-24 15:19:36 +00:00
# include <string>
2014-06-13 18:24:26 +00:00
# include "util/sstream.h"
2014-06-17 00:27:43 +00:00
# include "util/sexpr/option_declarations.h"
2014-06-13 22:13:32 +00:00
# include "kernel/type_checker.h"
2014-07-10 13:07:41 +00:00
# include "kernel/instantiate.h"
2014-06-13 18:24:26 +00:00
# include "library/scoped_ext.h"
# include "library/aliases.h"
2014-09-04 01:37:01 +00:00
# include "library/protected.h"
2015-11-02 01:19:57 +00:00
# include "library/constants.h"
2014-09-27 03:16:03 +00:00
# include "library/normalize.h"
2014-12-10 05:12:39 +00:00
# include "library/class.h"
2014-11-24 16:35:49 +00:00
# include "library/flycheck.h"
2015-05-29 21:37:06 +00:00
# include "library/abbreviation.h"
2015-05-12 22:08:10 +00:00
# include "library/user_recursors.h"
2014-12-19 23:00:05 +00:00
# include "library/pp_options.h"
2015-10-01 01:50:28 +00:00
# include "library/aux_recursors.h"
# include "library/private.h"
2015-10-15 01:36:41 +00:00
# include "library/decl_stats.h"
2015-10-15 02:34:53 +00:00
# include "library/meng_paulson.h"
2015-11-06 06:02:00 +00:00
# include "library/fun_info_manager.h"
2015-11-07 03:13:11 +00:00
# include "library/congr_lemma_manager.h"
2015-11-13 00:30:22 +00:00
# include "library/abstract_expr_manager.h"
2014-10-29 19:50:52 +00:00
# include "library/definitional/projection.h"
2015-11-05 05:53:12 +00:00
# include "library/blast/blast.h"
2015-11-19 23:30:38 +00:00
# include "library/blast/simplifier/simplifier.h"
2015-09-12 00:12:32 +00:00
# include "compiler/preprocess_rec.h"
2014-06-18 17:36:21 +00:00
# include "frontends/lean/util.h"
2014-06-11 18:44:16 +00:00
# include "frontends/lean/parser.h"
2014-06-17 20:35:31 +00:00
# include "frontends/lean/calc.h"
2014-06-15 05:13:25 +00:00
# include "frontends/lean/notation_cmd.h"
2014-06-18 20:55:48 +00:00
# include "frontends/lean/inductive_cmd.h"
2014-07-29 02:04:57 +00:00
# include "frontends/lean/structure_cmd.h"
2015-12-27 02:13:59 +00:00
# include "frontends/lean/print_cmd.h"
2014-11-24 07:00:59 +00:00
# include "frontends/lean/find_cmd.h"
2014-08-21 17:36:44 +00:00
# include "frontends/lean/begin_end_ext.h"
2014-06-18 17:36:21 +00:00
# include "frontends/lean/decl_cmds.h"
2014-07-08 21:28:33 +00:00
# include "frontends/lean/tactic_hint.h"
2014-09-23 02:22:53 +00:00
# include "frontends/lean/tokens.h"
2014-12-02 20:04:18 +00:00
# include "frontends/lean/parse_table.h"
2014-06-11 00:02:06 +00:00
namespace lean {
2014-06-13 18:24:26 +00:00
environment section_cmd ( parser & p ) {
2014-08-07 23:59:08 +00:00
name n ;
if ( p . curr_is_identifier ( ) )
n = p . check_atomic_id_next ( " invalid section, atomic identifier expected " ) ;
2014-06-13 18:24:26 +00:00
p . push_local_scope ( ) ;
2014-08-23 22:44:28 +00:00
return push_scope ( p . env ( ) , p . ios ( ) , scope_kind : : Section , n ) ;
}
2014-06-13 18:24:26 +00:00
environment namespace_cmd ( parser & p ) {
2014-07-08 02:15:46 +00:00
auto pos = p . pos ( ) ;
name n = p . check_atomic_id_next ( " invalid namespace declaration, atomic identifier expected " ) ;
if ( is_root_namespace ( n ) )
throw parser_error ( sstream ( ) < < " invalid namespace name, ' " < < n < < " ' is reserved " , pos ) ;
2014-10-10 23:21:30 +00:00
p . push_local_scope ( ) ;
2014-08-23 22:44:28 +00:00
return push_scope ( p . env ( ) , p . ios ( ) , scope_kind : : Namespace , n ) ;
2014-06-13 18:24:26 +00:00
}
2015-04-22 05:40:20 +00:00
static environment redeclare_aliases ( environment env , parser & p ,
list < pair < name , level > > old_level_entries ,
list < pair < name , expr > > old_entries ) {
environment const & old_env = p . env ( ) ;
2015-04-22 18:32:02 +00:00
if ( ! in_section ( old_env ) )
2015-04-22 05:40:20 +00:00
return env ;
2014-10-09 05:21:29 +00:00
list < pair < name , expr > > new_entries = p . get_local_entries ( ) ;
buffer < pair < name , expr > > to_redeclare ;
2015-06-04 04:40:03 +00:00
unsigned new_len = length ( new_entries ) ;
unsigned old_len = length ( old_entries ) ;
lean_assert ( old_len > = new_len ) ;
2014-10-09 05:21:29 +00:00
name_set popped_locals ;
2015-06-04 04:40:03 +00:00
while ( old_len > new_len ) {
2014-10-09 05:21:29 +00:00
pair < name , expr > entry = head ( old_entries ) ;
2014-10-11 22:33:31 +00:00
if ( is_local_ref ( entry . second ) )
2014-10-09 05:21:29 +00:00
to_redeclare . push_back ( entry ) ;
else if ( is_local ( entry . second ) )
popped_locals . insert ( mlocal_name ( entry . second ) ) ;
old_entries = tail ( old_entries ) ;
2015-06-04 04:40:03 +00:00
old_len - - ;
2014-10-09 05:21:29 +00:00
}
name_set popped_levels ;
list < pair < name , level > > new_level_entries = p . get_local_level_entries ( ) ;
while ( ! is_eqp ( old_level_entries , new_level_entries ) ) {
level const & l = head ( old_level_entries ) . second ;
if ( is_param ( l ) )
popped_levels . insert ( param_id ( l ) ) ;
old_level_entries = tail ( old_level_entries ) ;
}
for ( auto const & entry : to_redeclare ) {
2014-10-11 22:33:31 +00:00
expr new_ref = update_local_ref ( entry . second , popped_levels , popped_locals ) ;
2014-10-09 05:21:29 +00:00
if ( ! is_constant ( new_ref ) )
2015-04-22 05:40:20 +00:00
env = p . add_local_ref ( env , entry . first , new_ref ) ;
2014-10-09 05:21:29 +00:00
}
2015-04-22 05:40:20 +00:00
return env ;
2014-10-09 05:21:29 +00:00
}
2014-06-13 18:24:26 +00:00
environment end_scoped_cmd ( parser & p ) {
2014-10-09 05:21:29 +00:00
list < pair < name , level > > level_entries = p . get_local_level_entries ( ) ;
list < pair < name , expr > > entries = p . get_local_entries ( ) ;
2014-10-10 23:21:30 +00:00
p . pop_local_scope ( ) ;
2014-08-07 23:59:08 +00:00
if ( p . curr_is_identifier ( ) ) {
name n = p . check_atomic_id_next ( " invalid end of scope, atomic identifier expected " ) ;
2015-04-22 01:56:28 +00:00
environment env = pop_scope ( p . env ( ) , p . ios ( ) , n ) ;
2015-04-22 05:40:20 +00:00
return redeclare_aliases ( env , p , level_entries , entries ) ;
2014-08-07 23:59:08 +00:00
} else {
2015-04-22 01:56:28 +00:00
environment env = pop_scope ( p . env ( ) , p . ios ( ) ) ;
2015-04-22 05:40:20 +00:00
return redeclare_aliases ( env , p , level_entries , entries ) ;
2014-08-07 23:59:08 +00:00
}
2014-06-13 18:24:26 +00:00
}
2014-09-27 03:16:03 +00:00
environment check_cmd ( parser & p ) {
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-05-29 21:37:06 +00:00
e = expand_abbreviations ( p . env ( ) , e ) ;
2015-05-08 21:36:38 +00:00
auto tc = mk_type_checker ( p . env ( ) , p . mk_ngen ( ) ) ;
2014-09-27 03:16:03 +00:00
expr type = tc - > check ( e , ls ) . first ;
2014-07-10 17:32:00 +00:00
auto reg = p . regular_stream ( ) ;
2014-10-30 20:28:25 +00:00
formatter fmt = reg . get_formatter ( ) ;
2014-07-10 17:32:00 +00:00
options opts = p . ios ( ) . get_options ( ) ;
2015-01-13 21:02:14 +00:00
opts = opts . update_if_undef ( get_pp_metavar_args_name ( ) , true ) ;
2014-10-30 20:28:25 +00:00
fmt = fmt . update_options ( opts ) ;
2014-07-10 17:32:00 +00:00
unsigned indent = get_pp_indent ( opts ) ;
2014-08-24 16:35:25 +00:00
format r = group ( fmt ( e ) + space ( ) + colon ( ) + nest ( indent , line ( ) + fmt ( type ) ) ) ;
2014-11-24 16:35:49 +00:00
flycheck_information info ( p . regular_stream ( ) ) ;
if ( info . enabled ( ) ) {
p . display_information_pos ( p . cmd_pos ( ) ) ;
p . regular_stream ( ) < < " check result: \n " ;
}
2014-07-10 17:32:00 +00:00
reg < < mk_pair ( r , opts ) < < endl ;
2014-06-13 22:13:32 +00:00
return p . env ( ) ;
}
2014-09-27 03:16:03 +00:00
environment eval_cmd ( parser & p ) {
2014-11-10 20:46:04 +00:00
bool whnf = false ;
2014-11-08 04:39:50 +00:00
if ( p . curr_is_token ( get_whnf_tk ( ) ) ) {
p . next ( ) ;
whnf = true ;
}
2014-09-27 03:16:03 +00:00
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2014-11-08 04:39:50 +00:00
expr r ;
if ( whnf ) {
2015-05-08 21:36:38 +00:00
auto tc = mk_type_checker ( p . env ( ) , p . mk_ngen ( ) ) ;
2014-11-08 04:39:50 +00:00
r = tc - > whnf ( e ) . first ;
} else {
2015-05-09 18:49:55 +00:00
type_checker tc ( p . env ( ) ) ;
2015-05-21 02:09:44 +00:00
bool eta = false ;
bool eval_nested_prop = false ;
r = normalize ( tc , ls , e , eta , eval_nested_prop ) ;
2014-11-08 04:39:50 +00:00
}
2014-11-24 16:35:49 +00:00
flycheck_information info ( p . regular_stream ( ) ) ;
if ( info . enabled ( ) ) {
p . display_information_pos ( p . cmd_pos ( ) ) ;
p . regular_stream ( ) < < " eval result: \n " ;
}
2014-09-27 03:16:03 +00:00
p . regular_stream ( ) < < r < < endl ;
return p . env ( ) ;
}
2015-04-20 21:45:39 +00:00
environment exit_cmd ( parser & p ) {
flycheck_warning wrn ( p . regular_stream ( ) ) ;
p . display_warning_pos ( p . cmd_pos ( ) ) ;
p . regular_stream ( ) < < " using 'exit' to interrupt Lean " < < endl ;
2014-06-16 20:00:35 +00:00
throw interrupt_parser ( ) ;
}
2014-06-17 00:27:43 +00:00
environment set_option_cmd ( parser & p ) {
2015-07-13 23:13:41 +00:00
auto id_kind = parse_option_name ( p , " invalid set option, identifier (i.e., option name) expected " ) ;
name id = id_kind . first ;
option_kind k = id_kind . second ;
2014-06-17 00:27:43 +00:00
if ( k = = BoolOption ) {
2014-09-23 02:22:53 +00:00
if ( p . curr_is_token_or_id ( get_true_tk ( ) ) )
2014-06-17 00:27:43 +00:00
p . set_option ( id , true ) ;
2014-09-23 02:22:53 +00:00
else if ( p . curr_is_token_or_id ( get_false_tk ( ) ) )
2014-06-17 00:27:43 +00:00
p . set_option ( id , false ) ;
else
throw parser_error ( " invalid Boolean option value, 'true' or 'false' expected " , p . pos ( ) ) ;
p . next ( ) ;
} else if ( k = = StringOption ) {
if ( ! p . curr_is_string ( ) )
throw parser_error ( " invalid option value, given option is not a string " , p . pos ( ) ) ;
p . set_option ( id , p . get_str_val ( ) ) ;
p . next ( ) ;
} else if ( k = = DoubleOption ) {
p . set_option ( id , p . parse_double ( ) ) ;
} else if ( k = = UnsignedOption | | k = = IntOption ) {
p . set_option ( id , p . parse_small_nat ( ) ) ;
} else {
throw parser_error ( " invalid option value, 'true', 'false', string, integer or decimal value expected " , p . pos ( ) ) ;
}
p . updt_options ( ) ;
2014-10-30 21:45:35 +00:00
environment env = p . env ( ) ;
return update_fingerprint ( env , p . get_options ( ) . hash ( ) ) ;
2014-06-17 00:27:43 +00:00
}
2015-07-07 23:37:06 +00:00
static bool is_next_metaclass_tk ( parser const & p ) {
return p . curr_is_token ( get_lbracket_tk ( ) ) | | p . curr_is_token ( get_unfold_hints_bracket_tk ( ) ) ;
}
2015-12-28 17:57:45 +00:00
static optional < name > parse_metaclass ( parser & p ) {
2014-09-23 02:22:53 +00:00
if ( p . curr_is_token ( get_lbracket_tk ( ) ) ) {
2014-06-17 01:42:39 +00:00
p . next ( ) ;
2015-02-11 18:35:04 +00:00
auto pos = p . pos ( ) ;
2014-06-17 01:42:39 +00:00
name n ;
2015-02-11 18:35:04 +00:00
while ( ! p . curr_is_token ( get_rbracket_tk ( ) ) ) {
if ( p . curr_is_identifier ( ) )
n = n . append_after ( p . get_name_val ( ) . to_string ( ) . c_str ( ) ) ;
else if ( p . curr_is_keyword ( ) | | p . curr_is_command ( ) )
n = n . append_after ( p . get_token_info ( ) . value ( ) . to_string ( ) . c_str ( ) ) ;
else if ( p . curr_is_token ( get_sub_tk ( ) ) )
n = n . append_after ( " - " ) ;
else
throw parser_error ( " invalid 'open' command, identifier or symbol expected " , pos ) ;
p . next ( ) ;
}
2014-09-23 02:22:53 +00:00
p . check_token_next ( get_rbracket_tk ( ) , " invalid 'open' command, ']' expected " ) ;
2015-02-11 18:35:04 +00:00
if ( ! is_metaclass ( n ) & & n ! = get_decls_tk ( ) & & n ! = get_declarations_tk ( ) )
throw parser_error ( sstream ( ) < < " invalid metaclass name '[ " < < n < < " ]' " , pos ) ;
2015-12-28 17:57:45 +00:00
return optional < name > ( n ) ;
} else if ( p . curr ( ) = = scanner : : token_kind : : CommandKeyword ) {
name v = p . get_token_info ( ) . value ( ) ;
if ( v . is_atomic ( ) & & v . is_string ( ) & & v . size ( ) > 2 & & v . get_string ( ) [ 0 ] = = ' [ ' & & v . get_string ( ) [ v . size ( ) - 1 ] = = ' ] ' ) {
auto pos = p . pos ( ) ;
p . next ( ) ;
std : : string s ( v . get_string ( ) + 1 ) ;
s . pop_back ( ) ;
name n ( s ) ;
if ( ! is_metaclass ( n ) & & n ! = get_decls_tk ( ) & & n ! = get_declarations_tk ( ) )
throw parser_error ( sstream ( ) < < " invalid metaclass name '[ " < < n < < " ]' " , pos ) ;
return optional < name > ( n ) ;
}
2014-06-17 01:42:39 +00:00
}
2015-12-28 17:57:45 +00:00
return optional < name > ( ) ;
2014-06-17 01:42:39 +00:00
}
2015-02-11 19:02:59 +00:00
static void parse_metaclasses ( parser & p , buffer < name > & r ) {
if ( p . curr_is_token ( get_sub_tk ( ) ) ) {
p . next ( ) ;
buffer < name > tmp ;
get_metaclasses ( tmp ) ;
tmp . push_back ( get_decls_tk ( ) ) ;
2015-12-28 17:57:45 +00:00
while ( true ) {
if ( optional < name > m = parse_metaclass ( p ) ) {
tmp . erase_elem ( * m ) ;
if ( * m = = get_declarations_tk ( ) )
tmp . erase_elem ( get_decls_tk ( ) ) ;
} else {
break ;
}
2015-02-11 19:02:59 +00:00
}
r . append ( tmp ) ;
} else {
2015-12-28 17:57:45 +00:00
while ( true ) {
if ( optional < name > m = parse_metaclass ( p ) ) {
r . push_back ( * m ) ;
} else {
break ;
}
2015-02-11 19:02:59 +00:00
}
}
}
2014-06-17 01:42:39 +00:00
static void check_identifier ( parser & p , environment const & env , name const & ns , name const & id ) {
name full_id = ns + id ;
if ( ! env . find ( full_id ) )
2014-09-03 23:00:38 +00:00
throw parser_error ( sstream ( ) < < " invalid 'open' command, unknown declaration ' " < < full_id < < " ' " , p . pos ( ) ) ;
2014-06-17 01:42:39 +00:00
}
2014-09-04 01:37:01 +00:00
// add id as an abbreviation for d
2014-09-04 16:30:25 +00:00
static environment add_abbrev ( parser & p , environment const & env , name const & id , name const & d ) {
2014-09-04 01:37:01 +00:00
declaration decl = env . get ( d ) ;
buffer < level > ls ;
for ( name const & l : decl . get_univ_params ( ) )
ls . push_back ( mk_param_univ ( l ) ) ;
expr value = mk_constant ( d , to_list ( ls . begin ( ) , ls . end ( ) ) ) ;
name const & ns = get_namespace ( env ) ;
name full_id = ns + id ;
2014-09-04 16:30:25 +00:00
p . add_abbrev_index ( full_id , d ) ;
2015-01-20 20:36:56 +00:00
environment new_env =
2015-05-08 22:42:42 +00:00
module : : add ( env , check ( env , mk_definition ( env , full_id , decl . get_univ_params ( ) , decl . get_type ( ) , value ) ) ) ;
2014-09-04 01:37:01 +00:00
if ( full_id ! = id )
new_env = add_expr_alias_rec ( new_env , id , full_id ) ;
return new_env ;
}
// open/export [class] id (as id)? (id ...) (renaming id->id id->id) (hiding id ... id)
environment open_export_cmd ( parser & p , bool open ) {
2014-06-17 01:42:39 +00:00
environment env = p . env ( ) ;
2015-05-13 22:33:48 +00:00
unsigned fingerprint = 0 ;
2014-07-07 21:53:06 +00:00
while ( true ) {
2015-02-11 19:02:59 +00:00
buffer < name > metacls ;
parse_metaclasses ( p , metacls ) ;
bool decls = false ;
if ( metacls . empty ( ) | |
std : : find ( metacls . begin ( ) , metacls . end ( ) , get_decls_tk ( ) ) ! = metacls . end ( ) | |
std : : find ( metacls . begin ( ) , metacls . end ( ) , get_declarations_tk ( ) ) ! = metacls . end ( ) )
decls = true ;
2015-05-13 22:33:48 +00:00
for ( name const & n : metacls )
fingerprint = hash ( fingerprint , n . hash ( ) ) ;
2014-07-08 01:17:10 +00:00
auto pos = p . pos ( ) ;
2014-09-04 01:37:01 +00:00
name ns = p . check_id_next ( " invalid 'open/export' command, identifier expected " ) ;
2014-07-08 01:17:10 +00:00
optional < name > real_ns = to_valid_namespace_name ( env , ns ) ;
if ( ! real_ns )
throw parser_error ( sstream ( ) < < " invalid namespace name ' " < < ns < < " ' " , pos ) ;
ns = * real_ns ;
2015-05-20 18:42:16 +00:00
fingerprint = hash ( fingerprint , ns . hash ( ) ) ;
2014-09-04 00:37:02 +00:00
name as ;
2014-09-23 02:22:53 +00:00
if ( p . curr_is_token_or_id ( get_as_tk ( ) ) ) {
2014-09-04 00:37:02 +00:00
p . next ( ) ;
2014-09-04 01:37:01 +00:00
as = p . check_id_next ( " invalid 'open/export' command, identifier expected " ) ;
2014-09-04 00:37:02 +00:00
}
2014-09-04 01:37:01 +00:00
if ( open )
2015-02-11 19:02:59 +00:00
env = using_namespace ( env , p . ios ( ) , ns , metacls ) ;
2014-09-04 01:37:01 +00:00
else
2015-02-11 19:02:59 +00:00
env = export_namespace ( env , p . ios ( ) , ns , metacls ) ;
2014-07-07 21:53:06 +00:00
if ( decls ) {
// Remark: we currently to not allow renaming and hiding of universe levels
buffer < name > exceptions ;
bool found_explicit = false ;
2014-09-23 02:22:53 +00:00
while ( p . curr_is_token ( get_lparen_tk ( ) ) ) {
2014-06-17 01:42:39 +00:00
p . next ( ) ;
2014-09-23 02:22:53 +00:00
if ( p . curr_is_token_or_id ( get_renaming_tk ( ) ) ) {
2014-06-17 01:42:39 +00:00
p . next ( ) ;
2014-07-07 21:53:06 +00:00
while ( p . curr_is_identifier ( ) ) {
name from_id = p . get_name_val ( ) ;
p . next ( ) ;
2014-09-23 02:22:53 +00:00
p . check_token_next ( get_arrow_tk ( ) , " invalid 'open/export' command renaming, '->' expected " ) ;
2014-09-04 01:37:01 +00:00
name to_id = p . check_id_next ( " invalid 'open/export' command renaming, identifier expected " ) ;
2015-05-13 22:33:48 +00:00
fingerprint = hash ( hash ( fingerprint , from_id . hash ( ) ) , to_id . hash ( ) ) ;
2014-07-07 21:53:06 +00:00
check_identifier ( p , env , ns , from_id ) ;
exceptions . push_back ( from_id ) ;
2014-09-04 01:37:01 +00:00
if ( open )
env = add_expr_alias ( env , as + to_id , ns + from_id ) ;
else
2014-09-04 16:30:25 +00:00
env = add_abbrev ( p , env , as + to_id , ns + from_id ) ;
2014-07-07 21:53:06 +00:00
}
2014-09-23 02:22:53 +00:00
} else if ( p . curr_is_token_or_id ( get_hiding_tk ( ) ) ) {
2014-06-17 01:42:39 +00:00
p . next ( ) ;
2014-07-07 21:53:06 +00:00
while ( p . curr_is_identifier ( ) ) {
name id = p . get_name_val ( ) ;
p . next ( ) ;
check_identifier ( p , env , ns , id ) ;
exceptions . push_back ( id ) ;
2015-05-13 22:33:48 +00:00
fingerprint = hash ( fingerprint , id . hash ( ) ) ;
2014-07-07 21:53:06 +00:00
}
} else if ( p . curr_is_identifier ( ) ) {
found_explicit = true ;
while ( p . curr_is_identifier ( ) ) {
name id = p . get_name_val ( ) ;
p . next ( ) ;
2015-05-13 22:33:48 +00:00
fingerprint = hash ( fingerprint , id . hash ( ) ) ;
2014-07-07 21:53:06 +00:00
check_identifier ( p , env , ns , id ) ;
2014-09-04 01:37:01 +00:00
if ( open )
env = add_expr_alias ( env , as + id , ns + id ) ;
else
2014-09-04 16:30:25 +00:00
env = add_abbrev ( p , env , as + id , ns + id ) ;
2014-07-07 21:53:06 +00:00
}
} else {
2014-10-23 17:24:03 +00:00
throw parser_error ( " invalid 'open/export' command option, "
" identifier, 'hiding' or 'renaming' expected " , p . pos ( ) ) ;
2014-06-17 01:42:39 +00:00
}
2014-07-07 21:53:06 +00:00
if ( found_explicit & & ! exceptions . empty ( ) )
2014-10-23 17:24:03 +00:00
throw parser_error ( " invalid 'open/export' command option, "
" mixing explicit and implicit 'open/export' options " , p . pos ( ) ) ;
2014-09-23 02:22:53 +00:00
p . check_token_next ( get_rparen_tk ( ) , " invalid 'open/export' command option, ')' expected " ) ;
2014-09-04 01:37:01 +00:00
}
if ( ! found_explicit ) {
if ( open ) {
env = add_aliases ( env , ns , as , exceptions . size ( ) , exceptions . data ( ) ) ;
} else {
environment new_env = env ;
env . for_each_declaration ( [ & ] ( declaration const & d ) {
if ( ! is_protected ( env , d . get_name ( ) ) & &
is_prefix_of ( ns , d . get_name ( ) ) & &
! is_exception ( d . get_name ( ) , ns , exceptions . size ( ) , exceptions . data ( ) ) ) {
name new_id = d . get_name ( ) . replace_prefix ( ns , as ) ;
if ( ! new_id . is_anonymous ( ) )
2014-09-04 16:30:25 +00:00
new_env = add_abbrev ( p , new_env , new_id , d . get_name ( ) ) ;
2014-09-04 01:37:01 +00:00
}
} ) ;
env = new_env ;
}
2014-06-17 01:42:39 +00:00
}
}
2015-07-07 23:37:06 +00:00
if ( ! is_next_metaclass_tk ( p ) & & ! p . curr_is_identifier ( ) )
2014-07-07 21:53:06 +00:00
break ;
2014-06-17 01:42:39 +00:00
}
2015-05-13 22:33:48 +00:00
return update_fingerprint ( env , fingerprint ) ;
2014-06-17 01:42:39 +00:00
}
2015-05-20 18:42:16 +00:00
static environment open_cmd ( parser & p ) { return open_export_cmd ( p , true ) ; }
static environment export_cmd ( parser & p ) { return open_export_cmd ( p , false ) ; }
static environment override_cmd ( parser & p ) {
environment env = p . env ( ) ;
while ( p . curr_is_identifier ( ) ) {
auto pos = p . pos ( ) ;
name ns = p . check_id_next ( " invalid 'override' command, identifier expected " ) ;
optional < name > real_ns = to_valid_namespace_name ( env , ns ) ;
if ( ! real_ns )
throw parser_error ( sstream ( ) < < " invalid namespace name ' " < < ns < < " ' " , pos ) ;
ns = * real_ns ;
bool persistent = false ;
env = override_notation ( env , ns , persistent ) ;
2015-06-14 22:48:36 +00:00
env = overwrite_aliases ( env , ns , name ( ) ) ;
2015-05-20 18:42:16 +00:00
env = update_fingerprint ( env , ns . hash ( ) ) ;
}
return env ;
}
2014-06-17 01:42:39 +00:00
2015-05-20 18:42:16 +00:00
static environment erase_cache_cmd ( parser & p ) {
2014-08-11 20:55:29 +00:00
name n = p . check_id_next ( " invalid #erase_cache command, identifier expected " ) ;
p . erase_cached_definition ( n ) ;
return p . env ( ) ;
}
2015-05-20 18:42:16 +00:00
static environment projections_cmd ( parser & p ) {
2014-10-29 19:50:52 +00:00
name n = p . check_id_next ( " invalid #projections command, identifier expected " ) ;
if ( p . curr_is_token ( get_dcolon_tk ( ) ) ) {
p . next ( ) ;
buffer < name > proj_names ;
while ( p . curr_is_identifier ( ) ) {
proj_names . push_back ( n + p . get_name_val ( ) ) ;
p . next ( ) ;
}
return mk_projections ( p . env ( ) , n , proj_names ) ;
} else {
return mk_projections ( p . env ( ) , n ) ;
}
}
2015-05-20 18:42:16 +00:00
static environment telescope_eq_cmd ( parser & p ) {
2014-12-08 02:17:15 +00:00
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
buffer < expr > t ;
while ( is_pi ( e ) ) {
expr local = mk_local ( p . mk_fresh_name ( ) , binding_name ( e ) , binding_domain ( e ) , binder_info ( ) ) ;
t . push_back ( local ) ;
e = instantiate ( binding_body ( e ) , local ) ;
}
2015-05-08 21:36:38 +00:00
auto tc = mk_type_checker ( p . env ( ) , p . mk_ngen ( ) ) ;
2014-12-08 02:17:15 +00:00
buffer < expr > eqs ;
mk_telescopic_eq ( * tc , t , eqs ) ;
for ( expr const & eq : eqs ) {
regular ( p . env ( ) , p . ios ( ) ) < < local_pp_name ( eq ) < < " : " < < mlocal_type ( eq ) < < " \n " ;
tc - > check ( mlocal_type ( eq ) , ls ) ;
}
return p . env ( ) ;
}
2015-05-20 18:42:16 +00:00
static environment local_cmd ( parser & p ) {
2015-01-26 19:31:12 +00:00
if ( p . curr_is_token_or_id ( get_attribute_tk ( ) ) ) {
p . next ( ) ;
return local_attribute_cmd ( p ) ;
2015-02-11 01:31:40 +00:00
} else if ( p . curr_is_token ( get_abbreviation_tk ( ) ) ) {
p . next ( ) ;
return local_abbreviation_cmd ( p ) ;
2015-01-26 19:31:12 +00:00
} else {
return local_notation_cmd ( p ) ;
}
}
2015-03-06 21:03:30 +00:00
static environment help_cmd ( parser & p ) {
flycheck_information info ( p . regular_stream ( ) ) ;
if ( info . enabled ( ) ) {
p . display_information_pos ( p . cmd_pos ( ) ) ;
p . regular_stream ( ) < < " help result: \n " ;
}
if ( p . curr_is_token_or_id ( get_options_tk ( ) ) ) {
p . next ( ) ;
for ( auto odecl : get_option_declarations ( ) ) {
auto opt = odecl . second ;
regular ( p . env ( ) , p . ios ( ) )
< < " " < < opt . get_name ( ) < < " ( " < < opt . kind ( ) < < " ) "
< < opt . get_description ( ) < < " (default: " < < opt . get_default_value ( ) < < " ) " < < endl ;
}
} else if ( p . curr_is_token_or_id ( get_commands_tk ( ) ) ) {
p . next ( ) ;
buffer < name > ns ;
cmd_table const & cmds = p . cmds ( ) ;
cmds . for_each ( [ & ] ( name const & n , cmd_info const & ) {
ns . push_back ( n ) ;
} ) ;
std : : sort ( ns . begin ( ) , ns . end ( ) ) ;
for ( name const & n : ns ) {
regular ( p . env ( ) , p . ios ( ) )
< < " " < < n < < " : " < < cmds . find ( n ) - > get_descr ( ) < < endl ;
} ;
} else {
p . regular_stream ( )
< < " help options : describe available options \n "
< < " help commands : describe available commands \n " ;
}
return p . env ( ) ;
}
2015-05-20 18:42:16 +00:00
static environment init_quotient_cmd ( parser & p ) {
2015-04-23 22:27:56 +00:00
if ( ! ( p . env ( ) . prop_proof_irrel ( ) & & p . env ( ) . impredicative ( ) ) )
throw parser_error ( " invalid init_quotient command, this command is only available for kernels containing an impredicative and proof irrelevant Prop " , p . cmd_pos ( ) ) ;
2015-04-01 04:45:11 +00:00
return module : : declare_quotient ( p . env ( ) ) ;
}
2015-05-20 18:42:16 +00:00
static environment init_hits_cmd ( parser & p ) {
2015-04-23 22:27:56 +00:00
if ( p . env ( ) . prop_proof_irrel ( ) | | p . env ( ) . impredicative ( ) )
throw parser_error ( " invalid init_hits command, this command is only available for proof relevant and predicative kernels " , p . cmd_pos ( ) ) ;
return module : : declare_hits ( p . env ( ) ) ;
}
2015-09-11 17:49:07 +00:00
static environment compile_cmd ( parser & p ) {
name n = p . check_constant_next ( " invalid #compile command, constant expected " ) ;
declaration d = p . env ( ) . get ( n ) ;
2015-09-12 00:12:32 +00:00
buffer < name > aux_decls ;
preprocess_rec ( p . env ( ) , d , aux_decls ) ;
2015-09-11 17:49:07 +00:00
return p . env ( ) ;
}
2015-10-01 01:50:28 +00:00
static environment accessible_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
unsigned total = 0 ;
unsigned accessible = 0 ;
unsigned accessible_theorems = 0 ;
env . for_each_declaration ( [ & ] ( declaration const & d ) {
name const & n = d . get_name ( ) ;
total + + ;
if ( ( d . is_theorem ( ) | | d . is_definition ( ) ) & &
! is_instance ( env , n ) & & ! is_simp_rule ( env , n ) & & ! is_congr_rule ( env , n ) & &
! is_user_defined_recursor ( env , n ) & & ! is_aux_recursor ( env , n ) & &
! is_projection ( env , n ) & & ! is_private ( env , n ) & &
! is_user_defined_recursor ( env , n ) & & ! is_aux_recursor ( env , n ) & &
! is_subst_relation ( env , n ) & & ! is_trans_relation ( env , n ) & &
! is_symm_relation ( env , n ) & & ! is_refl_relation ( env , n ) ) {
accessible + + ;
if ( d . is_theorem ( ) )
accessible_theorems + + ;
}
} ) ;
p . regular_stream ( ) < < " total: " < < total < < " , accessible: " < < accessible < < " , accessible theorems: " < < accessible_theorems < < " \n " ;
return env ;
}
2015-10-15 01:36:41 +00:00
static void display_name_set ( parser & p , name const & n , name_set const & s ) {
if ( s . empty ( ) )
return ;
io_state_stream out = p . regular_stream ( ) ;
out < < " " < < n < < " := { " ;
bool first = true ;
s . for_each ( [ & ] ( name const & n2 ) {
if ( is_private ( p . env ( ) , n2 ) )
return ;
if ( first )
first = false ;
else
out < < " , " ;
out < < n2 ;
} ) ;
out < < " } \n " ;
}
static environment decl_stats_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
2015-10-15 02:34:53 +00:00
io_state_stream out = p . regular_stream ( ) ;
out < < " Use sets \n " ;
2015-10-15 01:36:41 +00:00
env . for_each_declaration ( [ & ] ( declaration const & d ) {
if ( ( d . is_theorem ( ) | | d . is_axiom ( ) ) & & ! is_private ( env , d . get_name ( ) ) )
display_name_set ( p , d . get_name ( ) , get_use_set ( env , d . get_name ( ) ) ) ;
} ) ;
2015-10-15 02:34:53 +00:00
out < < " Used-by sets \n " ;
2015-10-15 01:36:41 +00:00
env . for_each_declaration ( [ & ] ( declaration const & d ) {
if ( ! d . is_theorem ( ) & & ! d . is_axiom ( ) & & ! is_private ( env , d . get_name ( ) ) )
display_name_set ( p , d . get_name ( ) , get_used_by_set ( env , d . get_name ( ) ) ) ;
} ) ;
return env ;
}
2015-10-15 02:34:53 +00:00
static environment relevant_thms_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
name_set R ;
while ( p . curr_is_identifier ( ) ) {
R . insert ( p . check_constant_next ( " invalid #relevant_thms command, constant expected " ) ) ;
}
name_set TS = get_relevant_thms ( env , p . get_options ( ) , R ) ;
io_state_stream out = p . regular_stream ( ) ;
TS . for_each ( [ & ] ( name const & T ) {
2015-10-15 03:46:03 +00:00
out < < T < < " \n " ;
2015-10-15 02:34:53 +00:00
} ) ;
return env ;
}
2015-11-02 01:19:57 +00:00
static void check_expr_and_print ( parser & p , expr const & e ) {
environment const & env = p . env ( ) ;
type_checker tc ( env ) ;
expr t = tc . check_ignore_undefined_universes ( e ) . first ;
p . regular_stream ( ) < < e < < " : " < < t < < " \n " ;
}
2015-11-01 17:59:37 +00:00
static environment app_builder_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
2015-11-01 20:02:49 +00:00
auto pos = p . pos ( ) ;
app_builder b ( env ) ;
2015-11-01 17:59:37 +00:00
name c = p . check_constant_next ( " invalid #app_builder command, constant expected " ) ;
2015-11-02 01:19:57 +00:00
bool has_mask = false ;
buffer < bool > mask ;
2015-11-02 03:27:25 +00:00
if ( p . curr_is_token ( get_lbracket_tk ( ) ) ) {
2015-11-02 01:19:57 +00:00
p . next ( ) ;
has_mask = true ;
while ( true ) {
name flag = p . check_constant_next ( " invalid #app_builder command, constant (true, false) expected " ) ;
mask . push_back ( flag = = get_true_name ( ) ) ;
if ( ! p . curr_is_token ( get_comma_tk ( ) ) )
break ;
p . next ( ) ;
}
2015-11-02 03:27:25 +00:00
p . check_token_next ( get_rbracket_tk ( ) , " invalid #app_builder command, ']' expected " ) ;
2015-11-02 01:19:57 +00:00
}
2015-11-01 17:59:37 +00:00
buffer < expr > args ;
while ( true ) {
2015-11-01 20:02:49 +00:00
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
args . push_back ( e ) ;
2015-11-01 17:59:37 +00:00
if ( ! p . curr_is_token ( get_comma_tk ( ) ) )
break ;
p . next ( ) ;
}
2015-11-02 01:19:57 +00:00
if ( has_mask & & args . size ( ) > mask . size ( ) )
throw parser_error ( sstream ( ) < < " invalid #app_builder command, too many arguments " , pos ) ;
optional < expr > r ;
if ( has_mask )
r = b . mk_app ( c , mask . size ( ) , mask . data ( ) , args . data ( ) ) ;
else
r = b . mk_app ( c , args . size ( ) , args . data ( ) ) ;
if ( r ) {
check_expr_and_print ( p , * r ) ;
2015-11-01 17:59:37 +00:00
} else {
2015-11-01 20:02:49 +00:00
throw parser_error ( sstream ( ) < < " failed to build application for ' " < < c < < " ' " , pos ) ;
2015-11-01 17:59:37 +00:00
}
2015-11-02 01:19:57 +00:00
return env ;
}
static environment refl_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
auto pos = p . pos ( ) ;
app_builder b ( env ) ;
name relname = p . check_constant_next ( " invalid #refl command, constant expected " ) ;
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-11-08 21:05:41 +00:00
try {
expr r = b . mk_refl ( relname , e ) ;
check_expr_and_print ( p , r ) ;
} catch ( app_builder_exception & ) {
2015-11-02 01:19:57 +00:00
throw parser_error ( sstream ( ) < < " failed to build refl proof " , pos ) ;
}
return env ;
}
static environment symm_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
auto pos = p . pos ( ) ;
app_builder b ( env ) ;
name relname = p . check_constant_next ( " invalid #symm command, constant expected " ) ;
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-11-08 21:05:41 +00:00
try {
expr r = b . mk_symm ( relname , e ) ;
check_expr_and_print ( p , r ) ;
} catch ( app_builder_exception & ) {
2015-11-02 01:19:57 +00:00
throw parser_error ( sstream ( ) < < " failed to build symm proof " , pos ) ;
}
return env ;
}
static environment trans_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
auto pos = p . pos ( ) ;
app_builder b ( env ) ;
name relname = p . check_constant_next ( " invalid #trans command, constant expected " ) ;
expr H1 , H2 ; level_param_names ls ;
std : : tie ( H1 , ls ) = parse_local_expr ( p ) ;
p . check_token_next ( get_comma_tk ( ) , " invalid #trans command, ',' expected " ) ;
std : : tie ( H2 , ls ) = parse_local_expr ( p ) ;
2015-11-08 21:05:41 +00:00
try {
expr r = b . mk_trans ( relname , H1 , H2 ) ;
check_expr_and_print ( p , r ) ;
} catch ( app_builder_exception & ) {
2015-11-02 01:19:57 +00:00
throw parser_error ( sstream ( ) < < " failed to build trans proof " , pos ) ;
}
2015-11-01 17:59:37 +00:00
return env ;
}
2015-11-06 06:02:00 +00:00
static void parse_expr_vector ( parser & p , buffer < expr > & r ) {
p . check_token_next ( get_lbracket_tk ( ) , " invalid command, '[' expected " ) ;
while ( true ) {
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
r . push_back ( e ) ;
if ( ! p . curr_is_token ( get_comma_tk ( ) ) )
break ;
p . next ( ) ;
}
p . check_token_next ( get_rbracket_tk ( ) , " invalid command, ']' expected " ) ;
}
static environment replace_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
auto pos = p . pos ( ) ;
expr e ; level_param_names ls ;
buffer < expr > from ;
buffer < expr > to ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
p . check_token_next ( get_comma_tk ( ) , " invalid #replace command, ',' expected " ) ;
parse_expr_vector ( p , from ) ;
p . check_token_next ( get_comma_tk ( ) , " invalid #replace command, ',' expected " ) ;
parse_expr_vector ( p , to ) ;
if ( from . size ( ) ! = to . size ( ) )
throw parser_error ( " invalid #replace command, from/to vectors have different size " , pos ) ;
2015-12-08 22:58:08 +00:00
tmp_type_context ctx ( env , p . get_options ( ) ) ;
2015-11-06 06:02:00 +00:00
fun_info_manager infom ( ctx ) ;
auto r = replace ( infom , e , from , to ) ;
if ( ! r )
throw parser_error ( " #replace commad failed " , pos ) ;
p . regular_stream ( ) < < * r < < " \n " ;
return env ;
}
2015-11-17 23:43:10 +00:00
enum class congr_kind { Simp , Default , Rel } ;
static environment congr_cmd_core ( parser & p , congr_kind kind ) {
2015-11-07 03:13:11 +00:00
environment const & env = p . env ( ) ;
auto pos = p . pos ( ) ;
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-12-08 22:58:08 +00:00
tmp_type_context ctx ( env , p . get_options ( ) ) ;
2015-11-07 03:13:11 +00:00
app_builder b ( ctx ) ;
fun_info_manager infom ( ctx ) ;
congr_lemma_manager cm ( b , infom ) ;
2015-11-17 23:43:10 +00:00
optional < congr_lemma > r ;
switch ( kind ) {
case congr_kind : : Simp : r = cm . mk_congr_simp ( e ) ; break ;
case congr_kind : : Default : r = cm . mk_congr ( e ) ; break ;
case congr_kind : : Rel : r = cm . mk_rel_iff_congr ( e ) ; break ;
}
2015-11-07 03:13:11 +00:00
if ( ! r )
throw parser_error ( " failed to generated congruence lemma " , pos ) ;
2015-11-07 20:55:50 +00:00
auto out = p . regular_stream ( ) ;
out < < " [ " ;
bool first = true ;
for ( auto k : r - > get_arg_kinds ( ) ) {
if ( ! first ) out < < " , " ; else first = false ;
switch ( k ) {
2015-11-08 01:24:17 +00:00
case congr_arg_kind : : Fixed : out < < " fixed " ; break ;
case congr_arg_kind : : Eq : out < < " eq " ; break ;
case congr_arg_kind : : Cast : out < < " cast " ; break ;
2015-11-07 20:55:50 +00:00
}
}
out < < " ] \n " ;
out < < r - > get_proof ( ) < < " \n : \n " < < r - > get_type ( ) < < " \n " ; ;
2015-11-07 03:13:11 +00:00
type_checker tc ( env ) ;
2015-11-07 20:06:42 +00:00
expr type = tc . check ( r - > get_proof ( ) , ls ) . first ;
if ( ! tc . is_def_eq ( type , r - > get_type ( ) ) . first )
throw parser_error ( " congruence lemma reported type does not match given type " , pos ) ;
2015-11-07 03:13:11 +00:00
return env ;
}
2015-11-13 02:55:25 +00:00
static environment congr_simp_cmd ( parser & p ) {
2015-11-17 23:43:10 +00:00
return congr_cmd_core ( p , congr_kind : : Simp ) ;
2015-11-13 02:55:25 +00:00
}
static environment congr_cmd ( parser & p ) {
2015-11-17 23:43:10 +00:00
return congr_cmd_core ( p , congr_kind : : Default ) ;
}
static environment congr_rel_cmd ( parser & p ) {
return congr_cmd_core ( p , congr_kind : : Rel ) ;
2015-11-13 02:55:25 +00:00
}
2015-11-05 05:53:12 +00:00
static environment simplify_cmd ( parser & p ) {
name rel = p . check_constant_next ( " invalid #simplify command, constant expected " ) ;
2015-11-16 16:54:21 +00:00
name ns = p . check_id_next ( " invalid #simplify command, id expected " ) ;
2015-11-05 05:53:12 +00:00
unsigned o = p . parse_small_nat ( ) ;
2015-11-07 23:28:18 +00:00
2015-11-05 05:53:12 +00:00
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-11-07 23:28:18 +00:00
blast : : scope_debug scope ( p . env ( ) , p . ios ( ) ) ;
2015-11-16 16:54:21 +00:00
simp_rule_sets srss ;
2015-11-17 00:10:01 +00:00
if ( ns = = name ( " null " ) ) {
} else if ( ns = = name ( " env " ) ) {
srss = get_simp_rule_sets ( p . env ( ) ) ;
} else {
2015-12-08 22:58:08 +00:00
srss = get_simp_rule_sets ( p . env ( ) , p . get_options ( ) , ns ) ;
2015-11-17 00:10:01 +00:00
}
2015-11-16 16:54:21 +00:00
blast : : simp : : result r = blast : : simplify ( rel , e , srss ) ;
2015-11-05 05:53:12 +00:00
flycheck_information info ( p . regular_stream ( ) ) ;
if ( info . enabled ( ) ) {
p . display_information_pos ( p . cmd_pos ( ) ) ;
p . regular_stream ( ) < < " simplify result: \n " ;
}
2015-11-16 16:54:21 +00:00
if ( ! r . has_proof ( ) ) {
p . regular_stream ( ) < < " (refl): " < < r . get_new ( ) < < endl ;
2015-11-07 23:28:18 +00:00
} else {
2015-11-05 05:53:12 +00:00
auto tc = mk_type_checker ( p . env ( ) , p . mk_ngen ( ) ) ;
2015-11-07 23:28:18 +00:00
2015-11-05 05:53:12 +00:00
expr pf_type = tc - > check ( r . get_proof ( ) , ls ) . first ;
if ( o = = 0 ) p . regular_stream ( ) < < r . get_new ( ) < < endl ;
else if ( o = = 1 ) p . regular_stream ( ) < < r . get_proof ( ) < < endl ;
else p . regular_stream ( ) < < pf_type < < endl ;
}
return p . env ( ) ;
}
2015-11-13 04:31:36 +00:00
static environment normalizer_cmd ( parser & p ) {
environment const & env = p . env ( ) ;
expr e ; level_param_names ls ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
2015-11-13 04:38:54 +00:00
blast : : scope_debug scope ( p . env ( ) , p . ios ( ) ) ;
expr r = blast : : normalize ( e ) ;
2015-11-13 04:31:36 +00:00
p . regular_stream ( ) < < r < < endl ;
return env ;
}
2015-11-13 00:30:22 +00:00
static environment abstract_expr_cmd ( parser & p ) {
unsigned o = p . parse_small_nat ( ) ;
2015-12-08 22:58:08 +00:00
default_type_context ctx ( p . env ( ) , p . get_options ( ) ) ;
app_builder builder ( p . env ( ) , p . get_options ( ) ) ;
2015-11-13 00:30:22 +00:00
fun_info_manager fun_info ( ctx ) ;
2015-12-03 22:33:11 +00:00
congr_lemma_manager congr_lemma ( builder , fun_info ) ;
2015-12-03 22:59:31 +00:00
abstract_expr_manager ae_manager ( congr_lemma ) ;
2015-11-13 00:30:22 +00:00
flycheck_information info ( p . regular_stream ( ) ) ;
if ( info . enabled ( ) ) p . display_information_pos ( p . cmd_pos ( ) ) ;
expr e , a , b ;
level_param_names ls , ls1 , ls2 ;
2015-11-13 01:08:29 +00:00
if ( o = = 0 ) {
// hash
2015-11-13 00:30:22 +00:00
if ( info . enabled ( ) ) p . regular_stream ( ) < < " abstract hash: " < < endl ;
std : : tie ( e , ls ) = parse_local_expr ( p ) ;
p . regular_stream ( ) < < ae_manager . hash ( e ) < < endl ;
2015-11-13 01:08:29 +00:00
} else {
// is_equal
2015-11-13 00:30:22 +00:00
if ( info . enabled ( ) ) p . regular_stream ( ) < < " abstract is_equal: " < < endl ;
std : : tie ( a , ls1 ) = parse_local_expr ( p ) ;
p . check_token_next ( get_comma_tk ( ) , " invalid #abstract_expr command, ',' expected " ) ;
std : : tie ( b , ls2 ) = parse_local_expr ( p ) ;
p . regular_stream ( ) < < ae_manager . is_equal ( a , b ) < < endl ;
}
return p . env ( ) ;
}
2014-09-23 17:00:36 +00:00
void init_cmd_table ( cmd_table & r ) {
2015-11-02 01:19:57 +00:00
add_cmd ( r , cmd_info ( " open " , " create aliases for declarations, and use objects defined in other namespaces " ,
2014-10-29 19:50:52 +00:00
open_cmd ) ) ;
2015-11-02 01:19:57 +00:00
add_cmd ( r , cmd_info ( " export " , " create abbreviations for declarations, "
2014-10-29 19:50:52 +00:00
" and export objects defined in other namespaces " , export_cmd ) ) ;
2015-11-02 01:19:57 +00:00
add_cmd ( r , cmd_info ( " override " , " override notation declarations using the ones defined in the given namespace " ,
2015-05-20 18:42:16 +00:00
override_cmd ) ) ;
2015-11-02 01:19:57 +00:00
add_cmd ( r , cmd_info ( " set_option " , " set configuration option " , set_option_cmd ) ) ;
add_cmd ( r , cmd_info ( " exit " , " exit " , exit_cmd ) ) ;
add_cmd ( r , cmd_info ( " print " , " print a string " , print_cmd ) ) ;
add_cmd ( r , cmd_info ( " section " , " open a new section " , section_cmd ) ) ;
add_cmd ( r , cmd_info ( " namespace " , " open a new namespace " , namespace_cmd ) ) ;
add_cmd ( r , cmd_info ( " end " , " close the current namespace/section " , end_scoped_cmd ) ) ;
add_cmd ( r , cmd_info ( " check " , " type check given expression, and display its type " , check_cmd ) ) ;
add_cmd ( r , cmd_info ( " eval " , " evaluate given expression " , eval_cmd ) ) ;
add_cmd ( r , cmd_info ( " find_decl " , " find definitions and/or theorems " , find_cmd ) ) ;
add_cmd ( r , cmd_info ( " local " , " define local attributes or notation " , local_cmd ) ) ;
add_cmd ( r , cmd_info ( " help " , " brief description of available commands and options " , help_cmd ) ) ;
add_cmd ( r , cmd_info ( " init_quotient " , " initialize quotient type computational rules " , init_quotient_cmd ) ) ;
add_cmd ( r , cmd_info ( " init_hits " , " initialize builtin HITs " , init_hits_cmd ) ) ;
add_cmd ( r , cmd_info ( " #erase_cache " , " erase cached definition (for debugging purposes) " , erase_cache_cmd ) ) ;
add_cmd ( r , cmd_info ( " #projections " , " generate projections for inductive datatype (for debugging purposes) " , projections_cmd ) ) ;
add_cmd ( r , cmd_info ( " #telescope_eq " , " (for debugging purposes) " , telescope_eq_cmd ) ) ;
add_cmd ( r , cmd_info ( " #app_builder " , " (for debugging purposes) " , app_builder_cmd ) ) ;
add_cmd ( r , cmd_info ( " #refl " , " (for debugging purposes) " , refl_cmd ) ) ;
add_cmd ( r , cmd_info ( " #trans " , " (for debugging purposes) " , trans_cmd ) ) ;
add_cmd ( r , cmd_info ( " #symm " , " (for debugging purposes) " , symm_cmd ) ) ;
add_cmd ( r , cmd_info ( " #compile " , " (for debugging purposes) " , compile_cmd ) ) ;
2015-11-06 06:02:00 +00:00
add_cmd ( r , cmd_info ( " #replace " , " (for debugging purposes) " , replace_cmd ) ) ;
2015-11-13 02:55:25 +00:00
add_cmd ( r , cmd_info ( " #congr " , " (for debugging purposes) " , congr_cmd ) ) ;
add_cmd ( r , cmd_info ( " #congr_simp " , " (for debugging purposes) " , congr_simp_cmd ) ) ;
2015-11-17 23:43:10 +00:00
add_cmd ( r , cmd_info ( " #congr_rel " , " (for debugging purposes) " , congr_rel_cmd ) ) ;
2015-11-13 04:31:36 +00:00
add_cmd ( r , cmd_info ( " #normalizer " , " (for debugging purposes) " , normalizer_cmd ) ) ;
2015-11-02 01:19:57 +00:00
add_cmd ( r , cmd_info ( " #accessible " , " (for debugging purposes) display number of accessible declarations for blast tactic " , accessible_cmd ) ) ;
add_cmd ( r , cmd_info ( " #decl_stats " , " (for debugging purposes) display declaration statistics " , decl_stats_cmd ) ) ;
add_cmd ( r , cmd_info ( " #relevant_thms " , " (for debugging purposes) select relevant theorems using Meng&Paulson heuristic " , relevant_thms_cmd ) ) ;
2015-11-07 23:28:18 +00:00
add_cmd ( r , cmd_info ( " #simplify " , " (for debugging purposes) simplify given expression " , simplify_cmd ) ) ;
2015-11-13 00:30:22 +00:00
add_cmd ( r , cmd_info ( " #abstract_expr " , " (for debugging purposes) call abstract expr methods " , abstract_expr_cmd ) ) ;
2015-10-15 01:36:41 +00:00
2014-06-18 17:36:21 +00:00
register_decl_cmds ( r ) ;
2014-06-18 20:55:48 +00:00
register_inductive_cmd ( r ) ;
2014-07-29 02:04:57 +00:00
register_structure_cmd ( r ) ;
2014-06-17 20:39:44 +00:00
register_notation_cmds ( r ) ;
2014-08-21 17:36:44 +00:00
register_begin_end_cmds ( r ) ;
2014-07-08 21:28:33 +00:00
register_tactic_hint_cmd ( r ) ;
2014-06-11 18:52:58 +00:00
}
2014-09-23 17:00:36 +00:00
static cmd_table * g_cmds = nullptr ;
2014-06-11 00:02:06 +00:00
cmd_table get_builtin_cmds ( ) {
2014-09-23 17:00:36 +00:00
return * g_cmds ;
}
void initialize_builtin_cmds ( ) {
g_cmds = new cmd_table ( ) ;
init_cmd_table ( * g_cmds ) ;
}
void finalize_builtin_cmds ( ) {
delete g_cmds ;
2014-06-11 00:02:06 +00:00
}
}