-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[special-vars] Implement OIL_VERSION.
ble.sh and neofetch both want to use it. Addresses issue #683. Unrelated: Start QSTR doc.
- Loading branch information
Andy Chu
committed
Apr 8, 2020
1 parent
03f0b2d
commit 8778a5c
Showing
10 changed files
with
148 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ readonly MARKDOWN_DOCS=( | |
oil-proc-func-block | ||
eggex | ||
unicode | ||
qstr | ||
|
||
# Internal stuff | ||
interpreter-state | ||
|
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
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,95 @@ | ||
--- | ||
in_progress: true | ||
--- | ||
|
||
QSTR Serialization Format | ||
========================= | ||
|
||
We want a single way to serialize and parse arbitrary byte strings (which may | ||
be encoded in UTF-8 or another encoding.) | ||
|
||
- It should be safe to print arbitrary strings to terminals. | ||
- Strings should fit on a line. | ||
|
||
TODO: copy content from this page: | ||
<https://github.com/oilshell/oil/wiki/CSTR-Proposal> | ||
|
||
<div id="toc"> | ||
</div> | ||
|
||
## Use Case: `set -x` format (`xtrace`) | ||
|
||
Unquoted: | ||
|
||
``` | ||
$ set -x | ||
$ echo a b | ||
+ echo a b | ||
``` | ||
|
||
We need single quotes `'1 2'` to make arguments with spaces unambiguous: | ||
|
||
``` | ||
$ set -x | ||
$ x='a b' | ||
$ echo "$x" c | ||
+ echo 'a b' c | ||
``` | ||
|
||
We need C-escaped strings `$'1\n2'` to make arguments with newlines fit on a | ||
line: | ||
|
||
``` | ||
$ set -x | ||
$ x=$'a\nb' | ||
$ echo "$x" c | ||
+ echo $'a\nb' 3 | ||
``` | ||
|
||
And to show unprintable characters safely on a terminal: | ||
|
||
``` | ||
$ set -x | ||
$ x=$'\e\001' | ||
$ echo "$x" | ||
echo $'\x1b\x01' | ||
``` | ||
|
||
## Design | ||
|
||
- The `$''` emitter should be compatible with CSTR. These all mean the same thing: | ||
|
||
``` | ||
$'\x01\n' # shell-compatible (but confusing) | ||
c'\x01\n' # explicit CSTR | ||
'\x01\n' # implicit CSTR, which is similar ro Python format | ||
``` | ||
|
||
## Display Special Characters | ||
|
||
### Three options For Displaying Unicode | ||
|
||
|
||
1. Don't decode UTF-8. Just show bytes like `'\xce\xbc'`. | ||
2. Decode UTF-8. This could be useful for showing at a glance if we have valid | ||
UTF-8 strings. | ||
a. Show code points like `'\u03bc'`. ASCII friendly, so better for weird | ||
debugging situations. | ||
b. Show them literally. Depends on the terminal. | ||
|
||
### Special Chars Emitted | ||
|
||
- `\r` `\n` `\t` `\0` (subset of C and shell; Rust has this) | ||
- Everything else is either `\xFF` or `\u03bc` | ||
|
||
## Links | ||
|
||
- <https://doc.rust-lang.org/reference/tokens.html#string-literals> - Rust is | ||
precise about it: | ||
- `\x7F` | ||
- `\u{03bc}` or `\u{0003bc}`. This is clearer than the bare format. And | ||
there are bugs in octal in bash -- is it 3 or 4 chars, etc.? | ||
- But bash's `$''` doesn't accept this. | ||
- `\t` `\r` `\n` | ||
- `\\` | ||
- `\0` |
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