Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/language/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ let mut n = 27;
let mut steps = 0;
while n != 1 {
n = if n % 2 == 0 { math.idiv(n, 2) } else { 3 * n + 1 };
steps++;
steps += 1;
}
print(steps); // 111
```
5 changes: 2 additions & 3 deletions docs/src/language/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ let name = "ann";
let mut visits = 0;

visits += 1;
visits++;
print("{name} visited {visits} times"); // ann visited 2 times
print("{name} visited {visits} times"); // ann visited 1 times
```

Changing a `let` variable, with `=`, `+=`, `++` or any other assignment, is
Changing a `let` variable, with `=`, `+=` or any other assignment, is
caught at compile time, before the program runs:

```rune
Expand Down
2 changes: 1 addition & 1 deletion docs/src/stdlib/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int(1e300); // ValueError: int() cannot convert 1e+300 to an integer.

## object

`object()` makes an empty object. `object(src)` makes one from a map or an
`object(src)` makes an object from a map or an
array of `[key, value]` pairs; the keys must be strings. To copy an object
or a struct into a new object, use [spread](../language/spread-and-rest.md):
`{ ...src }`.
Expand Down
21 changes: 12 additions & 9 deletions examples/blog/md/block.rn
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ export fun render(src) {
let line = lines[i];

if line.trim() == "" {
i++;
i += 1;
continue;
}

if line.startsWith("```") {
let lang = line[3..].trim();
let mut code = [];
i++;
i += 1;

while i < lines.len() && !lines[i].startsWith("```") {
code.push(lines[i++]);
code.push(lines[i]);
i += 1;
}

i++;
i += 1;
let cls = if lang == "" { "" } else { " class=\"lang-{lang}\"" };
doc.html.push("<pre><code{cls}>{inline.escape(code.join("\n"))}</code></pre>");
continue;
Expand All @@ -53,21 +54,22 @@ export fun render(src) {
let id = slug(text);
doc.headings.push(Heading { level, text, id });
doc.html.push("""<h{level} id="{id}">{inline.render(text)}</h{level}>""");
i++;
i += 1;
continue;
}

if regex.test(r"^(-{3,}|\*{3,})$", line.trim()) {
doc.html.push("<hr>");
i++;
i += 1;
continue;
}

if line.startsWith(">") {
let mut quote = [];

while i < lines.len() && lines[i].startsWith(">") {
quote.push(lines[i++][1..].trim());
quote.push(lines[i][1..].trim());
i += 1;
}

doc.html.push("<blockquote><p>{inline.render(quote.join(" "))}</p></blockquote>");
Expand All @@ -88,7 +90,7 @@ export fun render(src) {
}

items.push("<li>{inline.render(it.text)}</li>");
i++;
i += 1;
}

doc.html.push("<{tag}>{items.join("")}</{tag}>");
Expand All @@ -98,7 +100,8 @@ export fun render(src) {
let mut para = [];

while i < lines.len() && !startsBlock(lines[i]) {
para.push(lines[i++].trim());
para.push(lines[i].trim());
i += 1;
}

doc.html.push("<p>{inline.render(para.join(" "))}</p>");
Expand Down
2 changes: 1 addition & 1 deletion examples/calc.rn
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Parser {

fun next(mut self) {
let t = self.tokens[self.i];
self.i++;
self.i += 1;
return t;
}

Expand Down
12 changes: 6 additions & 6 deletions examples/chess.rn
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Position {
kings[color(if p > 0 { 1 } else { -1 })] = sq(file, rank);
}

file++;
file += 1;
}

if file != 8 {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Position {
let p = self.board[sq(f, r)];

if p == EMPTY {
gap++;
gap += 1;
continue;
}

Expand Down Expand Up @@ -696,7 +696,7 @@ impl Search {
return self.quiesce(alpha, beta, ply);
}

self.nodes++;
self.nodes += 1;

let entry = self.tt?.[self.pos.hash];

Expand Down Expand Up @@ -724,7 +724,7 @@ impl Search {
continue;
}

legal++;
legal += 1;
let score = -self.negamax(remaining - 1, -beta, -a, ply + 1);
self.pos.unmake();

Expand Down Expand Up @@ -764,7 +764,7 @@ impl Search {
}

fun quiesce(mut self, alpha, beta, ply) {
self.nodes++;
self.nodes += 1;
let stand = self.pos.score * self.pos.side;

if stand >= beta {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ fun options(args) {
}

out.rest.push(arg);
i++;
i += 1;
}

return out;
Expand Down
14 changes: 7 additions & 7 deletions examples/kv/store.rn
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Store {
self.replay(id, i == ids.len() - 1, rec);
}

rec.segments++;
rec.segments += 1;
}

// A compacted segment, the one with a hint, is never appended to
Expand Down Expand Up @@ -180,7 +180,7 @@ impl Store {
}

self.apply(r.key, codec.Loc { seg: id, start: r.start, recLen: r.recLen, size: r.size }, r.kind);
rec.records++;
rec.records += 1;
at += r.recLen;
}
}
Expand All @@ -191,7 +191,7 @@ impl Store {
while at < data.len() {
let h = codec.decodeHint(data, at, id) ?? throw KvError { message: "{fs.base(self.segs[id].hint)}: bad entry at byte {at}" };
self.apply(h.key, h.loc, codec.PUT);
rec.hinted++;
rec.hinted += 1;
at = h.next;
}
}
Expand All @@ -217,13 +217,13 @@ impl Store {
self.out.flush();
}

self.writes++;
self.writes += 1;
self.apply(key, loc, kind);
}

