-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from michaeljones/for-as
Support `as` syntax in `for` loops to associate type with item
- Loading branch information
Showing
11 changed files
with
232 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: src/main.rs | ||
assertion_line: 1115 | ||
expression: "Hello,{% for item as Item in list %} to {{ item }} and {% endfor %} everyone else" | ||
|
||
--- | ||
[ | ||
Text( | ||
"Hello,", | ||
), | ||
For( | ||
"item", | ||
Some( | ||
"Item", | ||
), | ||
"list", | ||
[ | ||
Text( | ||
" to ", | ||
), | ||
Identifier( | ||
"item", | ||
), | ||
Text( | ||
" and ", | ||
), | ||
], | ||
), | ||
Text( | ||
" everyone else", | ||
), | ||
] |
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,30 @@ | ||
--- | ||
source: src/main.rs | ||
assertion_line: 1186 | ||
expression: "Hello,{% for item as Item in list %} to {{ item }} and {% endfor %} everyone else" | ||
|
||
--- | ||
import gleam/string_builder.{StringBuilder} | ||
import gleam/list | ||
|
||
|
||
|
||
pub fn render_builder(list list) -> StringBuilder { | ||
let builder = string_builder.from_string("") | ||
let builder = string_builder.append(builder, "Hello,") | ||
let builder = list.fold(list, builder, fn(builder, item: Item) { | ||
let builder = string_builder.append(builder, " to ") | ||
let builder = string_builder.append(builder, item) | ||
let builder = string_builder.append(builder, " and ") | ||
|
||
builder | ||
}) | ||
let builder = string_builder.append(builder, " everyone else") | ||
|
||
builder | ||
} | ||
|
||
pub fn render(list list) -> String { | ||
string_builder.to_string(render_builder(list: list)) | ||
} | ||
|
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,78 @@ | ||
--- | ||
source: src/main.rs | ||
assertion_line: 1018 | ||
expression: "Hello {% for item as Item in list %}{{ item }}{% endfor %}" | ||
|
||
--- | ||
[ | ||
( | ||
Text( | ||
"Hello ", | ||
), | ||
0..6, | ||
), | ||
( | ||
OpenStmt, | ||
6..7, | ||
), | ||
( | ||
For, | ||
9..12, | ||
), | ||
( | ||
Identifier( | ||
"item", | ||
), | ||
13..17, | ||
), | ||
( | ||
As, | ||
18..20, | ||
), | ||
( | ||
Identifier( | ||
"Item", | ||
), | ||
21..25, | ||
), | ||
( | ||
In, | ||
26..28, | ||
), | ||
( | ||
Identifier( | ||
"list", | ||
), | ||
29..33, | ||
), | ||
( | ||
CloseStmt, | ||
34..35, | ||
), | ||
( | ||
OpenValue, | ||
36..37, | ||
), | ||
( | ||
Identifier( | ||
"item", | ||
), | ||
39..43, | ||
), | ||
( | ||
CloseValue, | ||
44..45, | ||
), | ||
( | ||
OpenStmt, | ||
46..47, | ||
), | ||
( | ||
EndFor, | ||
49..55, | ||
), | ||
( | ||
CloseStmt, | ||
56..57, | ||
), | ||
] |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
pub type User { | ||
User(is_admin: Bool) | ||
} | ||
|
||
pub type NamedUser { | ||
NamedUser(name: String) | ||
} |
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,3 @@ | ||
{> import my_user.{NamedUser} | ||
{> with users as List(NamedUser) | ||
Hello,{% for user as NamedUser in users %} to {{ user.name }} and{% endfor %} everyone else |
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