hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 810193db9cbb6a84b757fc26aa526eac1c151b58
parent 025646da5faa323edd3ccd29abf786cc2664ac75
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 19 Feb 2021 16:11:48 -0500

hare::lex: expand keyword tests

Diffstat:
Mhare/lex/+test.ha | 15+++++++++++++++
Mhare/lex/lex.ha | 2+-
Mhare/lex/token.ha | 4++--
3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha @@ -184,6 +184,21 @@ fn lextest(in: str, expected: [](uint, uint, token)) void = { lextest(in, expected); }; +@test fn keywords() void = { + let keywords = bmap[..btoken::LAST_KEYWORD+1]; + for (let i = 0z; i < len(keywords); i += 1) { + let lexer = lexer_init(bufio::fixed( + strings::to_utf8(keywords[i])), "<test>"); + let tl = match (lex(&lexer)) { + tl: (token, location) => tl, + * => abort(), + }; + let tok = tl.0; + assert(tok is btoken); + assert(tok as btoken == i: btoken); + }; +}; + @test fn comments() void = { const in = "hello world // foo\nbar"; const expected: [_](uint, uint, token) = [ diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -197,7 +197,7 @@ fn lex_name( }; let n = strings::from_utf8(chars); - return match (sort::search(bmap[..btoken::NAMED_LAST+1], + return match (sort::search(bmap[..btoken::LAST_KEYWORD+1], size(str), &n, &ncmp)) { // TODO: Validate that names are ASCII null => (n: name: token, loc), diff --git a/hare/lex/token.ha b/hare/lex/token.ha @@ -64,7 +64,7 @@ export type btoken = enum { UNION, USE, VOID, - NAMED_LAST = VOID, + LAST_KEYWORD = VOID, // Operators ANDEQ, @@ -182,7 +182,7 @@ const bmap: [_]str = [ "&", "~", "|", - "case", + "=>", ":", ",", "/",