1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-17 14:34:25 +03:00
inform7/inter/bytecode-module/Chapter 4/The Pragma Construct.w

87 lines
3.6 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Pragma::] The Pragma Construct.
Defining the pragma construct.
@
@e PRAGMA_IST
=
void Inter::Pragma::define(void) {
inter_construct *IC = InterConstruct::create_construct(PRAGMA_IST, I"pragma");
InterConstruct::specify_syntax(IC, I"pragma IDENTIFIER TEXT");
InterConstruct::permit(IC, OUTSIDE_OF_PACKAGES_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Pragma::read);
METHOD_ADD(IC, CONSTRUCT_TRANSPOSE_MTID, Inter::Pragma::transpose);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Pragma::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Pragma::write);
2019-02-05 02:44:07 +02:00
}
@
@d TARGET_PRAGMA_IFLD 2
@d TEXT_PRAGMA_IFLD 3
@d EXTENT_PRAGMA_IFR 4
=
2019-07-14 12:44:07 +03:00
void Inter::Pragma::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
2022-02-09 12:33:49 +02:00
*E = InterConstruct::check_level_in_package(IBM, PRAGMA_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
if (SymbolAnnotation::nonempty(&(ilp->set))) { *E = Inter::Errors::plain(I"__annotations are not allowed", eloc); return; }
2019-02-05 02:44:07 +02:00
2022-02-03 17:51:44 +02:00
inter_symbol *target_name = InterSymbolsTable::symbol_from_name(InterBookmark::scope(IBM), ilp->mr.exp[0]);
2019-02-05 02:44:07 +02:00
if (target_name == NULL)
target_name = TextualInter::new_symbol(eloc, InterBookmark::scope(IBM), ilp->mr.exp[0], E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
text_stream *S = ilp->mr.exp[1];
2022-01-30 15:32:38 +02:00
inter_ti ID = InterWarehouse::create_text(InterBookmark::warehouse(IBM), InterBookmark::package(IBM));
2019-02-05 02:44:07 +02:00
int literal_mode = FALSE;
LOOP_THROUGH_TEXT(pos, S) {
int c = (int) Str::get(pos);
if (literal_mode == FALSE) {
if (c == '\\') { literal_mode = TRUE; continue; }
} else {
switch (c) {
case '\\': break;
case '"': break;
case 't': c = 9; break;
case 'n': c = 10; break;
2019-07-09 08:45:46 +03:00
default: { *E = Inter::Errors::plain(I"no such backslash escape", eloc); return; }
2019-02-05 02:44:07 +02:00
}
}
2019-07-09 08:45:46 +03:00
if (Inter::Constant::char_acceptable(c) == FALSE) { *E = Inter::Errors::quoted(I"bad character in text", S, eloc); return; }
2022-01-30 15:32:38 +02:00
PUT_TO(InterWarehouse::get_text(InterBookmark::warehouse(IBM), ID), c);
2019-02-05 02:44:07 +02:00
literal_mode = FALSE;
}
2020-07-01 02:58:55 +03:00
*E = Inter::Pragma::new(IBM, target_name, ID, (inter_ti) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_error_message *Inter::Pragma::new(inter_bookmark *IBM, inter_symbol *target_name, inter_ti pragma_text, inter_ti level, struct inter_error_location *eloc) {
2022-02-03 17:51:44 +02:00
inter_tree_node *P = Inode::new_with_2_data_fields(IBM, PRAGMA_IST, InterSymbolsTable::id_from_symbol_at_bookmark(IBM, target_name), pragma_text, eloc, level);
2022-02-07 00:33:07 +02:00
inter_error_message *E = InterConstruct::verify_construct(InterBookmark::package(IBM), P); if (E) return E;
2022-01-27 01:59:02 +02:00
NodePlacement::move_to_moving_bookmark(P, IBM);
2019-02-05 02:44:07 +02:00
return NULL;
}
2020-07-01 02:58:55 +03:00
void Inter::Pragma::transpose(inter_construct *IC, inter_tree_node *P, inter_ti *grid, inter_ti grid_extent, inter_error_message **E) {
2022-01-30 15:32:38 +02:00
P->W.instruction[TEXT_PRAGMA_IFLD] = grid[P->W.instruction[TEXT_PRAGMA_IFLD]];
}
2019-07-24 20:15:07 +03:00
void Inter::Pragma::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2020-05-11 17:21:29 +03:00
if (P->W.extent != EXTENT_PRAGMA_IFR) { *E = Inode::error(P, I"extent wrong", NULL); return; }
2022-02-03 17:51:44 +02:00
inter_symbol *target_name = InterSymbolsTable::symbol_from_ID_at_node(P, TARGET_PRAGMA_IFLD);
2020-05-11 17:21:29 +03:00
if (target_name == NULL) { *E = Inode::error(P, I"no target name", NULL); return; }
2022-01-30 15:32:38 +02:00
if (P->W.instruction[TEXT_PRAGMA_IFLD] == 0) { *E = Inode::error(P, I"no pragma text", NULL); return; }
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Pragma::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2022-02-03 17:51:44 +02:00
inter_symbol *target_name = InterSymbolsTable::symbol_from_ID_at_node(P, TARGET_PRAGMA_IFLD);
2022-01-30 15:32:38 +02:00
inter_ti ID = P->W.instruction[TEXT_PRAGMA_IFLD];
2020-05-11 17:21:29 +03:00
text_stream *S = Inode::ID_to_text(P, ID);
WRITE("pragma %S \"%S\"", InterSymbol::identifier(target_name), S);
2019-02-05 02:44:07 +02:00
}