-
Notifications
You must be signed in to change notification settings - Fork 0
Support multiple space-separated values in display statements
#636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa59993
fix(parser): let `display` show multiple space-separated values
claude 498a2c3
fix(parser): fold keyword-led display values (call/count/current)
claude ed6d419
fix(parser): fold display values right-associatively, matching `with`
github-actions[bot] 5ec4e0c
style: fix cargo fmt formatting for display fold keyword tests
github-actions[bot] fef9fb7
fix(tests): green the display fold tests; apply review nits
claude e95b0a2
fix(parser): centralize display fold classification; guard more state…
github-actions[bot] 879c858
fix(parser): green CI formatting, escape Windows paths, enforce fold …
github-actions[bot] d19567d
perf(parser): compile display-fold coupling check out of release builds
claude 18066a8
docs(test): fix misleading `display a b c` example in multi-value tes…
claude 398e486
Merge branch 'main' into claude/display-concatenation-bug-4puwvh
logbie 403f2c3
docs: don't claim `with` and space-separated display forms can be mix…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,76 @@ | ||
| // Multi-value `display`: a display can list several space-separated values. | ||
| // Quoted text is shown as-is; each other item (a variable, a number, an action | ||
| // call, or an expression) is evaluated first. The values are joined exactly | ||
| // like `with` — see the bottom of this file for where that "space-separated" | ||
| // framing breaks down (bare multi-word identifiers, indexing, and arithmetic | ||
| // all claim the space before a value-form fold ever gets a chance to run). | ||
|
|
||
| store user age as 28 | ||
| display "user age is " user age // user age is 28 | ||
|
|
||
| change user age to 9 | ||
| display "user age is " user age // user age is 9 | ||
|
|
||
| // Equivalent, written with `with`: | ||
| display "user age is " with user age // user age is 9 | ||
|
|
||
| // More than two values, mixing text, variables and an expression: | ||
| store name as "Alice" | ||
| display name " is " user age " years old" // Alice is 9 years old | ||
| display "in ten years: " user age plus 10 // in ten years: 19 | ||
|
|
||
| // A single value still behaves exactly as before: | ||
| display user age // 9 | ||
|
|
||
| // Direct index access is unchanged: `list index` is one value, not two. | ||
| create list scores: | ||
| add 100 | ||
| add 200 | ||
| add 300 | ||
| end list | ||
| display "first score: " scores 0 // first score: 100 | ||
|
|
||
| // Keyword-led values fold too. A `call` to a user-defined action: | ||
| define action called doubled with parameters n: | ||
| give back n times 2 | ||
| end action | ||
| display "doubled: " call doubled with 21 // doubled: 42 | ||
|
|
||
| // The count-loop variable `count` as a trailing value: | ||
| count from 1 to 3: | ||
| display "count is " count // count is 1 / 2 / 3 | ||
| end count | ||
|
|
||
| // The following condition from the original report now sees the right value: | ||
| check if user age is greater than 18: | ||
| display "Access granted" | ||
| otherwise: | ||
| display "Must be 18 or older" | ||
| end check | ||
|
|
||
| // Values are folded right-associatively, exactly matching `with`'s evaluation | ||
| // order — not just its final text. Popping "after" off a list changes what | ||
| // the list looks like when it gets stringified; both forms below stringify | ||
| // the list *after* the pop runs, so both print "[before]after": | ||
| create list left_items: | ||
| add "before" | ||
| add "after" | ||
| end list | ||
| display left_items "" pop of left_items // [before]after | ||
|
|
||
| create list right_items: | ||
| add "before" | ||
| add "after" | ||
| end list | ||
| display right_items with "" with pop of right_items // [before]after | ||
|
|
||
| // A few more keyword-led values that now fold safely (see is_value_start in | ||
| // src/parser/helpers.rs for the full list and why each is unambiguous): | ||
| store is_admin as no | ||
| display "is admin: " not is_admin // is admin: yes | ||
| display "exists: " file exists at "does-not-exist.txt" // exists: no | ||
|
|
||
| // A run of plain words with nothing between them is ONE multi-word variable, | ||
| // not several values — this looks up a variable literally named "a b c", | ||
| // the same as it would anywhere else in WFL: | ||
| // display a b c ← NOT three values; would need `a with b with c` |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
TestPrograms/docs_examples/basic_syntax/display_multiple_01.wfl
This file contains hidden or 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,13 @@ | ||
| // Display several values at once (Docs/02-getting-started/hello-world.md). | ||
| // Quoted text is shown as-is; a variable or expression is evaluated first. | ||
| // The space-separated form is shorthand for joining values with `with`. | ||
|
|
||
| store name as "Alice" | ||
| display "Hello, " name "!" // Hello, Alice! | ||
|
|
||
| // Exactly the same result, written with `with`: | ||
| display "Hello, " with name with "!" // Hello, Alice! | ||
|
|
||
| // Spaces come from the quotes, not from the join: | ||
| store age as 25 | ||
| display "I am " age " years old" // I am 25 years old |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.