Skip to content

Commit 9f5cdc1

Browse files
committed
fix: update multiline string handling in tokenizer and adjust test fixtures
1 parent 59e675a commit 9f5cdc1

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

internal/lox/api/scanner_api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func ScanTokens(source string) ([]string, []string, int, error) {
2626
} else if reflect.TypeOf(literal).Kind() == reflect.Float64 {
2727
literal = lox.FormatFloat(literal.(float64))
2828
}
29-
tokenLines = append(tokenLines, fmt.Sprintf("%s %s %s", lox.GetTokenName(token.Type), token.Lexeme, literal))
29+
30+
tokenLine := fmt.Sprintf("%s %s %s", lox.GetTokenName(token.Type), token.Lexeme, literal)
31+
// Handle potential multiline strings
32+
tokenLines = append(tokenLines, strings.Split(tokenLine, "\n")...)
3033
}
3134

3235
exitCode := 0

internal/stage12.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func testStrings(stageHarness *test_case_harness.TestCaseHarness) error {
1616
logger := stageHarness.Logger
1717

1818
string1 := random.RandomElementFromArray(QUOTED_STRINGS) + " " + "\"unterminated"
19-
string2 := `"foo bar 123 // hello world!"`
19+
string2 := `"foo bar // First line in a multiline string` + LF + `123 // This is the second line"`
2020
shuffledString2 := "(" + strings.Join(random.RandomElementsFromArray(QUOTED_STRINGS, 2), "+") + `) != "other_string"`
2121

2222
tokenizeTestCases := testcases.MultiTestCase{

internal/test_helpers/fixtures/pass_scanning

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,14 @@ Debug = true
296296
[stage-12] [test-2] ✓ Received exit code 65.
297297
[stage-12] [test-3] Running test case: 3
298298
[stage-12] [test-3] Writing contents to ./test.lox:
299-
[stage-12] [test-3.lox] "foo <|TAB|>bar 123 // hello world!"
299+
[stage-12] [test-3.lox] "foo <|TAB|>bar // First line in a multiline string
300+
[stage-12] [test-3.lox] 123 // This is the second line"
300301
[stage-12] [test-3] $ ./your_program.sh tokenize test.lox
301-
[your_program] STRING "foo bar 123 // hello world!" foo bar 123 // hello world!
302+
[your_program] STRING "foo bar // First line in a multiline string
303+
[your_program] 123 // This is the second line" foo bar // First line in a multiline string
304+
[your_program] 123 // This is the second line
302305
[your_program] EOF null
303-
[stage-12] [test-3] ✓ 2 line(s) match on stdout
306+
[stage-12] [test-3] ✓ 4 line(s) match on stdout
304307
[stage-12] [test-3] ✓ Received exit code 0.
305308
[stage-12] [test-4] Running test case: 4
306309
[stage-12] [test-4] Writing contents to ./test.lox:

0 commit comments

Comments
 (0)