Created
May 17, 2011 18:59
-
-
Save basicxman/977122 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env io | |
| # LispML (XML Builder) | |
| # Assignment from Seven Languages in Seven Weeks Chapter 2 | |
| Builder := Object clone | |
| Builder forward := method( | |
| tag := call message name | |
| temp := Map clone | |
| temp atPut(tag, list) | |
| call message arguments foreach(arg, content := self doMessage(arg); temp at(tag) append(content)) | |
| temp | |
| ) | |
| Lobby buildPrint := method(structure, currentDepth, | |
| if (currentDepth == nil, currentDepth = 0) | |
| start := "" | |
| for (i, 0, currentDepth - 1, start = start .. " ") | |
| if (structure type == "Map", | |
| structure foreach(key, value, | |
| writeln(start, "<", key, ">"); | |
| buildPrint(value, currentDepth + 1); | |
| writeln(start, "</", key, ">"); | |
| ) | |
| return | |
| ) | |
| if (structure type == "Sequence", | |
| writeln(start, structure); | |
| return | |
| ) | |
| if (structure type == "List", | |
| structure foreach(value, buildPrint(value, currentDepth + 1)) | |
| return | |
| ) | |
| ) | |
| derp := Builder ul(li("Io"), li("Lua"), li("Ruby"), ul(li("Derp"), li("Herp"), li("Jerp"))) | |
| buildPrint(derp) | |
| derp := Builder html( | |
| head( | |
| title("Test Page!") | |
| ), | |
| body( | |
| h1("Derp!"), | |
| p( | |
| i("Yay"), | |
| br(" "), | |
| b("Done.") | |
| ) | |
| ) | |
| ) | |
| buildPrint(derp) | |
| ------------ | |
| Andrew-Horsmans-iMac:Io basicxman$ io lispml_advanced.io | |
| <ul> | |
| <li> | |
| Io | |
| </li> | |
| <li> | |
| Lua | |
| </li> | |
| <li> | |
| Ruby | |
| </li> | |
| <ul> | |
| <li> | |
| Derp | |
| </li> | |
| <li> | |
| Herp | |
| </li> | |
| <li> | |
| Jerp | |
| </li> | |
| </ul> | |
| </ul> | |
| <html> | |
| <head> | |
| <title> | |
| Test Page! | |
| </title> | |
| </head> | |
| <body> | |
| <h1> | |
| Derp! | |
| </h1> | |
| <p> | |
| <i> | |
| Yay | |
| </i> | |
| <br> | |
| </br> | |
| <b> | |
| Done. | |
| </b> | |
| </p> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment