commit b81d9102ea1e930d5468cf4e8452ea0f4bb2f7e3
parent 4e765b74f1a425bd65903efffe6275a71a1aa098
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 19 Feb 2021 14:12:27 -0500
hare::lex: finish lex_name
Diffstat:
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
@@ -87,6 +87,14 @@ export fn lex(lex: *lexer) ((token, location) | io::EOF | error) = {
fn is_name(r: rune, num: bool) bool =
ascii::isalpha(r) || r == '_' || r == '@' || (num && ascii::isdigit(r));
+fn ncmp(a: const *void, b: const *void) int = {
+ let a = a: const *str, b = b: const *str;
+ return match (ascii::strcmp(*a, *b)) {
+ void => abort("non-ascii name"), // TODO: Bubble me up
+ i: int => i,
+ };
+};
+
fn lex_name(lex: *lexer, loc: location) ((token, location) | io::EOF | error) = {
let chars: []u8 = [];
match (next(lex)) {
diff --git a/hare/lex/token.ha b/hare/lex/token.ha
@@ -277,6 +277,7 @@ export type token = (btoken | label | name | literal);
export fn tokstr(tok: token) const str = {
return match (tok) {
b: btoken => bmap[b: int],
+ n: name => n: str,
* => abort(), // TODO
};
};