selfhost/cmd/wcc: drop snake_case from 119 cross-cutting identifiers
This commit is contained in:
@@ -56,12 +56,12 @@ export fn parserinit(p: *parser, a: *arena, l: *lex) void = {
|
||||
|
||||
fn advance(p: *parser) void = { refill(p); };
|
||||
|
||||
fn accept_tok(p: *parser, k: i32) bool = {
|
||||
fn accepttok(p: *parser, k: i32) bool = {
|
||||
if (p.cur_kind == k) { advance(p); return true; };
|
||||
return false;
|
||||
};
|
||||
|
||||
fn err_msg(p: *parser, msg: str) void = {
|
||||
fn errmsg(p: *parser, msg: str) void = {
|
||||
let pre: str = "parse: ";
|
||||
os.write(2, pre.ptr, pre.len: u64);
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
@@ -69,9 +69,9 @@ fn err_msg(p: *parser, msg: str) void = {
|
||||
p.errs += 1;
|
||||
};
|
||||
|
||||
fn expect_tok(p: *parser, k: i32, what: str) bool = {
|
||||
fn expecttok(p: *parser, k: i32, what: str) bool = {
|
||||
if (p.cur_kind == k) { advance(p); return true; };
|
||||
err_msg(p, what);
|
||||
errmsg(p, what);
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ fn expect_tok(p: *parser, k: i32, what: str) bool = {
|
||||
// Returns the empty str on error (and advances to make progress).
|
||||
fn expectident(p: *parser, into: *str) bool = {
|
||||
if (p.cur_kind != TK_IDENT) {
|
||||
err_msg(p, "expected identifier");
|
||||
errmsg(p, "expected identifier");
|
||||
advance(p);
|
||||
return false;
|
||||
};
|
||||
@@ -116,14 +116,14 @@ fn parsetype(p: *parser) *node = {
|
||||
};
|
||||
let n: *node = newnode(p.a, N_TARRAY, pf, pl, pc);
|
||||
n.rhs = parseexpr(p);
|
||||
expect_tok(p, TK_RBRACK, "expected ']' in array type");
|
||||
expecttok(p, TK_RBRACK, "expected ']' in array type");
|
||||
n.lhs = parsetype(p);
|
||||
return n;
|
||||
};
|
||||
|
||||
if (p.cur_kind == TK_STRUCT) {
|
||||
advance(p);
|
||||
expect_tok(p, TK_LBRACE, "expected '{' after struct");
|
||||
expecttok(p, TK_LBRACE, "expected '{' after struct");
|
||||
let n: *node = newnode(p.a, N_TSTRUCT, pf, pl, pc);
|
||||
let fhead: *node = nil;
|
||||
let ftail: *node = nil;
|
||||
@@ -136,13 +136,13 @@ fn parsetype(p: *parser) *node = {
|
||||
let fid: str;
|
||||
expectident(p, &fid);
|
||||
f.str = fid;
|
||||
expect_tok(p, TK_COLON, "expected ':' in field");
|
||||
expecttok(p, TK_COLON, "expected ':' in field");
|
||||
f.lhs = parsetype(p);
|
||||
if (fhead == nil) { fhead = f; ftail = f; }
|
||||
else { ftail.next = f; ftail = f; };
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
};
|
||||
expect_tok(p, TK_RBRACE, "expected '}' after struct fields");
|
||||
expecttok(p, TK_RBRACE, "expected '}' after struct fields");
|
||||
n.list = fhead;
|
||||
return n;
|
||||
};
|
||||
@@ -160,7 +160,7 @@ fn parsetype(p: *parser) *node = {
|
||||
// (T) or (T, T, ...) or (T | T | ...)
|
||||
advance(p);
|
||||
let first: *node = parsetype(p);
|
||||
if (accept_tok(p, TK_PIPE)) {
|
||||
if (accepttok(p, TK_PIPE)) {
|
||||
let n: *node = newnode(p.a, N_TTAGGED, pf, pl, pc);
|
||||
let head: *node = first;
|
||||
let tail: *node = first;
|
||||
@@ -168,14 +168,14 @@ fn parsetype(p: *parser) *node = {
|
||||
let e: *node = parsetype(p);
|
||||
tail.next = e;
|
||||
tail = e;
|
||||
if (!accept_tok(p, TK_PIPE)) { break; };
|
||||
if (!accepttok(p, TK_PIPE)) { break; };
|
||||
};
|
||||
expect_tok(p, TK_RPAREN, "expected ')' in tagged-union type");
|
||||
expecttok(p, TK_RPAREN, "expected ')' in tagged-union type");
|
||||
n.list = head;
|
||||
return n;
|
||||
};
|
||||
if (!accept_tok(p, TK_COMMA)) {
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after parenthesised type");
|
||||
if (!accepttok(p, TK_COMMA)) {
|
||||
expecttok(p, TK_RPAREN, "expected ')' after parenthesised type");
|
||||
return first;
|
||||
};
|
||||
let n: *node = newnode(p.a, N_TTUPLE, pf, pl, pc);
|
||||
@@ -185,28 +185,28 @@ fn parsetype(p: *parser) *node = {
|
||||
let e: *node = parsetype(p);
|
||||
tail.next = e;
|
||||
tail = e;
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
if (p.cur_kind == TK_RPAREN) { break; };
|
||||
};
|
||||
expect_tok(p, TK_RPAREN, "expected ')' in tuple type");
|
||||
expecttok(p, TK_RPAREN, "expected ')' in tuple type");
|
||||
n.list = head;
|
||||
return n;
|
||||
};
|
||||
|
||||
if (p.cur_kind == TK_FN) {
|
||||
advance(p);
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after fn in type");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after fn in type");
|
||||
let n: *node = newnode(p.a, N_TFN, pf, pl, pc);
|
||||
// Anonymous-or-named params: parseparams handles named only;
|
||||
// for fn-type expressions the C parser allows IDENT-less
|
||||
// (anonymous) params. Stub: only named params for now.
|
||||
n.list = parseparams(p);
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after fn type params");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after fn type params");
|
||||
n.lhs = parsetype(p);
|
||||
return n;
|
||||
};
|
||||
|
||||
err_msg(p, "expected type");
|
||||
errmsg(p, "expected type");
|
||||
advance(p);
|
||||
return newnode(p.a, N_TNAME, pf, pl, pc);
|
||||
};
|
||||
@@ -298,7 +298,7 @@ fn parseprimary(p: *parser) *node = {
|
||||
advance(p);
|
||||
let e: *node = parseexpr(p);
|
||||
// Tuple literal: (a, b, ...)
|
||||
if (accept_tok(p, TK_COMMA)) {
|
||||
if (accepttok(p, TK_COMMA)) {
|
||||
let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc);
|
||||
t.list = e;
|
||||
let tail: *node = e;
|
||||
@@ -307,12 +307,12 @@ fn parseprimary(p: *parser) *node = {
|
||||
let en: *node = parseexpr(p);
|
||||
tail.next = en;
|
||||
tail = en;
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
};
|
||||
expect_tok(p, TK_RPAREN, "expected ')' in tuple");
|
||||
expecttok(p, TK_RPAREN, "expected ')' in tuple");
|
||||
return t;
|
||||
};
|
||||
expect_tok(p, TK_RPAREN, "expected ')'");
|
||||
expecttok(p, TK_RPAREN, "expected ')'");
|
||||
return e;
|
||||
};
|
||||
if (p.cur_kind == TK_IDENT) {
|
||||
@@ -338,16 +338,16 @@ fn parseprimary(p: *parser) *node = {
|
||||
let fpc: i32 = p.cur_col;
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
expect_tok(p, TK_ASSIGN, "expected '=' in struct lit field");
|
||||
expecttok(p, TK_ASSIGN, "expected '=' in struct lit field");
|
||||
let v: *node = parseexpr(p);
|
||||
let f: *node = newnode(p.a, N_FIELD, fpf, fpl, fpc);
|
||||
f.str = id;
|
||||
f.lhs = v;
|
||||
if (head == nil) { head = f; tail = f; }
|
||||
else { tail.next = f; tail = f; };
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
};
|
||||
expect_tok(p, TK_RBRACE, "expected '}' after struct literal");
|
||||
expecttok(p, TK_RBRACE, "expected '}' after struct literal");
|
||||
s.list = head;
|
||||
return s;
|
||||
};
|
||||
@@ -356,11 +356,11 @@ fn parseprimary(p: *parser) *node = {
|
||||
if (p.cur_kind == TK_MATCH) {
|
||||
// match (e) { case let v: T => stmt; case T => stmt; case => stmt; };
|
||||
advance(p);
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after match");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after match");
|
||||
let m: *node = newnode(p.a, N_MATCH, pf, pl, pc);
|
||||
m.lhs = parseexpr(p);
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after match scrutinee");
|
||||
expect_tok(p, TK_LBRACE, "expected '{' to open match body");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after match scrutinee");
|
||||
expecttok(p, TK_LBRACE, "expected '{' to open match body");
|
||||
let head: *node = nil;
|
||||
let tail: *node = nil;
|
||||
for (p.cur_kind == TK_CASE) {
|
||||
@@ -374,21 +374,21 @@ fn parseprimary(p: *parser) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
mc.str = id;
|
||||
expect_tok(p, TK_COLON, "expected ':' after match binding");
|
||||
expecttok(p, TK_COLON, "expected ':' after match binding");
|
||||
mc.lhs = parsetype(p);
|
||||
} else { if (p.cur_kind != TK_FATARROW) {
|
||||
mc.lhs = parsetype(p);
|
||||
};};
|
||||
expect_tok(p, TK_FATARROW, "expected '=>' in match arm");
|
||||
expecttok(p, TK_FATARROW, "expected '=>' in match arm");
|
||||
mc.body = parsestmt(p);
|
||||
if (head == nil) { head = mc; tail = mc; }
|
||||
else { tail.next = mc; tail = mc; };
|
||||
};
|
||||
expect_tok(p, TK_RBRACE, "expected '}' after match body");
|
||||
expecttok(p, TK_RBRACE, "expected '}' after match body");
|
||||
m.list = head;
|
||||
return m;
|
||||
};
|
||||
err_msg(p, "expected expression");
|
||||
errmsg(p, "expected expression");
|
||||
advance(p);
|
||||
return newnode(p.a, N_NONE, pf, pl, pc);
|
||||
};
|
||||
@@ -402,7 +402,7 @@ fn parsearglist(p: *parser, close_kind: i32, head_out: **node) void = {
|
||||
let e: *node = parseexpr(p);
|
||||
if (head == nil) { head = e; tail = e; }
|
||||
else { tail.next = e; tail = e; };
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
if (p.cur_kind == close_kind) { break; };
|
||||
};
|
||||
*head_out = head;
|
||||
@@ -421,7 +421,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = {
|
||||
let arghead: *node = nil;
|
||||
parsearglist(p, TK_RPAREN, &arghead);
|
||||
n.list = arghead;
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after args");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after args");
|
||||
cur = n;
|
||||
continue;
|
||||
};
|
||||
@@ -435,7 +435,7 @@ fn parsepostfix(p: *parser, lhs: *node) *node = {
|
||||
if (p.cur_kind != TK_RBRACK) {
|
||||
n.cond = parseexpr(p);
|
||||
};
|
||||
expect_tok(p, TK_RBRACK, "expected ']' in slice");
|
||||
expecttok(p, TK_RBRACK, "expected ']' in slice");
|
||||
cur = n;
|
||||
continue;
|
||||
};
|
||||
@@ -453,14 +453,14 @@ fn parsepostfix(p: *parser, lhs: *node) *node = {
|
||||
if (p.cur_kind != TK_RBRACK) {
|
||||
n.cond = parseexpr(p);
|
||||
};
|
||||
expect_tok(p, TK_RBRACK, "expected ']' in slice");
|
||||
expecttok(p, TK_RBRACK, "expected ']' in slice");
|
||||
cur = n;
|
||||
continue;
|
||||
};
|
||||
let n: *node = newnode(p.a, N_INDEX, pf, pl, pc);
|
||||
n.lhs = cur;
|
||||
n.rhs = e;
|
||||
expect_tok(p, TK_RBRACK, "expected ']' after index");
|
||||
expecttok(p, TK_RBRACK, "expected ']' after index");
|
||||
cur = n;
|
||||
continue;
|
||||
};
|
||||
@@ -581,7 +581,7 @@ fn parseexpr(p: *parser) *node = {
|
||||
// (single-cond C-style), expr-stmt, defer, break, continue. Switch
|
||||
// and match arms are not yet wired; tuple-let / multi-let neither.
|
||||
|
||||
fn parselet_local(p: *parser) *node = {
|
||||
fn parseletlocal(p: *parser) *node = {
|
||||
let pf: str = p.cur_file;
|
||||
let pl: i32 = p.cur_line;
|
||||
let pc: i32 = p.cur_col;
|
||||
@@ -590,13 +590,13 @@ fn parselet_local(p: *parser) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
if (accept_tok(p, TK_COLON)) {
|
||||
if (accepttok(p, TK_COLON)) {
|
||||
n.lhs = parsetype(p);
|
||||
};
|
||||
if (accept_tok(p, TK_ASSIGN)) {
|
||||
if (accepttok(p, TK_ASSIGN)) {
|
||||
n.rhs = parseexpr(p);
|
||||
};
|
||||
expect_tok(p, TK_SEMI, "expected ';' after let");
|
||||
expecttok(p, TK_SEMI, "expected ';' after let");
|
||||
return n;
|
||||
};
|
||||
|
||||
@@ -604,7 +604,7 @@ fn parseblock(p: *parser) *node = {
|
||||
let pf: str = p.cur_file;
|
||||
let pl: i32 = p.cur_line;
|
||||
let pc: i32 = p.cur_col;
|
||||
expect_tok(p, TK_LBRACE, "expected '{' to open block");
|
||||
expecttok(p, TK_LBRACE, "expected '{' to open block");
|
||||
let blk: *node = newnode(p.a, N_BLOCK, pf, pl, pc);
|
||||
let head: *node = nil;
|
||||
let tail: *node = nil;
|
||||
@@ -616,7 +616,7 @@ fn parseblock(p: *parser) *node = {
|
||||
else { tail.next = s; tail = s; };
|
||||
};
|
||||
};
|
||||
expect_tok(p, TK_RBRACE, "expected '}' to close block");
|
||||
expecttok(p, TK_RBRACE, "expected '}' to close block");
|
||||
blk.list = head;
|
||||
return blk;
|
||||
};
|
||||
@@ -626,12 +626,12 @@ fn parseif(p: *parser) *node = {
|
||||
let pl: i32 = p.cur_line;
|
||||
let pc: i32 = p.cur_col;
|
||||
advance(p); // past `if`
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after if");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after if");
|
||||
let n: *node = newnode(p.a, N_IF, pf, pl, pc);
|
||||
n.cond = parseexpr(p);
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after if condition");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after if condition");
|
||||
n.body = parseblock(p);
|
||||
if (accept_tok(p, TK_ELSE)) {
|
||||
if (accepttok(p, TK_ELSE)) {
|
||||
if (p.cur_kind == TK_IF) {
|
||||
n.els = parseif(p);
|
||||
} else {
|
||||
@@ -646,7 +646,7 @@ fn parsefor(p: *parser) *node = {
|
||||
let pl: i32 = p.cur_line;
|
||||
let pc: i32 = p.cur_col;
|
||||
advance(p); // past `for`
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after for");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after for");
|
||||
let n: *node = newnode(p.a, N_FOR, pf, pl, pc);
|
||||
// Three forms (matching C parser):
|
||||
// for (cond) — only cond
|
||||
@@ -657,14 +657,14 @@ fn parsefor(p: *parser) *node = {
|
||||
// ';' it was cond. If we see two ';' total after init, post is
|
||||
// next. Simpler: peek for `let` to decide init form.
|
||||
if (p.cur_kind == TK_LET) {
|
||||
n.lhs = parselet_local(p); // init (consumes its own ';')
|
||||
n.lhs = parseletlocal(p); // init (consumes its own ';')
|
||||
n.cond = parseexpr(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after for cond");
|
||||
expecttok(p, TK_SEMI, "expected ';' after for cond");
|
||||
n.rhs = parseexpr(p);
|
||||
} else {
|
||||
// Parse one expr. If next is ';', it's a 3-clause without init.
|
||||
let first: *node = parseexpr(p);
|
||||
if (accept_tok(p, TK_SEMI)) {
|
||||
if (accepttok(p, TK_SEMI)) {
|
||||
// cond ; post
|
||||
n.cond = first;
|
||||
n.rhs = parseexpr(p);
|
||||
@@ -673,7 +673,7 @@ fn parsefor(p: *parser) *node = {
|
||||
n.cond = first;
|
||||
};
|
||||
};
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after for");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after for");
|
||||
n.body = parseblock(p);
|
||||
return n;
|
||||
};
|
||||
@@ -689,18 +689,18 @@ fn parsestmt(p: *parser) *node = {
|
||||
|
||||
if (p.cur_kind == TK_LBRACE) {
|
||||
let b: *node = parseblock(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after block");
|
||||
expecttok(p, TK_SEMI, "expected ';' after block");
|
||||
return b;
|
||||
};
|
||||
if (p.cur_kind == TK_LET) { return parselet_local(p); };
|
||||
if (p.cur_kind == TK_LET) { return parseletlocal(p); };
|
||||
if (p.cur_kind == TK_IF) {
|
||||
let n: *node = parseif(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after if");
|
||||
expecttok(p, TK_SEMI, "expected ';' after if");
|
||||
return n;
|
||||
};
|
||||
if (p.cur_kind == TK_FOR) {
|
||||
let n: *node = parsefor(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after for");
|
||||
expecttok(p, TK_SEMI, "expected ';' after for");
|
||||
return n;
|
||||
};
|
||||
if (p.cur_kind == TK_RETURN) {
|
||||
@@ -714,7 +714,7 @@ fn parsestmt(p: *parser) *node = {
|
||||
let t: *node = newnode(p.a, N_TUPLE, pf, pl, pc);
|
||||
t.list = first;
|
||||
let tail: *node = first;
|
||||
for (accept_tok(p, TK_COMMA)) {
|
||||
for (accepttok(p, TK_COMMA)) {
|
||||
let e: *node = parseexpr(p);
|
||||
tail.next = e;
|
||||
tail = e;
|
||||
@@ -724,24 +724,24 @@ fn parsestmt(p: *parser) *node = {
|
||||
n.lhs = first;
|
||||
};
|
||||
};
|
||||
expect_tok(p, TK_SEMI, "expected ';' after return");
|
||||
expecttok(p, TK_SEMI, "expected ';' after return");
|
||||
return n;
|
||||
};
|
||||
if (p.cur_kind == TK_DEFER) {
|
||||
advance(p);
|
||||
let n: *node = newnode(p.a, N_DEFER, pf, pl, pc);
|
||||
n.lhs = parseexpr(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after defer");
|
||||
expecttok(p, TK_SEMI, "expected ';' after defer");
|
||||
return n;
|
||||
};
|
||||
if (p.cur_kind == TK_BREAK) {
|
||||
advance(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after break");
|
||||
expecttok(p, TK_SEMI, "expected ';' after break");
|
||||
return newnode(p.a, N_BREAK, pf, pl, pc);
|
||||
};
|
||||
if (p.cur_kind == TK_CONTINUE) {
|
||||
advance(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after continue");
|
||||
expecttok(p, TK_SEMI, "expected ';' after continue");
|
||||
return newnode(p.a, N_CONTINUE, pf, pl, pc);
|
||||
};
|
||||
// expression statement, or tuple-destructure multi-assign:
|
||||
@@ -761,15 +761,15 @@ fn parsestmt(p: *parser) *node = {
|
||||
tail.next = lv;
|
||||
tail = lv;
|
||||
};
|
||||
expect_tok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues");
|
||||
expecttok(p, TK_ASSIGN, "expected '=' after multi-assign lvalues");
|
||||
m.rhs = parseexpr(p);
|
||||
m.list = head;
|
||||
expect_tok(p, TK_SEMI, "expected ';' after multi-assign");
|
||||
expecttok(p, TK_SEMI, "expected ';' after multi-assign");
|
||||
return m;
|
||||
};
|
||||
let n: *node = newnode(p.a, N_EXPRSTMT, pf, pl, pc);
|
||||
n.lhs = e;
|
||||
expect_tok(p, TK_SEMI, "expected ';' after expression statement");
|
||||
expecttok(p, TK_SEMI, "expected ';' after expression statement");
|
||||
return n;
|
||||
};
|
||||
|
||||
@@ -784,7 +784,7 @@ fn parseuse(p: *parser) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
expect_tok(p, TK_SEMI, "expected ';' after use");
|
||||
expecttok(p, TK_SEMI, "expected ';' after use");
|
||||
return n;
|
||||
};
|
||||
|
||||
@@ -797,11 +797,11 @@ fn parsedef(p: *parser, exported: i32) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
expect_tok(p, TK_COLON, "expected ':' in def");
|
||||
expecttok(p, TK_COLON, "expected ':' in def");
|
||||
n.lhs = parsetype(p);
|
||||
expect_tok(p, TK_ASSIGN, "expected '=' in def");
|
||||
expecttok(p, TK_ASSIGN, "expected '=' in def");
|
||||
n.rhs = parseexpr(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after def");
|
||||
expecttok(p, TK_SEMI, "expected ';' after def");
|
||||
n.exported = exported;
|
||||
return n;
|
||||
};
|
||||
@@ -815,13 +815,13 @@ fn parselet(p: *parser, exported: i32) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
if (accept_tok(p, TK_COLON)) {
|
||||
if (accepttok(p, TK_COLON)) {
|
||||
n.lhs = parsetype(p);
|
||||
};
|
||||
if (accept_tok(p, TK_ASSIGN)) {
|
||||
if (accepttok(p, TK_ASSIGN)) {
|
||||
n.rhs = parseexpr(p);
|
||||
};
|
||||
expect_tok(p, TK_SEMI, "expected ';' after let");
|
||||
expecttok(p, TK_SEMI, "expected ';' after let");
|
||||
n.exported = exported;
|
||||
return n;
|
||||
};
|
||||
@@ -838,11 +838,11 @@ fn parseattrs(p: *parser) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
a.str = id;
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after attribute name");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after attribute name");
|
||||
let arghead: *node = nil;
|
||||
parsearglist(p, TK_RPAREN, &arghead);
|
||||
a.list = arghead;
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after attribute args");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after attribute args");
|
||||
if (head == nil) { head = a; tail = a; }
|
||||
else { tail.next = a; tail = a; };
|
||||
};
|
||||
@@ -863,11 +863,11 @@ fn parseparams(p: *parser) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
expect_tok(p, TK_COLON, "expected ':' in parameter");
|
||||
expecttok(p, TK_COLON, "expected ':' in parameter");
|
||||
n.lhs = parsetype(p);
|
||||
if (head == nil) { head = n; tail = n; }
|
||||
else { tail.next = n; tail = n; };
|
||||
if (!accept_tok(p, TK_COMMA)) { break; };
|
||||
if (!accepttok(p, TK_COMMA)) { break; };
|
||||
if (p.cur_kind == TK_RPAREN) { break; };
|
||||
};
|
||||
return head;
|
||||
@@ -882,20 +882,20 @@ fn parsefn(p: *parser, exported: i32, attrs: *node) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
expect_tok(p, TK_LPAREN, "expected '(' after fn name");
|
||||
expecttok(p, TK_LPAREN, "expected '(' after fn name");
|
||||
n.list = parseparams(p);
|
||||
expect_tok(p, TK_RPAREN, "expected ')' after params");
|
||||
expecttok(p, TK_RPAREN, "expected ')' after params");
|
||||
if (p.cur_kind != TK_ASSIGN) {
|
||||
if (p.cur_kind != TK_SEMI) {
|
||||
n.lhs = parsetype(p);
|
||||
};
|
||||
};
|
||||
if (accept_tok(p, TK_ASSIGN)) {
|
||||
if (accepttok(p, TK_ASSIGN)) {
|
||||
n.body = parseblock(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after fn body");
|
||||
expecttok(p, TK_SEMI, "expected ';' after fn body");
|
||||
} else {
|
||||
// Body-less fn: FFI declaration (`fn name(args) ret;`).
|
||||
expect_tok(p, TK_SEMI, "expected ';' after fn header");
|
||||
expecttok(p, TK_SEMI, "expected ';' after fn header");
|
||||
};
|
||||
n.exported = exported;
|
||||
n.attr = attrs;
|
||||
@@ -911,9 +911,9 @@ fn parsetypedecl(p: *parser, exported: i32) *node = {
|
||||
let id: str;
|
||||
expectident(p, &id);
|
||||
n.str = id;
|
||||
expect_tok(p, TK_ASSIGN, "expected '=' in type decl");
|
||||
expecttok(p, TK_ASSIGN, "expected '=' in type decl");
|
||||
n.lhs = parsetype(p);
|
||||
expect_tok(p, TK_SEMI, "expected ';' after type decl");
|
||||
expecttok(p, TK_SEMI, "expected ';' after type decl");
|
||||
n.exported = exported;
|
||||
return n;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user