module lexer import arena fn test_syntax_abbreviation_tokens_keep_exact_spellings_positions_and_following_data() { source := "#'a #`b #,c #,@d" tokens := tokenize(source) or { panic(err) } kinds := [TokenKind.syntax_quote, .identifier, .syntax_quasiquote, .identifier, .syntax_unquote, .identifier, .syntax_unquote_splicing, .identifier, .eof] assert tokens.len == kinds.len for i, kind in kinds { assert tokens[i].kind == kind } assert tokens[0].lexeme == "#'" && tokens[0].start == 0 && tokens[0].end == 2 assert tokens[2].lexeme == '#`' && tokens[2].column == 5 assert tokens[4].lexeme == '#,' && tokens[4].column == 9 assert tokens[6].lexeme == '#,@' && tokens[6].column == 13 mut alt := new_alt_scanner("#'x #`(a,#,b,#,@c)") or { panic(err) } assert (alt.next() or { panic(err) }).span.kind == .syntax_quote assert (alt.next() or { panic(err) }).span.kind == .identifier assert (alt.next() or { panic(err) }).span.kind == .syntax_quasiquote } fn test_syntax_abbreviation_scanning_remains_allocation_free_and_span_sized() { source := "#'x #`(a #,b #,@c) ".repeat(10000) mut storage := arena.new(chunk_size: 4096) storage.push() before := storage.used() mut scanner := new_scanner(source) or { panic(err) } mut count := 0 for { token := scanner.next() or { panic(err) } if token.kind == .eof { break } count++ } assert count > 10000 assert storage.used() == before assert sizeof(TokenSpan) == 40 storage.pop() storage.free() } fn test_syntax_abbreviation_markers_stay_data_inside_strings_identifiers_and_comments() { tokens := tokenize('"#\' #` #, #,@" |#\'| #| #` #, #,@ |# #\'x') or { panic(err) } assert tokens.len == 5 assert tokens[0].kind == .string_literal && tokens[1].kind == .identifier assert tokens[2].kind == .syntax_quote && tokens[3].kind == .identifier assert tokens[4].kind == .eof }