replace leading _ for private symbols with keyword hide

This commit is contained in:
2026-07-14 20:19:01 +02:00
parent 5157cf3bcc
commit 267947e79d
31 changed files with 125220 additions and 122709 deletions
+19 -19
View File
@@ -20,17 +20,17 @@ Token :: struct {
kind Kind
}
_is_alpha func(value u8) bool {
hide is_alpha func(value u8) bool {
return value == '_' or
value >= 'a' and value <= 'z' or
value >= 'A' and value <= 'Z'
}
_is_digit func(value u8) bool {
hide is_digit func(value u8) bool {
return value >= '0' and value <= '9'
}
_word_kind func(word []u8) Kind {
hide word_kind func(word []u8) Kind {
# ponytail: enough keywords for the demo; add the full language set when a parser needs it.
if mem.eql(word, "func") or mem.eql(word, "void") {
return .keyword
@@ -38,7 +38,7 @@ _word_kind func(word []u8) Kind {
return .identifier
}
_append func(tokens @mut std.ArrayList(Token), kind Kind, start, end usize) void ! mem.AllocError {
hide append_token func(tokens @mut std.ArrayList(Token), kind Kind, start, end usize) void ! mem.AllocError {
try arraylist.append(tokens, Token {
start = start,
length = end - start,
@@ -54,19 +54,19 @@ lex func(source []u8, tokens @mut std.ArrayList(Token)) void ! mem.AllocError {
if value == ' ' or value == '\t' or value == '\r' {
cursor += 1
} else if value == '\n' {
try _append(tokens, .newline, cursor, cursor + 1)
try append_token(tokens, .newline, cursor, cursor + 1)
cursor += 1
} else if value == '#' {
while cursor < source.len and source[cursor] != '\n' : cursor += 1 {}
} else if _is_alpha(value) {
} else if is_alpha(value) {
start usize :: cursor
cursor += 1
while cursor < source.len and (_is_alpha(source[cursor]) or _is_digit(source[cursor])) : cursor += 1 {}
try _append(tokens, _word_kind(source[start..cursor]), start, cursor)
} else if _is_digit(value) {
while cursor < source.len and (is_alpha(source[cursor]) or is_digit(source[cursor])) : cursor += 1 {}
try append_token(tokens, word_kind(source[start..cursor]), start, cursor)
} else if is_digit(value) {
start usize :: cursor
while cursor < source.len and _is_digit(source[cursor]) : cursor += 1 {}
try _append(tokens, .integer, start, cursor)
while cursor < source.len and is_digit(source[cursor]) : cursor += 1 {}
try append_token(tokens, .integer, start, cursor)
} else if value == '"' {
start usize :: cursor
cursor += 1
@@ -78,9 +78,9 @@ lex func(source []u8, tokens @mut std.ArrayList(Token)) void ! mem.AllocError {
}
if cursor < source.len and source[cursor] == '"' {
cursor += 1
try _append(tokens, .string, start, cursor)
try append_token(tokens, .string, start, cursor)
} else {
try _append(tokens, .invalid, start, cursor)
try append_token(tokens, .invalid, start, cursor)
}
} else {
start usize :: cursor
@@ -88,14 +88,14 @@ lex func(source []u8, tokens @mut std.ArrayList(Token)) void ! mem.AllocError {
if value == ':' and cursor < source.len and source[cursor] == ':' {
cursor += 1
}
try _append(tokens, .punctuation, start, cursor)
try append_token(tokens, .punctuation, start, cursor)
}
}
try _append(tokens, .eof, cursor, cursor)
try append_token(tokens, .eof, cursor, cursor)
return
}
_kind_name func(kind Kind) *c_char {
hide kind_name func(kind Kind) *c_char {
return match kind {
.invalid: "invalid"
.eof: "eof"
@@ -108,8 +108,8 @@ _kind_name func(kind Kind) *c_char {
}
}
_print_token func(source []u8, token Token) void {
_ = c.printf("%-11s", _kind_name(token.kind))
hide print_token func(source []u8, token Token) void {
_ = c.printf("%-11s", kind_name(token.kind))
if token.length != 0 {
_ = c.printf(" `")
i usize = 0
@@ -149,7 +149,7 @@ main func() i32 {
}
for tokens.items |token| {
_print_token(source, token)
print_token(source, token)
}
return 0
}