Skip to content

Commit 0e5fe1b

Browse files
committed
refactor(rivetc.parser+rivet/parser): change slice syntax ([..] -> [:])
1 parent 3f528fc commit 0e5fe1b

File tree

15 files changed

+37
-37
lines changed

15 files changed

+37
-37
lines changed

cmd/src/rivet.ri

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2-
// source code is governed by an MIT license that can be found in the LICENSE
1+
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2+
// source code is governed by an MIT license that can be found in the LICENSE
33
// file.
44

55
import std/console;
@@ -41,13 +41,13 @@ func main() {
4141
// These commands are handled directly by the compiler.
4242
is_test := cmd == "test";
4343
mut prefs_ := prefs.Prefs.from_args(
44-
process.args[2..], is_test, is_test || cmd == "run", cmd == "check"
44+
process.args[2:], is_test, is_test || cmd == "run", cmd == "check"
4545
)!;
4646
prefs_.load_module_info()!;
4747
rivet.compile(prefs_)!;
4848
},
49-
"new", "init" -> tools.cmd_new(process.args[2..], cmd == "init")!,
50-
"fmt" -> tools.cmd_fmt(process.args[2..])!,
49+
"new", "init" -> tools.cmd_new(process.args[2:], cmd == "init")!,
50+
"fmt" -> tools.cmd_fmt(process.args[2:])!,
5151
"version" -> {
5252
console.ewriteln(utils.full_version());
5353
process.exit(0);

lib/rivet/src/ast/Env.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub struct Env {
135135
new_inputs.push(input);
136136
continue;
137137
}
138-
exts := base_name_input.substr(end: base_name_input.len - 3).split(".")[1..];
138+
exts := base_name_input.substr(end: base_name_input.len - 3).split(".")[1:];
139139
mut already_exts := []string(cap: exts.len);
140140
mut should_compile := false;
141141
for ext in exts {

lib/rivet/src/builder/mod.ri

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ pub struct Builder {
9595
}
9696
}
9797

98+
func parse_files(mut self, mod_sym: ast.Module, files: []string) {
99+
for sf in parser.Parser(env: self.env).parse_module(mod_sym, files) {
100+
self.env.source_files.push(sf);
101+
}
102+
if report.total_errors() > 0 {
103+
self.abort();
104+
}
105+
}
106+
98107
func load_root_module(mut self) -> ! {
99108
files := if Path.is_directory(self.env.prefs.input) {
100109
mut filtered_files := self.env.filter_files(
@@ -137,8 +146,8 @@ pub struct Builder {
137146

138147
func import_modules(mut self) -> ! {
139148
for mut sf in self.env.source_files {
140-
for mut d in sf.decls {
141-
if d is .Import(mut import_decl) {
149+
for mut decl in sf.decls {
150+
if decl is .Import(mut import_decl) {
142151
if self.env.universe.scope.exists(import_decl.info.full_name) {
143152
continue;
144153
}
@@ -217,8 +226,8 @@ pub struct Builder {
217226
);
218227
full_name = if "src" in names {
219228
src_idx := utils.index_of(names, "src");
220-
utils.join(names[..src_idx], ".").concat(
221-
".", utils.join(names[src_idx + 1..], ".")
229+
utils.join(names[:src_idx], ".").concat(
230+
".", utils.join(names[src_idx + 1:], ".")
222231
)
223232
} else {
224233
utils.join(names, ".")
@@ -272,15 +281,6 @@ pub struct Builder {
272281
);
273282
}
274283

275-
func parse_files(mut self, mod_sym: ast.Module, files: []string) {
276-
for sf in parser.Parser(env: self.env).parse_module(mod_sym, files) {
277-
self.env.source_files.push(sf);
278-
}
279-
if report.total_errors() > 0 {
280-
self.abort();
281-
}
282-
}
283-
284284
func resolve_deps(mut self) {
285285
g := self.import_graph();
286286
g_resolved := g.resolve();

lib/rivet/src/checker/call_expr.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ extend Checker {
422422
// check default expressions
423423
if func_.has_named_args {
424424
args_len := call_expr.pure_args_count();
425-
mut args := call_expr.args[..args_len];
425+
mut args := call_expr.args[:args_len];
426426
mut i: uint := args_len;
427427
while i < func_args_len : i += 1 {
428428
arg := func_.args[i];

lib/rivet/src/checker/exprs.ri

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ extend Checker {
269269
}
270270
self.inside_unsafe_block = false;
271271
}
272-
block.defer_stmts = self.defer_stmts[self.defer_stmts_start..];
273-
self.defer_stmts = self.defer_stmts[..self.defer_stmts_start];
272+
block.defer_stmts = self.defer_stmts[self.defer_stmts_start:];
273+
self.defer_stmts = self.defer_stmts[:self.defer_stmts_start];
274274
block.type
275275
},
276276
.Unary(mut unary) -> self.check_unary(unary),

lib/rivet/src/checker/match_expr.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ extend Checker {
201201
err_details = err_details.concat(utils.join(unhandled, ", "));
202202
} else {
203203
err_details = err_details.concat(
204-
utils.join(unhandled[..MATCH_EXHAUSTIVE_CUTOFF_LIMIT], ", ")
204+
utils.join(unhandled[:MATCH_EXHAUSTIVE_CUTOFF_LIMIT], ", ")
205205
);
206206
remaining := unhandled.len - MATCH_EXHAUSTIVE_CUTOFF_LIMIT;
207207
if remaining > 0 {

lib/rivet/src/codegen/mir/mod.ri

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub struct Func < traits.Stringable {
158158
sb.write_string("extern ");
159159
}
160160
sb.write_string("func @{}(".fmt(self.name));
161-
for i, arg in self.locals[..self.args_len] {
161+
for i, arg in self.locals[:self.args_len] {
162162
sb.write_fmt("%{}: {}", arg.dbg_name, arg.type);
163163
if i < self.args_len - 1 {
164164
sb.write_string(", ");
@@ -170,7 +170,7 @@ pub struct Func < traits.Stringable {
170170
} else {
171171
sb.writeln(" {");
172172
if self.blocks.len > 0 {
173-
locals := self.locals[self.args_len..];
173+
locals := self.locals[self.args_len:];
174174
for local in locals {
175175
sb.writeln_fmt(" var %{}: {};", local.dbg_name, local.type);
176176
}

lib/rivet/src/parser/exprs.ri

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2-
// source code is governed by an MIT license that can be found in the LICENSE
1+
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2+
// source code is governed by an MIT license that can be found in the LICENSE
33
// file.
44

55
import ../ast;
@@ -498,7 +498,7 @@ extend Parser {
498498
)
499499
},
500500
self.accept(.Lbracket) -> {
501-
index: ast.Expr := if self.accept(.DotDot) {
501+
index: ast.Expr := if self.accept(.Colon) {
502502
if self.tok.kind == .Rbracket {
503503
.Range(pos: expr.position() + self.tok.pos)
504504
} else {
@@ -509,7 +509,7 @@ extend Parser {
509509
}
510510
} else {
511511
start := self.parse_expr();
512-
if self.accept(.DotDot) {
512+
if self.accept(.Colon) {
513513
if self.tok.kind == .Rbracket {
514514
.Range(
515515
start: start, has_start: true,

lib/rivet/src/token/Kind.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var kind_strings := [
105105
KindMap(.KwWhile, "while")
106106
];
107107

108-
var keywords_table := kind_strings[@as(uint, Kind.KeywordBegin)..];
108+
var keywords_table := kind_strings[@as(uint, Kind.KeywordBegin):];
109109

110110
pub enum Kind < traits.Stringable {
111111
Unknown, // unknown

lib/rivet/src/utils/file.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct SourceCache {
6060
pub func find_lines_between(mut self, path_: string, line: uint, end_line: uint) -> ?[]string {
6161
return if lines := self.find_lines(path_) {
6262
if lines.len > 0 && lines.len >= end_line {
63-
lines[line..end_line]
63+
lines[line:end_line]
6464
} else {
6565
none
6666
}

lib/std/src/flag/mod.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct FlagParser {
7979
if v := idx_dashdash {
8080
all_before_dashdash.trim(v);
8181
if v < original_args.len {
82-
all_after_dashdash = original_args[v + 1..];
82+
all_after_dashdash = original_args[v + 1:];
8383
}
8484
}
8585
return Self(

lib/std/src/fs/Path.c.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub struct Path {
184184
defer(error) unsafe {
185185
mem.dealloc(result)
186186
}
187-
for p in paths[first_index..] {
187+
for p in paths[first_index:] {
188188
mut components := p.tokenize(SEPARATOR);
189189
while component := components.next() {
190190
if component == "." {

lib/std/src/hash/fnv1a/mod.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file.
44

55
// This module implements a FNV-1a hash.
6-
// See: https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function
6+
// See: https..//en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function
77

88
const FNV32_PRIME: uint32 := 16777619;
99
const FNV32_OFFSET_BASIS: uint32 := 2166136261;

rivetc/src/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def parse_primary_expr(self):
10561056
)
10571057
elif self.accept(Kind.Lbracket):
10581058
index = self.empty_expr()
1059-
if self.accept(Kind.DotDot):
1059+
if self.accept(Kind.Colon):
10601060
if self.tok.kind == Kind.Rbracket:
10611061
index = ast.RangeExpr(
10621062
None, None, False, index.pos, False, False
@@ -1068,7 +1068,7 @@ def parse_primary_expr(self):
10681068
)
10691069
else:
10701070
index = self.parse_expr()
1071-
if self.accept(Kind.DotDot):
1071+
if self.accept(Kind.Colon):
10721072
if self.tok.kind == Kind.Rbracket:
10731073
index = ast.RangeExpr(
10741074
index, None, False, index.pos, True, False

tests/valid/src/dynamic_array.ri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test "dynamic array from fixed array" {
22
arr := [1, 2, 3];
3-
mut dyn_array := arr[..];
3+
mut dyn_array := arr[:];
44
dyn_array.push(2);
55
@assert(dyn_array.len == 4);
66

0 commit comments

Comments
 (0)