Expand coding symbol rail

This commit is contained in:
slhx agent
2026-06-21 21:20:29 +02:00
parent 27c4269a3d
commit 062d0f1af9
3 changed files with 29 additions and 5 deletions
+26 -2
View File
@@ -12,6 +12,12 @@ pub const Symbol = enum {
brackets,
braces,
slash,
line_comment,
star,
ampersand,
hash,
dollar,
at,
pipe,
double_quote,
single_quote,
@@ -31,6 +37,12 @@ pub const entries = [_]Entry{
.{ .key = "b", .symbol = .brackets, .label = "[]", .protocol_command = "command pair brackets" },
.{ .key = "c", .symbol = .braces, .label = "{}", .protocol_command = "command pair braces" },
.{ .key = "s", .symbol = .slash, .label = "/", .protocol_command = "command insert /" },
.{ .key = "f", .symbol = .line_comment, .label = "//", .protocol_command = "command insert //" },
.{ .key = "x", .symbol = .star, .label = "*", .protocol_command = "command insert *" },
.{ .key = "a", .symbol = .ampersand, .label = "&", .protocol_command = "command insert &" },
.{ .key = "h", .symbol = .hash, .label = "#", .protocol_command = "command insert #" },
.{ .key = "d", .symbol = .dollar, .label = "$", .protocol_command = "command insert $" },
.{ .key = "r", .symbol = .at, .label = "@", .protocol_command = "command insert @" },
.{ .key = "v", .symbol = .pipe, .label = "|", .protocol_command = "command insert |" },
.{ .key = "q", .symbol = .double_quote, .label = "\"\"", .protocol_command = "command pair double_quote" },
.{ .key = "e", .symbol = .single_quote, .label = "''", .protocol_command = "command pair single_quote" },
@@ -38,7 +50,7 @@ pub const entries = [_]Entry{
.{ .key = "u", .symbol = .underscore, .label = "_", .protocol_command = "command insert _" },
};
pub const rail_status = "symbols: p () b [] c {} s / v | q \"\" e '' t `` u _";
pub const rail_status = "symbols: p () b [] c {} s / f // x * a & h # d $ r @ v | q \"\" e '' t `` u _";
pub fn lookup(key: []const u8) ?Entry {
for (entries) |entry| {
@@ -59,6 +71,12 @@ test "regular: symbol rail maps mobile-friendly letters to coding punctuation" {
try std.testing.expectEqual(Symbol.brackets, lookup("b").?.symbol);
try std.testing.expectEqual(Symbol.braces, lookup("c").?.symbol);
try std.testing.expectEqual(Symbol.slash, lookup("s").?.symbol);
try std.testing.expectEqual(Symbol.line_comment, lookup("f").?.symbol);
try std.testing.expectEqual(Symbol.star, lookup("x").?.symbol);
try std.testing.expectEqual(Symbol.ampersand, lookup("a").?.symbol);
try std.testing.expectEqual(Symbol.hash, lookup("h").?.symbol);
try std.testing.expectEqual(Symbol.dollar, lookup("d").?.symbol);
try std.testing.expectEqual(Symbol.at, lookup("r").?.symbol);
try std.testing.expectEqual(Symbol.pipe, lookup("v").?.symbol);
try std.testing.expectEqual(Symbol.double_quote, lookup("q").?.symbol);
try std.testing.expectEqual(Symbol.single_quote, lookup("e").?.symbol);
@@ -71,6 +89,12 @@ test "regular: symbol rail protocol commands stay tiny and explicit" {
try std.testing.expectEqualStrings("command pair brackets", protocolCommand(.brackets));
try std.testing.expectEqualStrings("command pair braces", protocolCommand(.braces));
try std.testing.expectEqualStrings("command insert /", protocolCommand(.slash));
try std.testing.expectEqualStrings("command insert //", protocolCommand(.line_comment));
try std.testing.expectEqualStrings("command insert *", protocolCommand(.star));
try std.testing.expectEqualStrings("command insert &", protocolCommand(.ampersand));
try std.testing.expectEqualStrings("command insert #", protocolCommand(.hash));
try std.testing.expectEqualStrings("command insert $", protocolCommand(.dollar));
try std.testing.expectEqualStrings("command insert @", protocolCommand(.at));
try std.testing.expectEqualStrings("command insert |", protocolCommand(.pipe));
try std.testing.expectEqualStrings("command pair double_quote", protocolCommand(.double_quote));
try std.testing.expectEqualStrings("command pair single_quote", protocolCommand(.single_quote));
@@ -79,7 +103,7 @@ test "regular: symbol rail protocol commands stay tiny and explicit" {
}
test "adversarial: unknown symbol key does not map to a symbol" {
try std.testing.expectEqual(@as(?Entry, null), lookup("x"));
try std.testing.expectEqual(@as(?Entry, null), lookup("z"));
try std.testing.expectEqual(@as(?Entry, null), lookup("/"));
try std.testing.expectEqual(@as(?Entry, null), lookup(""));
}