1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-05 08:34:22 +03:00
inform7/inter/bytecode-module/Chapter 6/The Socket Construct.w

62 lines
2.2 KiB
OpenEdge ABL
Raw Normal View History

2022-03-01 02:41:22 +02:00
[SocketInstruction::] The Socket Construct.
2022-02-11 12:48:26 +02:00
Defining the socket construct.
2022-03-13 13:28:33 +02:00
@ This is a pseudo-construct: it looks like an instruction in textual Inter
syntax, but specifies something else, and does not result in an |inter_tree_node|.
2022-02-11 12:48:26 +02:00
=
2022-03-01 02:41:22 +02:00
void SocketInstruction::define_construct(void) {
inter_construct *IC = InterInstruction::create_construct(SOCKET_IST, I"socket");
InterInstruction::specify_syntax(IC, I"socket IDENTIFIER TOKENS");
METHOD_ADD(IC, CONSTRUCT_READ_MTID, SocketInstruction::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, SocketInstruction::verify);
InterInstruction::allow_in_depth_range(IC, 0, 1);
InterInstruction::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
2022-02-11 12:48:26 +02:00
}
2022-03-13 13:28:33 +02:00
void SocketInstruction::verify(inter_construct *IC, inter_tree_node *P,
inter_package *owner, inter_error_message **E) {
*E = Inode::error(P, I"SOCKET_IST structures cannot exist", NULL);
2022-02-11 12:48:26 +02:00
}
2022-03-13 13:28:33 +02:00
@ What it does is to specify a symbol which is a socket in the current tree:
this results in an entry in the symbols table for the current package (which
will always be |/main/connectors|, in fact) but not an instruction.
2022-02-11 12:48:26 +02:00
2022-03-13 13:28:33 +02:00
For how these are printed back, see //PlugInstruction::write_declaration//,
which handles both plugs and sockets.
2022-02-11 12:48:26 +02:00
=
2022-03-13 13:28:33 +02:00
void SocketInstruction::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp,
inter_error_location *eloc, inter_error_message **E) {
text_stream *symbol_text = ilp->mr.exp[0];
text_stream *equate_text = ilp->mr.exp[1];
inter_tree *I = InterBookmark::tree(IBM);
inter_symbols_table *T = InterBookmark::scope(IBM);
inter_symbol *socket_s = TextualInter::new_symbol(eloc, T, symbol_text, E);
if (*E) return;
text_stream *equate_name = NULL;
match_results mr = Regexp::create_mr();
if (Regexp::match(&mr, equate_text, L"~~> \"(%C+)\"")) {
*E = InterErrors::plain(I"a socket cannot wire to a name", eloc);
return;
} else if (Regexp::match(&mr, equate_text, L"~~> (%C+)")) {
equate_name = mr.exp[0];
} else {
Regexp::dispose_of(&mr);
*E = InterErrors::plain(I"bad socket syntax", eloc); return;
2022-02-11 12:48:26 +02:00
}
2022-03-13 13:28:33 +02:00
inter_symbol *eq = InterSymbolsTable::URL_to_symbol(I, equate_name);
if (eq == NULL) {
InterSymbol::make_socket(socket_s);
Wiring::wire_to_name(socket_s, equate_name);
2022-02-11 12:48:26 +02:00
} else {
2022-03-13 13:28:33 +02:00
Wiring::make_socket_to(socket_s, eq);
2022-02-11 12:48:26 +02:00
}
2022-03-13 13:28:33 +02:00
Regexp::dispose_of(&mr);
2022-02-11 12:48:26 +02:00
}