-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add quine.wybe sample * Fix typo in json; add more details in sammples/README.md * Formatting; authorship * Add complex test with shorter quine * Better validation in README
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
Some small example Wybe programs. | ||
# Some small example Wybe programs. | ||
|
||
## brainfuck.wybe | ||
|
||
A [Brainfuck](https://esolangs.org/wiki/Brainfuck) parser and interpreter. | ||
|
||
## json.wybe | ||
|
||
A JSON document parser. | ||
|
||
## quine.wybe | ||
|
||
A [Quine](https://en.wikipedia.org/wiki/Quine_(computing)). | ||
|
||
To validate: | ||
```sh | ||
$ wybemk quine | ||
$ ./quine | diff ./quine.wybe - | ||
$ echo $? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## json.Wybe | ||
## json.wybe | ||
## Author: James Barnes | ||
# | ||
# A recursive-descent parser for JSON documents in Wybe. | ||
|
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,56 @@ | ||
## quine.wybe | ||
## Author: James Barnes | ||
# | ||
# A Quine | ||
?listing = [ | ||
"## quine.wybe", | ||
"## Author: James Barnes", | ||
"#", | ||
"# A Quine", | ||
"?listing = [", | ||
"]", | ||
"?n_lines = listing^length", | ||
"?preamble_lines = 5", | ||
"for _ in 0..preamble_lines; ?line in listing {", | ||
" !println line", | ||
"}", | ||
"for ?index in 0..n_lines; ?line in listing {", | ||
" for _ in 0..4 {", | ||
" !print ' '", | ||
" }", | ||
" ?quote = 34:char", | ||
" !print quote; !print line; !print quote", | ||
" if { index < n_lines - 1 ::", | ||
" !println ','", | ||
" | else ::", | ||
" !nl", | ||
" }", | ||
"}", | ||
"for ?i in preamble_lines..n_lines {", | ||
" if { ?line = listing[i] ::", | ||
" !println(line)", | ||
" }", | ||
"}" | ||
] | ||
?n_lines = listing^length | ||
?preamble_lines = 5 | ||
for _ in 0..preamble_lines; ?line in listing { | ||
!println line | ||
} | ||
for ?index in 0..n_lines; ?line in listing { | ||
for _ in 0..4 { | ||
!print ' ' | ||
} | ||
?quote = 34:char | ||
!print quote; !print line; !print quote | ||
if { index < n_lines - 1 :: | ||
!println ',' | ||
| else :: | ||
!nl | ||
} | ||
} | ||
for ?i in preamble_lines..n_lines { | ||
if { ?line = listing[i] :: | ||
!println(line) | ||
} | ||
} |
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,8 @@ | ||
---------------------------------------------------------------------- | ||
- program - output | ||
---------------------------------------------------------------------- | ||
["[","]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}}"]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}} | ||
["[","]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}}"]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}} | ||
---------------------------------------------------------------------- | ||
|
||
|
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,13 @@ | ||
from complex.utils import * | ||
|
||
WYBE_QUINE:str = r"""["[","]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}}"]=?L;?q=34:char;if{L=[?a,?b|_]::for _ in L{!print a;!print q};!print',';for _ in L{!print q;!print b}}""" | ||
|
||
@test_case | ||
def quine(ctx: Context) -> None: | ||
ctx.save_file("quine.wybe", WYBE_QUINE) | ||
_ = ctx.wybe_build_target("quine", False, False, check=True) | ||
_, output = ctx.execute_program("./quine", check=True) | ||
ctx.write_section("program - output", "\n".join([WYBE_QUINE, output])) | ||
|
||
assert WYBE_QUINE == output | ||
|