Almost done reading source files.
parent
1bea958fed
commit
70d0454695
|
@ -20,7 +20,14 @@ pub const Node = struct {
|
|||
children: NodeList,
|
||||
};
|
||||
|
||||
pub const PropertyValue = union {
|
||||
const PropertyValueTags = enum {
|
||||
string,
|
||||
integer,
|
||||
float,
|
||||
reference,
|
||||
};
|
||||
|
||||
pub const PropertyValue = union(PropertyValueTags) {
|
||||
// nil: null,
|
||||
string: [] const u8, // String.
|
||||
integer: u64, // Num (integer).
|
||||
|
|
|
@ -398,10 +398,12 @@ const Parser = struct {
|
|||
.Identifier => {
|
||||
// Loop over identifier and points.
|
||||
p.putBackToken(token);
|
||||
const string = try p.parseReference();
|
||||
p.say("parsed reference: {}\n", .{string});
|
||||
const loc: Token.Loc = try p.parseReference();
|
||||
// p.say("loc: {}\n", .{loc});
|
||||
// const val: []const u8 = try p.parseReference();
|
||||
// p.say("value: {}\n", .{val});
|
||||
return PropertyValue{
|
||||
.reference = string
|
||||
.reference = p.source[loc.start..loc.end]
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -412,25 +414,30 @@ const Parser = struct {
|
|||
}
|
||||
}
|
||||
|
||||
// Get the representation of the reference in a simple string.
|
||||
fn parseReference(p: *Parser) ![]u8 {
|
||||
// Get the representation of the reference: returning a location.
|
||||
fn parseReference(p: *Parser) !Token.Loc {
|
||||
|
||||
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)});
|
||||
// try std.fmt.format(fbs.writer(), "{}", .{p.giveTokenContent(id)});
|
||||
|
||||
var loc: Token.Loc = Token.Loc{
|
||||
.start = p.token_locs[id].start,
|
||||
.end = p.token_locs[id].end,
|
||||
};
|
||||
|
||||
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)});
|
||||
loc.end = p.token_locs[following].end;
|
||||
},
|
||||
|
||||
else => {
|
||||
|
@ -440,7 +447,8 @@ const Parser = struct {
|
|||
}
|
||||
}
|
||||
|
||||
return representation[0..fbs.pos];
|
||||
// return representation[0..fbs.pos];
|
||||
return loc;
|
||||
}
|
||||
|
||||
fn parseProperty(p: *Parser) !void {
|
||||
|
@ -449,7 +457,10 @@ const Parser = struct {
|
|||
const attribute_name = try p.expectToken(.Identifier);
|
||||
const colon = try p.expectToken(.Colon);
|
||||
const value: PropertyValue = try p.parseValue();
|
||||
std.debug.print("{}\n", .{value});
|
||||
p.say("property class {} name {} value: {}\n"
|
||||
, .{ p.giveTokenContent(class_name)
|
||||
, p.giveTokenContent(attribute_name)
|
||||
, value});
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue