commit d4d01f7eeaf60f1631db382cdfc779de245148ed
parent eb2dff3e40d3290a52dee0c6bf9599c80e420464
Author: Sebastian <sebastian@sebsite.pw>
Date: Fri, 8 Sep 2023 00:22:39 -0400
hare::parse: measure ident length correctly
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/hare/parse/+test/ident_test.ha b/hare/parse/+test/ident_test.ha
@@ -39,4 +39,16 @@ fn ident_test(in: str, expected: ast::ident, extra: ltok...) void = {
ident_test("foo::bar", ["foo", "bar"]);
ident_test("foo::bar::baz", ["foo", "bar", "baz"]);
ident_test("foo::bar;", ["foo", "bar"], ltok::SEMICOLON);
+
+ // identifier exceeds maximum length
+ let buf: [ast::IDENT_MAX / 2 + ast::IDENT_MAX + 3]u8 = [0...];
+ let buf = buf[..0];
+ static append(buf, 'a');
+ for (let i = 0z; i < ast::IDENT_MAX / 2; i += 1) {
+ static append(buf, [':', ':', 'a']...);
+ };
+ ident_test(strings::fromutf8(buf)!,
+ ["a"...]: [ast::IDENT_MAX / 2 + 1]str);
+ static append(buf, [':', ':', 'a']...);
+ ident_test(strings::fromutf8(buf)!, []);
};
diff --git a/hare/parse/ident.ha b/hare/parse/ident.ha
@@ -11,8 +11,8 @@ use strings;
fn ident_trailing(lexer: *lex::lexer) ((ast::ident, bool) | error) = {
let ident: []str = [];
let trailing = false;
- let z = 0z;
append(ident, want(lexer, ltok::NAME)?.1 as str);
+ let z = len(ident[0]);
for (true) {
match (try(lexer, ltok::DOUBLE_COLON)?) {
case void => break;