1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-02 23:14:57 +03:00

Divided off CommandParserKit

This commit is contained in:
Graham Nelson 2020-01-27 10:54:21 +00:00
parent df224cfd40
commit fea417f46e
18 changed files with 58 additions and 54 deletions

View file

@ -18,15 +18,14 @@
real number <= value, word value, arithmetic value, real arithmetic value, sayable value
truth state <= value, word value, sayable value
text <= value, pointer value, sayable value
snippet <= value, word value, sayable value
unicode character <= value, word value, sayable value
use option <= value, word value, sayable value
response <= value, word value, sayable value
verb <= value, word value, sayable value
snippet <= value, word value, sayable value
table name <= value, word value, sayable value
equation name <= value, word value
rulebook outcome <= value, word value, sayable value
topic <= value, word value
nothing <= value, word value
phrase value -> value <= value, word value, sayable value
value, value <= value, word value
@ -48,6 +47,7 @@
scene <= value, word value, enumerated value, sayable value
figure name <= value, word value, enumerated value, sayable value
sound name <= value, word value, enumerated value, sayable value
topic <= value, word value
natural language <= value, word value, enumerated value, sayable value
room <= value, word value, sayable value, object
thing <= value, word value, sayable value, object
@ -92,15 +92,14 @@
real number ->
truth state ->
text ->
snippet ->
unicode character ->
use option ->
response ->
verb ->
snippet ->
table name ->
equation name ->
rulebook outcome ->
topic ->
nothing ->
phrase value -> value ->
value, value ->
@ -122,6 +121,7 @@
scene ->
figure name ->
sound name ->
topic ->
natural language ->
room -> object ->
thing -> object ->

View file

@ -240,6 +240,17 @@ void Kits::feed_early_source_text(OUTPUT_STREAM) {
}
}
int Kits::number_of_early_fed_sentences(void) {
int N = 0;
inform_kit *K;
LOOP_OVER_LINKED_LIST(K, inform_kit, kits_to_include) {
text_stream *X;
LOOP_OVER_LINKED_LIST(X, text_stream, K->extensions) N++;
if (K->early_source) N++;
}
return N;
}
linked_list *requirements_list = NULL;
linked_list *Kits::list_of_inter_libraries(void) {
requirements_list = NEW_LINKED_LIST(inter_library);

View file

@ -173,7 +173,7 @@ pcalc_prop *Calculus::Simplifications::use_listed_in(pcalc_prop *prop, int *chan
parse_node *tab = spec->down->next;
table_column *tc = Rvalues::to_table_column(col);
kind *K = Tables::Columns::get_kind(tc);
if (Kinds::Compare::eq(K, K_understanding)) K = K_snippet;
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) K = K_snippet;
int nv = Calculus::Variables::find_unused(prop);
pcalc_term nv_term = Calculus::Terms::new_variable(nv);
prop = Calculus::Propositions::insert_atom(prop, pl_prev,

View file

@ -53,7 +53,7 @@ any kind.
int Calculus::Equality::REL_typecheck(binary_predicate *bp,
kind **kinds_of_terms, kind **kinds_required, tc_problem_kit *tck) {
LOGIF(MATCHING, "Typecheck $u '==' $u\n", kinds_of_terms[0], kinds_of_terms[1]);
if ((Kinds::Compare::eq(kinds_of_terms[0], K_understanding)) &&
if ((K_understanding) && (Kinds::Compare::eq(kinds_of_terms[0], K_understanding)) &&
(Kinds::Compare::eq(kinds_of_terms[1], K_text))) {
LOGIF(MATCHING, "No!\n");
Problems::Issue::tcp_problem(_p_(PM_TextIsNotTopic), tck,
@ -69,10 +69,10 @@ int Calculus::Equality::REL_typecheck(binary_predicate *bp,
if ((Kinds::Compare::le(kinds_of_terms[0], K_object)) &&
(Properties::Conditions::name_can_coincide_with_property(kinds_of_terms[1])))
@<Apply rule for "is" applied to an object and a value@>
else if ((Kinds::Compare::eq(kinds_of_terms[1], K_understanding)) &&
else if ((K_understanding) && (Kinds::Compare::eq(kinds_of_terms[1], K_understanding)) &&
(Kinds::Compare::eq(kinds_of_terms[0], K_snippet)))
return ALWAYS_MATCH;
else if ((Kinds::Compare::eq(kinds_of_terms[0], K_understanding)) &&
else if ((K_understanding) && (Kinds::Compare::eq(kinds_of_terms[0], K_understanding)) &&
(Kinds::Compare::eq(kinds_of_terms[1], K_snippet)))
return ALWAYS_MATCH;
else if ((Kinds::Compare::eq(kinds_of_terms[1], K_text)) &&

View file

@ -257,7 +257,7 @@ void Kinds::RunTime::get_default_value(inter_t *v1, inter_t *v2, kind *K) {
return;
}
if (Kinds::Compare::eq(K, K_understanding)) {
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) {
inter_name *empty = Hierarchy::find(DEFAULTTOPIC_HL);
Emit::to_ival(v1, v2, empty);
return;

View file

@ -136,7 +136,7 @@ void Specifications::Compiler::emit_to_kind(parse_node *value, kind *K_wanted) {
kind *K_found = Specifications::to_kind(value);
Kinds::RunTime::notify_of_use(K_found);
if ((Kinds::Compare::eq(K_wanted, K_understanding)) && (Kinds::Compare::eq(K_found, K_text))) {
if ((K_understanding) && (Kinds::Compare::eq(K_wanted, K_understanding)) && (Kinds::Compare::eq(K_found, K_text))) {
ParseTree::set_kind_of_value(value, K_understanding);
K_found = K_understanding;
}

View file

@ -1610,7 +1610,7 @@ literal can mean are too generous.)
}
LOGIF(MATCHING, "Kinds found: $u, wanted: $u\n", kind_found, kind_wanted);
if (((Kinds::Compare::eq(kind_wanted, K_understanding)) &&
if (((K_understanding) && (Kinds::Compare::eq(kind_wanted, K_understanding)) &&
(Kinds::Compare::eq(kind_found, K_understanding) == FALSE))
|| (Kinds::Compare::compatible(kind_found, kind_wanted) == NEVER_MATCH)) {
THIS_IS_AN_INTERESTING_PROBLEM {
@ -2974,7 +2974,7 @@ different representations at run-time.
@<Step (5.d.2) Coerce constant TEXT and TEXT ROUTINE to UNDERSTANDING@> =
LOG_DASH("(5.d.2)");
if ((Rvalues::is_CONSTANT_of_kind(p, K_text)) &&
(Kinds::Compare::eq(kind_expected, K_understanding))) {
(K_understanding) && (Kinds::Compare::eq(kind_expected, K_understanding))) {
ParseTree::set_kind_of_value(p, K_understanding);
}
@ -3386,14 +3386,16 @@ int Dash::validate_parameter(parse_node *spec, kind *K) {
kind_found = Specifications::to_kind(spec);
if ((Kinds::get_construct(kind_found) == CON_property) && (Kinds::Compare::le(K, K_object)))
return TRUE;
if ((Kinds::Compare::eq(kind_found, K_snippet)) && (Kinds::Compare::eq(K, K_understanding)))
if ((K_understanding) && (Kinds::Compare::eq(kind_found, K_snippet)) &&
(Kinds::Compare::eq(K, K_understanding)))
return TRUE;
if ((Kinds::Compare::eq(K, K_understanding)) && (ParseTree::is(spec, CONSTANT_NT) == FALSE) &&
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding)) &&
(ParseTree::is(spec, CONSTANT_NT) == FALSE) &&
(Kinds::Compare::eq(kind_found, K_text)))
goto DontValidate;
vts = Specifications::from_kind(K);
if (Dash::compatible_with_description(spec, vts) == NEVER_MATCH) {
if ((Kinds::Compare::eq(K, K_understanding)) && (ParseTree::is(spec, CONSTANT_NT))) {
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding)) && (ParseTree::is(spec, CONSTANT_NT))) {
vts = Specifications::from_kind(K_snippet);
if (Dash::compatible_with_description(spec, vts) != NEVER_MATCH) return TRUE;
}

View file

@ -742,7 +742,7 @@ kinds of value:
return;
}
#ifdef IF_MODULE
if (Kinds::Compare::eq(kind_of_constant, K_understanding)) {
if ((K_understanding) && (Kinds::Compare::eq(kind_of_constant, K_understanding))) {
if (Wordings::empty(ParseTree::get_text(spec_found)))
internal_error("Text no longer available for CONSTANT/UNDERSTANDING");
inter_t v1 = 0, v2 = 0;

View file

@ -129,7 +129,7 @@ the values given there.
if (Kinds::FloatingPoint::uses_floating_point(K)) bits += TB_COLUMN_REAL;
if (Kinds::Behaviour::uses_pointer_values(K)) bits += TB_COLUMN_ALLOCATED;
if (Kinds::Compare::eq(K, K_understanding)) bits = TB_COLUMN_TOPIC;
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) bits = TB_COLUMN_TOPIC;
if (Kinds::Behaviour::requires_blanks_bitmap(K) == FALSE) bits += TB_COLUMN_NOBLANKBITS;
if (t->preserve_row_order_at_run_time) bits += TB_COLUMN_DONTSORTME;

View file

@ -110,7 +110,7 @@ void Tables::Columns::set_kind(table_column *tc, table *t, kind *K) {
tc->table_from_which_kind_inferred = t;
LOGIF(TABLES, "Table column $C contains kind $u, according to $B\n",
tc, tc->kind_stored_in_column, t);
if (Kinds::Compare::eq(K, K_understanding))
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding)))
Tables::Relations::supply_kind_for_listed_in_tc(tc->listed_in_predicate, K_snippet);
else Tables::Relations::supply_kind_for_listed_in_tc(tc->listed_in_predicate, K);
}
@ -396,7 +396,7 @@ void Tables::Columns::note_kind(table *t, int i, table_column_usage *tcu,
Tables::Columns::set_kind(tcu->column_identity, t, K);
} else {
int allow_refinement = TRUE;
if (Kinds::Compare::eq(CK, K_understanding)) {
if ((K_understanding) && (Kinds::Compare::eq(CK, K_understanding))) {
CK = K_text; /* make sure the entries are texts... */
allow_refinement = FALSE; /* ...and don't allow any change to the kind */
}

View file

@ -605,7 +605,7 @@ void Adjectives::Meanings::set_definition_domain(adjective_meaning *am, int earl
K = Rvalues::to_kind(supplied);
if (K == NULL) @<Reject domain of adjective@>;
if (Kinds::Behaviour::is_kind_of_kind(K)) @<Reject domain as vague@>;
if (Kinds::Compare::eq(K, K_understanding)) @<Reject domain as topic@>;
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) @<Reject domain as topic@>;
@<Set the domain INFS as needed@>;
}

View file

@ -667,7 +667,7 @@ to abbreviated forms of object names are normally allowed.
if (domain == NULL) domain = Kinds::weaken(Specifications::to_kind(governing_spec));
if (Specifications::is_new_variable_like(governing_spec))
domain = Specifications::kind_of_new_variable_like(governing_spec);
if (Kinds::contains(domain, Kinds::get_construct(K_understanding)))
if ((K_understanding) && (Kinds::contains(domain, Kinds::get_construct(K_understanding))))
@<Issue a problem for topics that vary@>;
pcalc_prop *prop = Calculus::Propositions::Abstract::to_create_something(domain, W);
if (prevailing_mood == CERTAIN_CE)

View file

@ -1033,6 +1033,7 @@ description.
if (entry->parc >= 2) {
if (Wordings::nonempty(entry->parameter[1])) {
if ((entry->action_listed != NULL)
&& (K_understanding)
&& (Kinds::Compare::eq(PL::Actions::get_data_type_of_second_noun(entry->action_listed), K_understanding))
&& (<understanding-action-irregular-operand>(entry->parameter[1]))) {
trial_ap.second_spec = Rvalues::from_grammar_verb(NULL); /* Why no GV here? */
@ -1347,7 +1348,7 @@ void PL::Actions::Patterns::put_action_object_into_ap(action_pattern *ap, int po
else { any_flag = TRUE; spec = Specifications::from_kind(K_thing); }
}
if (spec == NULL) spec = Specifications::new_UNKNOWN(W);
if (Rvalues::is_CONSTANT_of_kind(spec, K_text))
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(spec, K_text)))
ParseTree::set_kind_of_value(spec, K_understanding);
ParseTree::set_text(spec, W);
LOGIF(ACTION_PATTERN_PARSING, "PAOIA (position %d) %W = $P\n", pos, W, spec);
@ -1366,10 +1367,10 @@ void PL::Actions::Patterns::emit_try(action_pattern *ap, int store_instead) {
parse_node *spec1 = ap->second_spec; /* the second noun */
parse_node *spec2 = ap->actor_spec; /* the actor */
if ((Rvalues::is_CONSTANT_of_kind(spec0, K_understanding)) &&
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(spec0, K_understanding)) &&
(<nominative-pronoun>(ParseTree::get_text(spec0)) == FALSE))
spec0 = Rvalues::from_wording(ParseTree::get_text(spec0));
if ((Rvalues::is_CONSTANT_of_kind(spec1, K_understanding)) &&
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(spec1, K_understanding)) &&
(<nominative-pronoun>(ParseTree::get_text(spec1)) == FALSE))
spec1 = Rvalues::from_wording(ParseTree::get_text(spec1));
@ -1409,7 +1410,7 @@ text when the action expects that.
=
void PL::Actions::Patterns::emit_try_action_parameter(parse_node *spec, kind *required_kind) {
if (Kinds::Compare::eq(required_kind, K_understanding)) {
if ((K_understanding) && (Kinds::Compare::eq(required_kind, K_understanding))) {
kind *K = Specifications::to_kind(spec);
if ((Kinds::Compare::compatible(K, K_understanding)) ||
(Kinds::Compare::compatible(K, K_text))) {
@ -1550,7 +1551,7 @@ int PL::Actions::Patterns::compile_pattern_match_clause_inner(int f,
force_proposition = FALSE;
}
else if (ParseTreeUsage::is_rvalue(spec)) {
if (Rvalues::is_CONSTANT_of_kind(spec, K_understanding)) {
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(spec, K_understanding))) {
if ((<understanding-action-irregular-operand>(ParseTree::get_text(spec))) &&
(<<r>> == TRUE)) {
Produce::val(Emit::tree(), K_truth_state, LITERAL_IVAL, 1);
@ -1644,7 +1645,7 @@ void PL::Actions::Patterns::as_stored_action(value_holster *VH, action_pattern *
int request_bits = ap->request;
if (ap->noun_spec) {
if (Rvalues::is_CONSTANT_of_kind(ap->noun_spec, K_understanding)) {
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(ap->noun_spec, K_understanding))) {
request_bits = request_bits | 16;
TEMPORARY_TEXT(BC);
literal_text *lt = Strings::TextLiterals::compile_literal(NULL, FALSE, ParseTree::get_text(ap->noun_spec));
@ -1655,7 +1656,7 @@ void PL::Actions::Patterns::as_stored_action(value_holster *VH, action_pattern *
Emit::array_numeric_entry(0);
}
if (ap->second_spec) {
if (Rvalues::is_CONSTANT_of_kind(ap->second_spec, K_understanding)) {
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(ap->second_spec, K_understanding))) {
request_bits = request_bits | 32;
literal_text *lt = Strings::TextLiterals::compile_literal(NULL, TRUE, ParseTree::get_text(ap->second_spec));
Emit::array_iname_entry(lt->lt_sba_iname);

View file

@ -1322,7 +1322,7 @@ void PL::Actions::cat_something2(action_name *an, int n, inter_symbol *n_s, inte
Produce::inv_primitive(Emit::tree(), INDIRECT1V_BIP);
Produce::down(Emit::tree());
Produce::val_iname(Emit::tree(), K_value, Kinds::Behaviour::get_name_of_printing_rule_ACTIONS(K));
if (Kinds::Compare::eq(K, K_understanding)) {
if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) {
Produce::inv_primitive(Emit::tree(), PLUS_BIP);
Produce::down(Emit::tree());
Produce::inv_primitive(Emit::tree(), TIMES_BIP);
@ -1502,7 +1502,7 @@ void PL::Actions::act_index_something(OUTPUT_STREAM, action_name *an, int argc)
if (argc == 0) K = an->noun_kind;
if (argc == 1) K = an->second_kind;
if (Kinds::Compare::le(K, K_object)) WRITE("something");
else if (Kinds::Compare::eq(K, K_understanding)) WRITE("some text");
else if ((K_understanding) && (Kinds::Compare::eq(K, K_understanding))) WRITE("some text");
else Kinds::Textual::write(OUT, K);
HTML::end_colour(OUT);
WRITE(" ");

View file

@ -669,6 +669,7 @@ parse_node *PL::Parsing::Lines::gl_determine(grammar_line *gl, int depth,
if (spec) {
if ((Specifications::is_kind_like(spec)) &&
(K_understanding) &&
(Kinds::Compare::eq(Specifications::to_kind(spec), K_understanding))) { /* "[text]" token */
int usb_contribution = i - 100;
if (usb_contribution >= 0) usb_contribution = -1;

View file

@ -211,7 +211,7 @@ to be used in I7: these are defined by the following routine.
=
kind *PL::Parsing::Tokens::kind_for_special_token(int gtc) {
if (gtc == TOPIC_TOKEN_GTC) return K_understanding;
if ((K_understanding) && (gtc == TOPIC_TOKEN_GTC)) return K_understanding;
return K_object;
}
@ -425,7 +425,8 @@ parse_node *PL::Parsing::Tokens::determine(parse_node *pn, int depth, int *score
@<Vet the grammar token determination for parseability at run-time@> =
if (Specifications::is_description(spec)) {
kind *K = Specifications::to_kind(spec);
if ((Kinds::Compare::le(K, K_object) == FALSE) &&
if ((K_understanding) &&
(Kinds::Compare::le(K, K_object) == FALSE) &&
(Kinds::Compare::eq(K, K_understanding) == FALSE) &&
(Kinds::Behaviour::request_I6_GPR(K) == FALSE)) {
Problems::quote_source(1, current_sentence);
@ -1047,7 +1048,8 @@ kind *PL::Parsing::Tokens::compile(gpr_kit *gprk, parse_node *pn, int code_mode,
if (Specifications::is_kind_like(spec)) {
kind *K = ParseTree::get_kind_of_value(spec);
if ((Kinds::Compare::le(K, K_object) == FALSE) &&
if ((K_understanding) &&
(Kinds::Compare::le(K, K_object) == FALSE) &&
(Kinds::Compare::eq(K, K_understanding) == FALSE)) {
if (Kinds::Behaviour::offers_I6_GPR(K)) {
text_stream *i6_gpr_name = Kinds::Behaviour::get_explicit_I6_GPR(K);
@ -1241,7 +1243,7 @@ kind *PL::Parsing::Tokens::compile(gpr_kit *gprk, parse_node *pn, int code_mode,
}
} else {
if (ParseTree::is(spec, CONSTANT_NT)) {
if (Rvalues::is_CONSTANT_of_kind(spec, K_understanding)) {
if ((K_understanding) && (Rvalues::is_CONSTANT_of_kind(spec, K_understanding))) {
gv = Rvalues::to_grammar_verb(spec);
if (code_mode) {
Produce::inv_primitive(Emit::tree(), STORE_BIP);

View file

@ -452,7 +452,13 @@ source texts implicitly begin with an inclusion of the Standard Rules.)
=
<if-start-of-source-text> internal 0 {
int w1 = Wordings::first_wn(W);
if ((no_sentences_read == 3) &&
#ifdef CORE_MODULE
int N = 1 + Kits::number_of_early_fed_sentences();
#endif
#ifndef CORE_MODULE
int N = 3;
#endif
if ((no_sentences_read == N) &&
((w1 == 0) || (compare_word(w1-1, PARBREAK_V)))) return TRUE;
return FALSE;
}

View file

@ -16,11 +16,6 @@ inter_library *CodeGen::Libraries::new(pathname *P) {
lib->location = P;
lib->attachment_point = Str::new();
WRITE_TO(lib->attachment_point, "/main/%S", Pathnames::directory_name(P));
// filename *F = Filenames::in_folder(P, I"kit_metadata.txt");
// TextFiles::read(F, FALSE,
// NULL, FALSE, CodeGen::Libraries::read_metadata, NULL, (void *) lib);
// if (lib->attachment_point == NULL)
// Errors::nowhere("library metadata file failed to set attachment point");
return lib;
}
@ -34,20 +29,6 @@ text_stream *CodeGen::Libraries::URL(inter_library *lib) {
return lib->attachment_point;
}
void CodeGen::Libraries::read_metadata(text_stream *text,
text_file_position *tfp, void *state) {
inter_library *lib = (inter_library *) state;
match_results mr = Regexp::create_mr();
if ((Str::is_whitespace(text)) || (Regexp::match(&mr, text, L" *#%c*"))) {
;
} else if (Regexp::match(&mr, text, L"attach: (%c*)")) {
lib->attachment_point = Str::duplicate(mr.exp[0]);
} else {
Errors::in_text_file("illegible line in library metadata file", tfp);
}
Regexp::dispose_of(&mr);
}
inter_library *CodeGen::Libraries::find(text_stream *name, int N, pathname **PP) {
for (int i=0; i<N; i++) {
pathname *P = Pathnames::subfolder(PP[i], name);