Reading property values.
parent
bf6aa3ecf6
commit
1bea958fed
|
@ -189,6 +189,7 @@ const Parser = struct {
|
|||
// Propagate memory errors.
|
||||
error.OutOfMemory => { return (error.OutOfMemory); },
|
||||
error.InvalidCharacter => continue,
|
||||
error.NoSpaceLeft => continue,
|
||||
error.Overflow => continue,
|
||||
error.ParseError => continue,
|
||||
}; // |normal_value| { stuff; to; do; }
|
||||
|
@ -201,6 +202,7 @@ const Parser = struct {
|
|||
// Propagate memory errors.
|
||||
error.OutOfMemory => { return (error.OutOfMemory); },
|
||||
error.InvalidCharacter => continue,
|
||||
error.NoSpaceLeft => continue,
|
||||
error.Overflow => continue,
|
||||
error.ParseError => {
|
||||
p.say("we catched a ParseError on token: {}\n"
|
||||
|
@ -376,11 +378,13 @@ const Parser = struct {
|
|||
.StringLiteral => {
|
||||
return PropertyValue{.string = p.giveTokenContent(token)};
|
||||
},
|
||||
|
||||
.IntegerLiteral => {
|
||||
return PropertyValue{
|
||||
.integer = try std.fmt.parseInt(u64, p.giveTokenContent(token), 10)
|
||||
};
|
||||
},
|
||||
|
||||
.FloatLiteral => {
|
||||
// p.say("property: {} {} = {}\n"
|
||||
// , .{p.giveTokenContent(class_name)
|
||||
|
@ -390,13 +394,17 @@ const Parser = struct {
|
|||
.float = try std.fmt.parseFloat(f64, p.giveTokenContent(token))
|
||||
};
|
||||
},
|
||||
|
||||
.Identifier => {
|
||||
// Loop over identifier and points.
|
||||
return error.ParseError;
|
||||
// p.putBackToken(token);
|
||||
// // TODO: do the loop
|
||||
// const string: []const u8 = p.giveStringFromReference();
|
||||
p.putBackToken(token);
|
||||
const string = try p.parseReference();
|
||||
p.say("parsed reference: {}\n", .{string});
|
||||
return PropertyValue{
|
||||
.reference = string
|
||||
};
|
||||
},
|
||||
|
||||
else => {
|
||||
return error.ParseError;
|
||||
}
|
||||
|
@ -404,6 +412,37 @@ const Parser = struct {
|
|||
}
|
||||
}
|
||||
|
||||
// Get the representation of the reference in a simple string.
|
||||
fn parseReference(p: *Parser) ![]u8 {
|
||||
|
||||
var representation: [100]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(representation[0..]);
|
||||
|
||||
// First part of the reference has to be an Identifier.
|
||||
const id = try p.expectToken(.Identifier);
|
||||
try std.fmt.format(fbs.writer(), "{}", .{p.giveTokenContent(id)});
|
||||
|
||||
while (true) {
|
||||
const token = p.nextToken();
|
||||
switch (p.token_ids[token]) {
|
||||
|
||||
.Period => {
|
||||
p.say("reading a point\n", .{});
|
||||
// Following token is expected to be an Identifier.
|
||||
const following = try p.expectToken(.Identifier);
|
||||
try std.fmt.format(fbs.writer(), ".{}", .{p.giveTokenContent(following)});
|
||||
},
|
||||
|
||||
else => {
|
||||
p.putBackToken(token);
|
||||
break;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return representation[0..fbs.pos];
|
||||
}
|
||||
|
||||
fn parseProperty(p: *Parser) !void {
|
||||
const property = try p.expectToken(.Keyword_property);
|
||||
const class_name = try p.expectToken(.Identifier);
|
||||
|
|
Loading…
Reference in New Issue