-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f703122
Showing
4 changed files
with
93 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.dub | ||
docs.json | ||
__dummy.html | ||
docs/ | ||
/scheme-d | ||
scheme-d.so | ||
scheme-d.dylib | ||
scheme-d.dll | ||
scheme-d.a | ||
scheme-d.lib | ||
scheme-d-test-* | ||
*.exe | ||
*.o | ||
*.obj | ||
*.lst |
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 @@ | ||
{ | ||
"authors": [ | ||
"karita" | ||
], | ||
"copyright": "Copyright © 2019, karita", | ||
"dependencies": { | ||
"pegged": "~>0.4.4", | ||
"sumtype": "~>0.9.4" | ||
}, | ||
"description": "Write yourself a Scheme in 48 Hours in D", | ||
"license": "BSL-1.0", | ||
"name": "scheme-d" | ||
} |
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,7 @@ | ||
{ | ||
"fileVersion": 1, | ||
"versions": { | ||
"pegged": "0.4.4", | ||
"sumtype": "0.9.4" | ||
} | ||
} |
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,58 @@ | ||
import std.stdio; | ||
import std.typecons; | ||
|
||
import sumtype; | ||
import pegged.grammar; | ||
|
||
|
||
mixin(grammar(` | ||
SchemeParser: | ||
Body < SExpr* / Comment | ||
Comment <: ';' (!endOfLine .)* endOfLine | ||
SExpr < :'(' (Value / Comment)* :')' | ||
Value < Number / List / Atom / String / True / False / SExpr | ||
List < quote SExpr | ||
Atom <~ AtomChar (AtomChar / Digit)* | ||
AtomChar <- [a-zA-Z_] / '+' / '-' / '*' / '/' | ||
/ quote / ':' / '!' / '$' / '%' / '&' / '=' / '~' / '^' / ':' | ||
String <~ :doublequote Char* :doublequote | ||
Char <~ backslash doublequote | ||
/ backslash backslash | ||
/ backslash [bfnrt] | ||
/ (!doublequote .) | ||
Number <~ '-'? ('0' / [1-9] Digit* ('.' Digit*)?) | ||
Digit <- [0-9] | ||
True <- "#t" | ||
False <- "#f" | ||
`)); | ||
|
||
struct Atom { string name; } | ||
struct List { Object[] data; } | ||
struct DottedList | ||
{ | ||
Object[] data; | ||
Object tail; | ||
} | ||
|
||
alias Object = SumType!( | ||
Atom, | ||
List, | ||
long, | ||
string, | ||
bool); | ||
|
||
void main(string[] args) | ||
{ | ||
enum input1 = ` | ||
(f0 #t #f '(1 2 3) '()) | ||
(f1 "string" | ||
;; comment | ||
(+ 20 -30)) | ||
`; | ||
writeln(SchemeParser(input1)); | ||
// writeln("Hello, ", args[1]); | ||
} |