hare

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

commit 7160f3adf59f2c06329de4fdc80dff04042303f7
parent f90dd840ff569382052bbc5899a2256870b30903
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 19 Feb 2021 14:25:37 -0500

hare::lex: add lexname test

Diffstat:
Mhare/lex/+test.ha | 19++++++++++++++++++-
Mhare/lex/lex.ha | 2+-
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha @@ -40,7 +40,12 @@ fn lextest(in: str, expected: [](uint, uint, token)) void = { }; let tok = tl.0, loc = tl.1; match (tok) { - b: btoken => if (etok as btoken != b) { + b: btoken => if (!(etok is btoken) || etok as btoken != b) { + fmt::errorln("bad token at {}: got {}, wanted {}", + i, tokstr(tok), tokstr(etok)); + abort(); + }, + n: name => if (!(etok is name) || etok as name != n) { fmt::errorln("bad token at {}: got {}, wanted {}", i, tokstr(tok), tokstr(etok)); abort(); @@ -121,3 +126,15 @@ fn lextest(in: str, expected: [](uint, uint, token)) void = { ]; lextest(in, expected); }; + +@test fn lexname() void = { + const in = "hello world return void foobar"; + const expected: [_](uint, uint, token) = [ + (1, 1, "hello": name), + (1, 7, "world": name), + (1, 13, btoken::RETURN), + (1, 20, btoken::VOID), + (1, 25, "foobar": name), + ]; + lextest(in, expected); +}; diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -119,7 +119,7 @@ fn lex_name(lex: *lexer, loc: location) ((token, location) | io::EOF | error) = }; let n = strings::from_utf8(chars); - return match (sort::search(bmap[..btoken::NAMED_LAST], + return match (sort::search(bmap[..btoken::NAMED_LAST+1], size(str), &n, &ncmp)) { // TODO: Validate that names are ASCII null => (n: name: token, loc),