fun rotate(mut self) {
self.out.close();
self.active++;
self.active += 1;
self.openActive();
}

Expand Down Expand Up @@ -282,7 +282,7 @@ impl Store {
let mut keydir = map();

for chunk in chunks(self.keydir.entries(), self.maxSegment) {
self.active++;
self.active += 1;
let mut log = bytes.buffer();
let mut hints = bytes.buffer();

Expand All @@ -309,7 +309,7 @@ impl Store {

self.segs = segs;
self.keydir = keydir;
self.active++;
self.active += 1;
self.openActive();
return { before, after: self.info() };
}
Expand Down
8 changes: 4 additions & 4 deletions examples/log-report.rn
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ impl Stats {
fun new() { Stats {} }

fun add(mut self, { status, bytes, latency }) {
self.count++;
self.count += 1;
self.bytes += bytes;

if status >= 500 {
self.errors++;
self.errors += 1;
}

self.latencies.push(latency);
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Report {
fun new() { Report {} }

fun add(mut self, e) {
self.total++;
self.total += 1;

let key = "{e.method} {e.path}";

Expand All @@ -100,7 +100,7 @@ impl Report {
self.clients[e.ip] = { hits: 0, paths: set() };
}

self.clients[e.ip].hits++;
self.clients[e.ip].hits += 1;
self.clients[e.ip].paths.add(e.path);

self.slowest.push(e);
Expand Down
6 changes: 3 additions & 3 deletions examples/query/aggregate.rn
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun accumulate(mut acc, aggs, r) {
let a = aggs[i];

if a.arg == nil {
acc[i]++;
acc[i] += 1;
continue;
}

Expand All @@ -85,11 +85,11 @@ fun accumulate(mut acc, aggs, r) {
}

match a.fn {
Agg.Count => acc[i]++,
Agg.Count => acc[i] += 1,
Agg.Sum => acc[i] = (acc[i] ?? 0) + v,
Agg.Avg => {
acc[i][0] += v;
acc[i][1]++;
acc[i][1] += 1;
},
Agg.Min => { if acc[i] == nil || expr.compare(v, acc[i]) < 0 {
acc[i] = v;
Expand Down
14 changes: 10 additions & 4 deletions examples/query/main.rn
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ fun main(args) {

while i < args.len() {
match args[i] {
"-d" => dir = args?.[++i] ?? return usage(),
"-f" => format = args?.[++i] ?? return usage(),
"-d" => {
i += 1;
dir = args?.[i] ?? return usage();
},
"-f" => {
i += 1;
format = args?.[i] ?? return usage();
},
a => rest.push(a),
}

i++;
i += 1;
}

if format !in output.FORMATS {
Expand All @@ -104,7 +110,7 @@ fun main(args) {

while line != nil {
if line.trim() != "" && !tryRun(line, catalog, format) {
failed++;
failed += 1;
}

line = io.readLine();
Expand Down
6 changes: 3 additions & 3 deletions examples/query/parser.rn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Parser {
let t = self.tokens[self.i];

if t.kind != Kind.Eof {
self.i++;
self.i += 1;
}

return t;
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Parser {
return ast.Like { expr, pattern: self.expr(5), not };
}

self.i--;
self.i -= 1;
self.fail("expected IN, BETWEEN or LIKE after NOT");
}

Expand All @@ -284,7 +284,7 @@ impl Parser {
Token { kind: Kind.Id, text, word, pos } if word !in RESERVED => self.reference(text, word, pos),
_ => {
if t.kind != Kind.Eof {
self.i--;
self.i -= 1;
}

self.fail("expected an expression");
Expand Down
4 changes: 2 additions & 2 deletions examples/query/table.rn
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fun splitCsv(line) {
if c == "\"" {
if chars?.[i + 1] == "\"" {
cell.push("\"");
i++;
i += 1;
} else {
quoted = false;
}
Expand All @@ -116,7 +116,7 @@ fun splitCsv(line) {
cell.push(c);
}

i++;
i += 1;
}

cells.push(cell.join(""));
Expand Down
2 changes: 1 addition & 1 deletion examples/shop.rn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Client {
let r = self.send("POST", "/auth/refresh", { refreshToken: self.refreshToken });
self.token = r.accessToken;
self.refreshToken = r.refreshToken;
self.refreshes++;
self.refreshes += 1;
}

fun expire(mut self) {
Expand Down
2 changes: 1 addition & 1 deletion examples/todo.rn
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Store {

fun add(mut self, task) {
self.tasks.push(Task({ ...task, id: self.nextId }));
self.nextId++;
self.nextId += 1;
return self.nextId - 1;
}

Expand Down
Loading
Loading