aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/errmsg.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-07-14 18:27:51 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-07-14 18:27:51 -0400
commit4d920cee6e8be2f2ae2cfd9067358c65b977568a (patch)
tree2c04de6151b7448dec9958d0a91234ea0ba9a15d /src-self-hosted/errmsg.zig
parentda3acacc14331a6be33445c3bfd204e2cccabddd (diff)
parent28c3d4809bc6d497ac81892bc7eb03b95d8c2b32 (diff)
downloadzig-4d920cee6e8be2f2ae2cfd9067358c65b977568a.tar.gz
zig-4d920cee6e8be2f2ae2cfd9067358c65b977568a.zip
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'src-self-hosted/errmsg.zig')
-rw-r--r--src-self-hosted/errmsg.zig25
1 files changed, 19 insertions, 6 deletions
diff --git a/src-self-hosted/errmsg.zig b/src-self-hosted/errmsg.zig
index b6fd78d8f6..4e353bfb14 100644
--- a/src-self-hosted/errmsg.zig
+++ b/src-self-hosted/errmsg.zig
@@ -11,11 +11,22 @@ pub const Color = enum {
On,
};
+pub const Span = struct {
+ first: ast.TokenIndex,
+ last: ast.TokenIndex,
+
+ pub fn token(i: TokenIndex) Span {
+ return Span {
+ .first = i,
+ .last = i,
+ };
+ }
+};
+
pub const Msg = struct {
path: []const u8,
text: []u8,
- first_token: TokenIndex,
- last_token: TokenIndex,
+ span: Span,
tree: *ast.Tree,
};
@@ -39,8 +50,10 @@ pub fn createFromParseError(
.tree = tree,
.path = path,
.text = text_buf.toOwnedSlice(),
- .first_token = loc_token,
- .last_token = loc_token,
+ .span = Span{
+ .first = loc_token,
+ .last = loc_token,
+ },
});
errdefer allocator.destroy(msg);
@@ -48,8 +61,8 @@ pub fn createFromParseError(
}
pub fn printToStream(stream: var, msg: *const Msg, color_on: bool) !void {
- const first_token = msg.tree.tokens.at(msg.first_token);
- const last_token = msg.tree.tokens.at(msg.last_token);
+ const first_token = msg.tree.tokens.at(msg.span.first);
+ const last_token = msg.tree.tokens.at(msg.span.last);
const start_loc = msg.tree.tokenLocationPtr(0, first_token);
const end_loc = msg.tree.tokenLocationPtr(first_token.end, last_token);
if (!color_on) {