std.zig.parser now parses error, this and unreachable
parent
aabf7cf57e
commit
df09c01f7f
|
@ -25,6 +25,9 @@ pub const Node = struct {
|
|||
BoolLiteral,
|
||||
NullLiteral,
|
||||
UndefinedLiteral,
|
||||
ThisLiteral,
|
||||
Unreachable,
|
||||
ErrorType,
|
||||
BuiltinCall,
|
||||
Call,
|
||||
LineComment,
|
||||
|
@ -49,6 +52,9 @@ pub const Node = struct {
|
|||
Id.BoolLiteral => @fieldParentPtr(NodeBoolLiteral, "base", base).iterate(index),
|
||||
Id.NullLiteral => @fieldParentPtr(NodeNullLiteral, "base", base).iterate(index),
|
||||
Id.UndefinedLiteral => @fieldParentPtr(NodeUndefinedLiteral, "base", base).iterate(index),
|
||||
Id.ThisLiteral => @fieldParentPtr(NodeThisLiteral, "base", base).iterate(index),
|
||||
Id.Unreachable => @fieldParentPtr(NodeUnreachable, "base", base).iterate(index),
|
||||
Id.ErrorType => @fieldParentPtr(NodeErrorType, "base", base).iterate(index),
|
||||
Id.BuiltinCall => @fieldParentPtr(NodeBuiltinCall, "base", base).iterate(index),
|
||||
Id.Call => @fieldParentPtr(NodeCall, "base", base).iterate(index),
|
||||
Id.LineComment => @fieldParentPtr(NodeLineComment, "base", base).iterate(index),
|
||||
|
@ -74,6 +80,9 @@ pub const Node = struct {
|
|||
Id.BoolLiteral => @fieldParentPtr(NodeBoolLiteral, "base", base).firstToken(),
|
||||
Id.NullLiteral => @fieldParentPtr(NodeNullLiteral, "base", base).firstToken(),
|
||||
Id.UndefinedLiteral => @fieldParentPtr(NodeUndefinedLiteral, "base", base).firstToken(),
|
||||
Id.Unreachable => @fieldParentPtr(NodeUnreachable, "base", base).firstToken(),
|
||||
Id.ThisLiteral => @fieldParentPtr(NodeThisLiteral, "base", base).firstToken(),
|
||||
Id.ErrorType => @fieldParentPtr(NodeErrorType, "base", base).firstToken(),
|
||||
Id.BuiltinCall => @fieldParentPtr(NodeBuiltinCall, "base", base).firstToken(),
|
||||
Id.Call => @fieldParentPtr(NodeCall, "base", base).firstToken(),
|
||||
Id.LineComment => @fieldParentPtr(NodeLineComment, "base", base).firstToken(),
|
||||
|
@ -99,6 +108,9 @@ pub const Node = struct {
|
|||
Id.BoolLiteral => @fieldParentPtr(NodeBoolLiteral, "base", base).lastToken(),
|
||||
Id.NullLiteral => @fieldParentPtr(NodeNullLiteral, "base", base).lastToken(),
|
||||
Id.UndefinedLiteral => @fieldParentPtr(NodeUndefinedLiteral, "base", base).lastToken(),
|
||||
Id.ThisLiteral => @fieldParentPtr(NodeThisLiteral, "base", base).lastToken(),
|
||||
Id.Unreachable => @fieldParentPtr(NodeUnreachable, "base", base).lastToken(),
|
||||
Id.ErrorType => @fieldParentPtr(NodeErrorType, "base", base).lastToken(),
|
||||
Id.BuiltinCall => @fieldParentPtr(NodeBuiltinCall, "base", base).lastToken(),
|
||||
Id.Call => @fieldParentPtr(NodeCall, "base", base).lastToken(),
|
||||
Id.LineComment => @fieldParentPtr(NodeLineComment, "base", base).lastToken(),
|
||||
|
@ -688,6 +700,57 @@ pub const NodeUndefinedLiteral = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub const NodeThisLiteral = struct {
|
||||
base: Node,
|
||||
token: Token,
|
||||
|
||||
pub fn iterate(self: &NodeThisLiteral, index: usize) ?&Node {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn firstToken(self: &NodeThisLiteral) Token {
|
||||
return self.token;
|
||||
}
|
||||
|
||||
pub fn lastToken(self: &NodeThisLiteral) Token {
|
||||
return self.token;
|
||||
}
|
||||
};
|
||||
|
||||
pub const NodeUnreachable = struct {
|
||||
base: Node,
|
||||
token: Token,
|
||||
|
||||
pub fn iterate(self: &NodeUnreachable, index: usize) ?&Node {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn firstToken(self: &NodeUnreachable) Token {
|
||||
return self.token;
|
||||
}
|
||||
|
||||
pub fn lastToken(self: &NodeUnreachable) Token {
|
||||
return self.token;
|
||||
}
|
||||
};
|
||||
|
||||
pub const NodeErrorType = struct {
|
||||
base: Node,
|
||||
token: Token,
|
||||
|
||||
pub fn iterate(self: &NodeErrorType, index: usize) ?&Node {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn firstToken(self: &NodeErrorType) Token {
|
||||
return self.token;
|
||||
}
|
||||
|
||||
pub fn lastToken(self: &NodeErrorType) Token {
|
||||
return self.token;
|
||||
}
|
||||
};
|
||||
|
||||
pub const NodeLineComment = struct {
|
||||
base: Node,
|
||||
lines: ArrayList(Token),
|
||||
|
|
|
@ -451,6 +451,42 @@ pub const Parser = struct {
|
|||
try stack.append(State.AfterOperand);
|
||||
continue;
|
||||
},
|
||||
Token.Id.Keyword_this => {
|
||||
const node = try arena.create(ast.NodeThisLiteral);
|
||||
*node = ast.NodeThisLiteral {
|
||||
.base = self.initNode(ast.Node.Id.ThisLiteral),
|
||||
.token = token,
|
||||
};
|
||||
try stack.append(State {
|
||||
.Operand = &node.base
|
||||
});
|
||||
try stack.append(State.AfterOperand);
|
||||
continue;
|
||||
},
|
||||
Token.Id.Keyword_unreachable => {
|
||||
const node = try arena.create(ast.NodeUnreachable);
|
||||
*node = ast.NodeUnreachable {
|
||||
.base = self.initNode(ast.Node.Id.Unreachable),
|
||||
.token = token,
|
||||
};
|
||||
try stack.append(State {
|
||||
.Operand = &node.base
|
||||
});
|
||||
try stack.append(State.AfterOperand);
|
||||
continue;
|
||||
},
|
||||
Token.Id.Keyword_error => {
|
||||
const node = try arena.create(ast.NodeErrorType);
|
||||
*node = ast.NodeErrorType {
|
||||
.base = self.initNode(ast.Node.Id.ErrorType),
|
||||
.token = token,
|
||||
};
|
||||
try stack.append(State {
|
||||
.Operand = &node.base
|
||||
});
|
||||
try stack.append(State.AfterOperand);
|
||||
continue;
|
||||
},
|
||||
Token.Id.Builtin => {
|
||||
const node = try arena.create(ast.NodeBuiltinCall);
|
||||
*node = ast.NodeBuiltinCall {
|
||||
|
@ -1499,6 +1535,18 @@ pub const Parser = struct {
|
|||
const null_literal = @fieldParentPtr(ast.NodeNullLiteral, "base", base);
|
||||
try stream.print("{}", self.tokenizer.getTokenSlice(null_literal.token));
|
||||
},
|
||||
ast.Node.Id.ThisLiteral => {
|
||||
const this_literal = @fieldParentPtr(ast.NodeThisLiteral, "base", base);
|
||||
try stream.print("{}", self.tokenizer.getTokenSlice(this_literal.token));
|
||||
},
|
||||
ast.Node.Id.Unreachable => {
|
||||
const unreachable_node = @fieldParentPtr(ast.NodeUnreachable, "base", base);
|
||||
try stream.print("{}", self.tokenizer.getTokenSlice(unreachable_node.token));
|
||||
},
|
||||
ast.Node.Id.ErrorType => {
|
||||
const error_type = @fieldParentPtr(ast.NodeErrorType, "base", base);
|
||||
try stream.print("{}", self.tokenizer.getTokenSlice(error_type.token));
|
||||
},
|
||||
ast.Node.Id.MultilineStringLiteral => {
|
||||
const multiline_str_literal = @fieldParentPtr(ast.NodeMultilineStringLiteral, "base", base);
|
||||
try stream.print("\n");
|
||||
|
|
Loading…
Reference in New Issue