1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-16 22:14:23 +03:00
inform7/services/linguistics-test/Chapter 1/Program Control.w

120 lines
3.4 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Main::] Program Control.
What shall we test?
2019-02-05 02:44:07 +02:00
@ A simple command line:
2019-02-05 02:44:07 +02:00
@d PROGRAM_NAME "linguistics-test"
@e VOCABULARY_CLSW
2019-02-05 02:44:07 +02:00
@e TEST_DIAGRAMS_CLSW
2020-07-20 13:30:03 +03:00
@e RAW_DIAGRAMS_CLSW
@e TRACE_DIAGRAMS_CLSW
@e VIABILITY_DIAGRAMS_CLSW
@e SURGERY_CLSW
2020-07-08 01:49:36 +03:00
@e TEST_ARTICLES_CLSW
2020-07-07 20:24:23 +03:00
@e TEST_PRONOUNS_CLSW
2019-02-05 02:44:07 +02:00
=
int main(int argc, char **argv) {
Foundation::start(argc, argv);
2019-02-05 02:44:07 +02:00
WordsModule::start();
InflectionsModule::start();
SyntaxModule::start();
2020-05-30 16:33:19 +03:00
LexiconModule::start();
2019-02-05 02:44:07 +02:00
LinguisticsModule::start();
pathname *P = Pathnames::from_text(I"services");
P = Pathnames::down(P, I"linguistics-test");
P = Pathnames::down(P, I"Tangled");
filename *S = Filenames::in(P, I"Syntax.preform");
LoadPreform::load(S, NULL);
CommandLine::declare_heading(
L"linguistics-test: a tool for testing the linguistics module\n");
2019-02-05 02:44:07 +02:00
CommandLine::declare_switch(TEST_DIAGRAMS_CLSW, L"diagram", 2,
L"test sentence diagrams from text in X");
2020-07-20 13:30:03 +03:00
CommandLine::declare_switch(RAW_DIAGRAMS_CLSW, L"raw", 2,
L"test raw sentence diagrams from text in X");
CommandLine::declare_switch(TRACE_DIAGRAMS_CLSW, L"trace", 2,
L"test raw sentence diagrams from text in X with tracing on");
CommandLine::declare_switch(VIABILITY_DIAGRAMS_CLSW, L"viability", 2,
L"show viability map for sentences in X");
CommandLine::declare_switch(SURGERY_CLSW, L"surgery", 2,
L"show surgeries performed on sentences in X");
CommandLine::declare_switch(VOCABULARY_CLSW, L"vocabulary", 2,
L"read vocabulary from file X for use in -diagram tests");
2020-07-08 01:49:36 +03:00
CommandLine::declare_switch(TEST_ARTICLES_CLSW, L"test-articles", 2,
L"test pronoun stock (ignoring X)");
2020-07-07 20:24:23 +03:00
CommandLine::declare_switch(TEST_PRONOUNS_CLSW, L"test-pronouns", 2,
L"test pronoun stock (ignoring X)");
2019-02-05 02:44:07 +02:00
CommandLine::read(argc, argv, NULL, &Main::respond, &Main::ignore);
WordsModule::end();
InflectionsModule::end();
SyntaxModule::end();
2020-05-30 16:33:19 +03:00
LexiconModule::end();
2019-02-05 02:44:07 +02:00
LinguisticsModule::end();
Foundation::end();
return 0;
}
@ |-trace| turns all verb phrase tracing on; |-viability| just shows the
viability map for each sentence.
@d TRACING_LINGUISTICS_CALLBACK Main::trace_parsing
=
int trace_diagrams_mode = FALSE;
int viability_diagrams_mode = FALSE;
int surgery_mode = FALSE;
int Main::trace_parsing(int A) {
if (trace_diagrams_mode) return trace_diagrams_mode;
if (A == VIABILITY_VP_TRACE) return viability_diagrams_mode;
if (A == SURGERY_VP_TRACE) return surgery_mode;
return FALSE;
}
@ =
2019-02-05 02:44:07 +02:00
void Main::respond(int id, int val, text_stream *arg, void *state) {
text_stream *save_DL = DL;
DL = STDOUT;
Streams::enable_debugging(DL);
2019-02-05 02:44:07 +02:00
switch (id) {
case VOCABULARY_CLSW: Banking::load_from_file(arg); break;
case TRACE_DIAGRAMS_CLSW:
trace_diagrams_mode = TRUE;
Diagramming::test_diagrams(arg, TRUE);
break;
case VIABILITY_DIAGRAMS_CLSW:
viability_diagrams_mode = TRUE;
Diagramming::test_diagrams(arg, TRUE);
break;
case SURGERY_CLSW:
surgery_mode = TRUE;
Diagramming::test_diagrams(arg, TRUE);
break;
2020-07-20 13:30:03 +03:00
case RAW_DIAGRAMS_CLSW:
Interpreting::go(Diagramming::test_diagrams(arg, TRUE));
break;
case TEST_DIAGRAMS_CLSW:
2020-07-20 13:30:03 +03:00
Interpreting::go(Diagramming::test_diagrams(arg, FALSE));
break;
case TEST_ARTICLES_CLSW:
Articles::create_small_word_sets();
Articles::test(STDOUT);
break;
case TEST_PRONOUNS_CLSW:
Pronouns::create_small_word_sets();
Pronouns::test(STDOUT);
break;
2019-02-05 02:44:07 +02:00
}
DL = save_DL;
2019-02-05 02:44:07 +02:00
}
void Main::ignore(int id, text_stream *arg, void *state) {
Errors::fatal("only switches may be used at the command line");
}