Parsing assignments.
parent
0d9130ec89
commit
78afcf554e
|
@ -3,7 +3,7 @@
|
|||
Object {
|
||||
property string thing: "i has the thing"
|
||||
|
||||
Object {
|
||||
Object (my-children-id) {
|
||||
property string thing: "i has the other thing"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,11 @@ pub fn parse(gpa: *Allocator, source: []const u8) Allocator.Error!*Tree {
|
|||
return tree;
|
||||
}
|
||||
|
||||
const Assignment = struct {
|
||||
id_attribute: TokenIndex,
|
||||
id_value: TokenIndex,
|
||||
};
|
||||
|
||||
/// Represents in-progress parsing, will be converted to an ast.Tree after completion.
|
||||
const Parser = struct {
|
||||
arena: std.heap.ArenaAllocator,
|
||||
|
@ -241,16 +246,54 @@ const Parser = struct {
|
|||
}
|
||||
// Either simple or full header.
|
||||
const identifier: ?[] const u8 = try p.parseFullClassHeader();
|
||||
// const parent_class_name = p.eatToken(.Identifier);
|
||||
std.debug.print("TODO: read class: {}\n",
|
||||
|
||||
std.debug.print("TODO: read class: {}",
|
||||
.{p.giveTokenContent(class_name.?)});
|
||||
// switch (class_name) {
|
||||
// .usize => |v| {
|
||||
// std.debug.print("TODO: read class: {}\n",
|
||||
// .{p.giveTokenContent(v) orelse null});
|
||||
// },
|
||||
// }
|
||||
// TODO: parsing a class.\n
|
||||
|
||||
if (identifier) |id| {
|
||||
std.debug.print(", id: {}\n", .{id});
|
||||
}
|
||||
else {
|
||||
std.debug.print("\n", .{});
|
||||
}
|
||||
|
||||
// TODO: parsing class content.
|
||||
const token = p.nextToken();
|
||||
switch (p.token_ids[token]) {
|
||||
.Identifier => {
|
||||
p.putBackToken(token);
|
||||
const assignment = try p.parseAssignment();
|
||||
std.debug.print("redefining an attribute {} => {}\n"
|
||||
, .{ p.giveTokenContent(assignment.id_attribute)
|
||||
, p.giveTokenContent(assignment.id_value)});
|
||||
},
|
||||
else => {
|
||||
p.putBackToken(token);
|
||||
std.debug.print("reading {} in a class, backing up\n"
|
||||
, .{p.giveTokenContent(token)});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn parseAssignment(p: *Parser) !Assignment {
|
||||
const id_attribute = p.eatToken(.Identifier);
|
||||
const ignored = try p.expectToken(.Colon);
|
||||
const id_value = p.nextToken();
|
||||
switch (p.token_ids[id_value]) {
|
||||
.StringLiteral,
|
||||
.IntegerLiteral,
|
||||
.FloatLiteral => {
|
||||
if (id_attribute) |ia| {
|
||||
return Assignment{.id_attribute = ia, .id_value = id_value};
|
||||
}
|
||||
},
|
||||
else => {
|
||||
return error.ParseError;
|
||||
}
|
||||
}
|
||||
return error.ParseError;
|
||||
}
|
||||
|
||||
fn parseFullClassHeader(p: *Parser) !?[]const u8 {
|
||||
|
|
Loading…
Reference in New Issue