Reading long references (anchor.something.blah).
parent
70d0454695
commit
bf8283b7cf
|
@ -294,7 +294,7 @@ const Parser = struct {
|
|||
|
||||
while (true) {
|
||||
const token = p.nextToken();
|
||||
p.say("token: {}\n", .{p.giveTokenContent(token)});
|
||||
// p.say("within a class, token: {}\n", .{p.giveTokenContent(token)});
|
||||
switch (p.token_ids[token]) {
|
||||
|
||||
.Identifier => {
|
||||
|
@ -306,19 +306,39 @@ const Parser = struct {
|
|||
.LBrace => {
|
||||
p.putBackToken(following);
|
||||
p.putBackToken(token);
|
||||
p.say("reading a new class\n", .{});
|
||||
// p.say("reading a new class\n", .{});
|
||||
// WARNING: RECURSION: this may cause errors.
|
||||
const res = p.parseClass();
|
||||
continue;
|
||||
},
|
||||
|
||||
.Colon => {
|
||||
// p.putBackToken(following);
|
||||
// p.putBackToken(token);
|
||||
|
||||
const value: PropertyValue = try p.parseValue();
|
||||
p.say("attribute {} value: {}\n"
|
||||
, .{ p.giveTokenContent(token)
|
||||
, value});
|
||||
// const assignment = try p.parseAssignment();
|
||||
// p.say("redefining an attribute {} => {}\n"
|
||||
// , .{ p.giveTokenContent(assignment.id_attribute)
|
||||
// , p.giveTokenContent(assignment.id_value)});
|
||||
},
|
||||
|
||||
.Period => {
|
||||
p.putBackToken(following);
|
||||
p.putBackToken(token);
|
||||
const assignment = try p.parseAssignment();
|
||||
p.say("redefining an attribute {} => {}\n"
|
||||
, .{ p.giveTokenContent(assignment.id_attribute)
|
||||
, p.giveTokenContent(assignment.id_value)});
|
||||
|
||||
// Hacking a bit, this is not a value but an identifier.
|
||||
const attribute_loc: Token.Loc = try p.parseReference();
|
||||
|
||||
const colon = p.expectToken(.Colon);
|
||||
|
||||
const value: PropertyValue = try p.parseValue();
|
||||
p.say("attribute {} value: {}\n"
|
||||
, .{ p.source[attribute_loc.start..attribute_loc.end]
|
||||
, value});
|
||||
},
|
||||
|
||||
else => {
|
||||
|
@ -340,12 +360,7 @@ const Parser = struct {
|
|||
continue;
|
||||
},
|
||||
|
||||
.LBrace => {
|
||||
p.say("Reading a LBrace\n", .{});
|
||||
},
|
||||
|
||||
.RBrace => {
|
||||
p.say("Reading a RBrace\n", .{});
|
||||
p.putBackToken(token);
|
||||
break;
|
||||
},
|
||||
|
@ -414,6 +429,28 @@ const Parser = struct {
|
|||
}
|
||||
}
|
||||
|
||||
// // statement => Keyword_property Identifier Identifier Colon value
|
||||
// // value => StringLiteral | Keyword_null | IntegerLiteral | FloatLiteral
|
||||
// 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]) {
|
||||
// .Keyword_null,
|
||||
// .StringLiteral,
|
||||
// .IntegerLiteral,
|
||||
// .FloatLiteral => {
|
||||
// if (id_attribute) |ia| {
|
||||
// return Assignment{.id_attribute = ia, .id_value = id_value};
|
||||
// }
|
||||
// },
|
||||
// else => {
|
||||
// return error.ParseError;
|
||||
// }
|
||||
// }
|
||||
// return error.ParseError;
|
||||
// }
|
||||
|
||||
// Get the representation of the reference: returning a location.
|
||||
fn parseReference(p: *Parser) !Token.Loc {
|
||||
|
||||
|
@ -464,28 +501,6 @@ const Parser = struct {
|
|||
}
|
||||
|
||||
|
||||
// statement => Keyword_property Identifier Identifier Colon value
|
||||
// value => StringLiteral | Keyword_null | IntegerLiteral | FloatLiteral
|
||||
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]) {
|
||||
.Keyword_null,
|
||||
.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 {
|
||||
if (p.eatToken(.LParen) == null)
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue