Created
November 23, 2011 04:12
-
-
Save jomontanari/1387869 to your computer and use it in GitHub Desktop.
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 indent := 0 | |
Builder writeIndent := method(for(i, 1, indent, " " print)) | |
Builder forward := method( | |
self writeIndent | |
writeln("<", call message name, ">") | |
indent = indent +1 | |
call message arguments foreach( | |
arg, | |
content := self doMessage(arg); | |
if (content type == "Sequence", for(i, 1, indent, " " print; writeln(content)) | |
) | |
indent = indent -1 | |
self writeIndent | |
writeln("</", call message name, ">") | |
) | |
Builder body( | |
ul( | |
li("Io"), | |
li("Lua"), | |
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
squareBrackets := method( | |
r := List clone | |
call message arguments foreach(arg, | |
r append(arg) | |
) | |
r | |
) | |
my_list := doString("[2, 4, 6]") | |
my_list println |
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(":", "atPutAttribute") | |
curlyBrackets := method( | |
r := Map clone | |
call message arguments foreach(arg, | |
r doString(arg asString) | |
) | |
r | |
) | |
Map atPutAttribute := method( | |
self atPut( | |
call evalArgAt(0), | |
call evalArgAt(1) | |
) | |
) | |
Xml_Element := Object clone | |
Xml_Element write_xml := method( | |
write("<", name) | |
attributes foreach(key, val, write_attribute(key, val)) | |
writeln(">") | |
contents foreach(c, writeln(c)) | |
children foreach(write_xml) | |
writeln("</", name, ">") | |
) | |
Xml_Element write_attribute := method(key, val, write(" \"", key, "\"=\"", val, "\"")) | |
Builder := Object clone | |
Builder writeIndent := method(for(i, 1, indent, " " print)) | |
Builder xml_elements := List clone | |
Builder forward := method( | |
xml_element := Xml_Element clone | |
xml_element name := call message name | |
xml_element attributes := Map clone | |
xml_element contents := List clone | |
xml_element children := List clone | |
xml_elements append(xml_element) | |
call message arguments foreach( | |
arg, | |
content := self doMessage(arg); | |
if (content type == "Map", xml_element attributes mergeInPlace(content)) | |
if (content type == "Sequence", xml_element contents append(content)) | |
if (content type != "Map" and content type != "Sequence", xml_element children append(content)) | |
) | |
if (xml_elements first == xml_element, xml_element write_xml) | |
xml_element | |
) | |
Builder xml( | |
book({ author : "Tate", Title : "Something" }), | |
book("A great read") | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jo,
2-list-brackets - will not work for [1,2,3,[4,5],6,7]
Srikanth