Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Enhance the XML program to add spaces to show the indentation structure
- Builder := Object clone
- Builder num := 0
- Builder forward := method(
- self num := self num+1
- indent(num, " ")
- writeln("<", call message name, ">")
- call message arguments foreach(
- arg,
- content := self doMessage(arg);
- if(content type == "Sequence",
- indent(num+1, " ")
- writeln(content)))
- indent(num, " ")
- self num := self num-1
- writeln("</", call message name, ">"))
- Builder indent := method(cnt, identifier,
- for(i, 1, cnt, 1, write(identifier))
- )
- # Create a list syntax that uses brackets
- list := List clone
- squareBrackets := method(
- call message arguments foreach(arg,
- call sender list append(arg)
- )
- )
- # Enhance the XML program to handle attribute
- num := 0
- 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) .. "\"")
- )
- forward := method(
- self num := self num+1
- indent(num, "**")
- argument := ""
- # this is not nice, but I don't find another way to avoid evaluation
- if (call argAt(0) asString exSlice(0, 13) == "curlyBrackets",
- key := call evalArgAt(0) keys at(0)
- argument := " " .. key .. "=" .. call evalArgAt(0) at (key)
- call message arguments remove(0)
- )
- writeln("<", call message name, argument, ">")
- call message arguments foreach(
- arg,
- content := self doMessage(arg);
- if(content type == "Sequence",
- indent(num+1, "**")
- writeln(content)))
- indent(num, "**")
- self num := self num-1
- writeln("</", call message name, ">"))
- indent := method(cnt, identifier,
- for(i, 1, cnt, 1, write(identifier))
- )
- # Sample
- ul({"o":"p"},li("Io"),li("JS"),li(a(href({"url":"google.de"},"Google"))))
- # Result
- **<ul o="p">
- ****<li>
- ******Io
- ****</li>
- ****<li>
- ******JS
- ****</li>
- ****<li>
- ******<a>
- ********<href url="google.de">
- **********Google
- ********</href>
- ******</a>
- ****</li>
- **</ul>
- ==> nil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement