-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for nested bracket strings in self-hosted parser.
- Loading branch information
Showing
6 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
self-hosted/spec/savi-lang-parse/05-parse-nested-bracket-strings.savi
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,16 @@ | ||
:actor Main | ||
:new | ||
<<<FOO>>> | ||
<<<FOO<<<BAR>>>BAZ>>> | ||
<<< | ||
FOO | ||
BAR | ||
BAZ | ||
>>> | ||
<<< | ||
FOO | ||
<<< | ||
BAR | ||
>>> | ||
BAZ | ||
>>> |
23 changes: 23 additions & 0 deletions
23
self-hosted/spec/savi-lang-parse/05-parse-nested-bracket-strings.savi.ast.yaml
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,23 @@ | ||
#1: | ||
declares: #2: | ||
0: #3: | ||
terms: #4: | ||
0: #5: | ||
name: "actor" | ||
1: #6: | ||
name: "Main" | ||
body: #7: | ||
1: #8: | ||
terms: #9: | ||
0: #10: | ||
name: "new" | ||
body: #11: | ||
terms: #12: | ||
0: #13: | ||
string: "FOO" | ||
1: #14: | ||
string: "FOO<<<BAR>>>BAZ" | ||
2: #15: | ||
string: "FOO\nBAR\nBAZ" | ||
3: #16: | ||
string: "FOO\n<<<\n BAR\n>>>\nBAZ" |
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,37 @@ | ||
:module _StringLiterals | ||
:fun process_bracket_string_indentation(string String) String | ||
// Look at the first few characters of the string to find the indentation. | ||
first_non_space_index USize = 0 | ||
saw_newline = False | ||
string.each_char_with_index_and_width -> (char, index, width | | ||
case char == ( | ||
| ' ' | | ||
| '\t' | | ||
| '\r' | | ||
if saw_newline ( | ||
first_non_space_index = index | ||
break string // TODO: no need for break value here | ||
) | ||
| '\n' | | ||
if saw_newline ( | ||
first_non_space_index = index | ||
break string // TODO: no need for break value here | ||
) | ||
saw_newline = True | ||
| | ||
first_non_space_index = index | ||
break string // TODO: no need for break value here | ||
) | ||
) | ||
|
||
// If the string has no indentation, or is only whitespace, return as-is. | ||
return string if (first_non_space_index == 0 || !saw_newline) | ||
|
||
// Remove the indentation and trim remaining whitespace before and after. | ||
initial_indentation = string.trim(0, first_non_space_index) | ||
content = string.clone.replace_all(initial_indentation, "\n") | ||
content.trim_in_place( | ||
content.leading_whitespace_index | ||
content.trailing_whitespace_index | ||
) | ||
--content |
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