Function resolve [src]
Resolve escapes in target or prereq. Only valid with .target_must_resolve or .prereq_must_resolve.
Prototype
pub fn resolve(self: Token, gpa: Allocator, list: *std.ArrayListUnmanaged(u8)) error{OutOfMemory}!void Parameters
self: Tokengpa: Allocatorlist: *std.ArrayListUnmanaged(u8) Possible Errors
Source
pub fn resolve(self: Token, gpa: Allocator, list: *std.ArrayListUnmanaged(u8)) error{OutOfMemory}!void {
switch (self) {
.target_must_resolve => |bytes| {
var state: enum { start, escape, dollar } = .start;
for (bytes) |c| {
switch (state) {
.start => {
switch (c) {
'\\' => state = .escape,
'$' => state = .dollar,
else => try list.append(gpa, c),
}
},
.escape => {
switch (c) {
' ', '#', '\\' => {},
'$' => {
try list.append(gpa, '\\');
state = .dollar;
continue;
},
else => try list.append(gpa, '\\'),
}
try list.append(gpa, c);
state = .start;
},
.dollar => {
try list.append(gpa, '$');
switch (c) {
'$' => {},
else => try list.append(gpa, c),
}
state = .start;
},
}
}
},
.prereq_must_resolve => |bytes| {
var state: enum { start, escape } = .start;
for (bytes) |c| {
switch (state) {
.start => {
switch (c) {
'\\' => state = .escape,
else => try list.append(gpa, c),
}
},
.escape => {
switch (c) {
' ' => {},
'\\' => {
try list.append(gpa, c);
continue;
},
else => try list.append(gpa, '\\'),
}
try list.append(gpa, c);
state = .start;
},
}
}
},
else => unreachable,
}
}