-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Decouple string start & end delimiters in parser logic Since both multiline and symbolic strings will end with `"%`, it will no longer be true that the start & end delimiters of a string must match. It will also no longer be the case that we can infer whether or not indentation must be stripped from the starting delimiter. This commit separates the opening and closing delimeter into two different types, and provides a more explicit API for working with them, which will be resilient to the addition of a new `StringStartDelimiter` in a later commit. * Desugar symbolic strings to arrays This commit implements the symbolic string syntax `s%"..."%`. These strings using the same parsing rules as multiline strings, but are then desugared to `Term::Array`s rather than `Term::StrChunks`. * `StringEndDelimiter::Multiline` -> `StringEndDelimiter::Special`
- Loading branch information
1 parent
0e90872
commit c30ad1f
Showing
5 changed files
with
202 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
let {check, ..} = import "lib/assert.ncl" in | ||
|
||
[ | ||
# Static symbolic string | ||
s%"hello, world"% == ["hello, world"], | ||
# Interpolating a string | ||
let s = "test" in | ||
s%"This is a %{s}"% == ["This is a ", "test"], | ||
# Interpolating an interpolated string | ||
let f = "f" in | ||
s%"abc %{"de%{f}"}"% == ["abc ", "def"], | ||
# Interpolating a number | ||
s%"num: %{100}"% == ["num: ", 100], | ||
# Interpolating a bool | ||
s%"bool: %{true}"% == ["bool: ", true], | ||
# Interpolating an array | ||
s%"array: %{[true, 1, "yes"]}"% == ["array: ", [true, 1, "yes"]], | ||
# Interpolating a record | ||
let r = { a = 1, b = false } in | ||
s%"record: %{r}"% == ["record: ", r], | ||
# Interpolating multiple values | ||
let str = "some string" in | ||
let num = 999.999 in | ||
let bool = false in | ||
let array = ["an", "array", 100] in | ||
let record = { a = 1, simple = "yes", record = true } in | ||
let actual = s%" | ||
1. %{str} | ||
2. %{num} | ||
3. %{bool} | ||
4. %{array} | ||
5. %{record}"% | ||
in | ||
let expected = [ | ||
"1. ", str, | ||
"\n2. ", num, | ||
"\n3. ", bool, | ||
"\n4. ", array, | ||
"\n5. ", record | ||
] | ||
in | ||
actual == expected, | ||
] | ||
|> check |