Created
October 12, 2011 07:34
-
-
Save japaz/1280539 to your computer and use it in GitHub Desktop.
7L7W Io - Day 3
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
Builder := Object clone | |
Builder addIndent := method( | |
for(i, 1, indent*2, " " print) | |
) | |
Builder indent := 0 | |
Builder forward := method( | |
self addIndent | |
writeln("<", call message name, ">") | |
indent = indent +1 | |
call message arguments foreach( | |
arg, | |
content := self doMessage(arg); | |
if(content type == "Sequence", self addIndent; writeln(content))) | |
indent = indent -1 | |
self addIndent | |
writeln("</", call message name, ">")) | |
Builder ul( | |
li("Io"), | |
li("Lua"), | |
li(ul( | |
li("Java"), | |
li("C++"))), | |
li("JavaScript")) |
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
OperatorTable addAssignOperator(":" , "atPutNumber" ) | |
curlyBrackets := method( | |
r := Map clone | |
call message arguments foreach(arg, | |
r doMessage(arg) | |
) | |
r | |
) | |
Map atPutNumber := method( | |
self atPut( | |
call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\"" ), | |
call evalArgAt(1)) | |
) | |
Builder := Object clone | |
Builder addIndent := method( | |
for(i, 1, indent*2, " " print) | |
) | |
Builder indent := 0 | |
Builder forward := method( | |
addIndent | |
write("<", call message name) | |
firstMessage := call message arguments first | |
if( firstMessage != nil, | |
if(firstMessage name == "curlyBrackets", | |
attrs := doMessage(firstMessage) | |
if(attrs isKindOf(Map), attrs foreach(k,v,write(" ",k,"=","\"",v,"\""))) | |
) | |
) | |
writeln(">") | |
indent = indent +1 | |
call message arguments foreach( | |
arg, | |
content := self doMessage(arg); | |
if(content type == "Sequence", addIndent; writeln(content))) | |
indent = indent -1 | |
addIndent | |
writeln("</", call message name, ">")) | |
doString("Builder ul( | |
li(\"Io\"), | |
li(\"Lua\"), | |
li(ul( | |
li(\"Java\"), | |
li(\"C++\"))), | |
li(\"JavaScript\"), | |
book({\"author\": \"Tate\"}, \"Hi\"))") | |
// str := "Builder ul(li({\"class\":\"prototyped\"},\"Io\"), li(\"Lua\"), li(\"Javascript\") )" | |
// doString(str) |
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
squareBrackets := method( | |
l := List clone | |
call message arguments foreach(arg, | |
l append(arg) | |
) | |
l | |
) | |
["1", "2", "3"] print | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment