Skip to content

Commit 05a34b9

Browse files
manverulpil
authored andcommitted
fix another hash-in-string bug
1 parent fd74ff0 commit 05a34b9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v2.0.1 - 2026-01-13
4+
5+
- Fixed a bug where the '#' symbol in ''' strings would be treated like a comment
6+
37
## v2.0.0 - 2025-05-31
48

59
- Added [gleam_time](https://hexdocs.pm/gleam_time/index.html) as a dependency.

src/tom.gleam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ fn drop_comments(input: Tokens, acc: Tokens, in_string: Bool) -> Tokens {
709709
["\\", "\"", ..input] if in_string ->
710710
drop_comments(input, ["\"", "\\", ..acc], in_string)
711711
["\"", ..input] -> drop_comments(input, ["\"", ..acc], !in_string)
712+
["'", "'", "'", ..input] ->
713+
drop_comments(input, ["'", "'", "'", ..acc], !in_string)
712714
["#", ..input] if in_string -> drop_comments(input, ["#", ..acc], in_string)
713715
["#", ..input] if !in_string ->
714716
input

test/tom_test.gleam

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,25 @@ pub fn parse_multi_line_single_quote_string_too_many_quotes_test() {
508508
|> should.equal(Error(tom.Unexpected("''''", "'''")))
509509
}
510510

511+
pub fn parse_multi_line_literal_string_with_hash_test() {
512+
let expected =
513+
dict.from_list([
514+
#(
515+
"a",
516+
tom.String(
517+
"This string contains a #hash character\nand more text after it\n",
518+
),
519+
),
520+
])
521+
"a = '''
522+
This string contains a #hash character
523+
and more text after it
524+
'''
525+
"
526+
|> tom.parse
527+
|> should.equal(Ok(expected))
528+
}
529+
511530
pub fn parse_multi_line_string_escape_newline_test() {
512531
let expected =
513532
dict.from_list([

0 commit comments

Comments
 (0)