[This local archive copy mirrored from the canonical site: http://www.mds.rmit.edu.au/sim_2.1/ace-overview.html; links may not have complete integrity, so use the canonical document at this URL if possible.]
The Ace Scripting Language
|
||
Ace is a freely available scripting language which allows powerful manipulation of SGML and XML documents. |
Welcome to the home page for the Ace scripting language!
Ace was developed as a part of the Structured Information Manager (SIM), a commercial product currently available in Australia and the US. The Ace scripting language is used throughout SIM for specifying indexing rules in the SIM database server, for developing web applications in the SIM web server, and so on. A free version of the Ace scripting language has been released to the public allowing scripts to be run from the command line. As Ace is part of a commercial product, source code is not available, only precompiled executables. The highlights of Ace are:
Example code to extract all sections within chapters that have a title is: doc.all("CHAPTER").children("SECTION").(n: n.children("TITLE").exists()) A free download of Ace is available, as well as a mailing list. Some more sample code is also available. The Structured Information Manager is a product of the RMIT Multimedia Database Systems Group. Level 2, 723 Swanston St, Carlton 3053, AUSTRALIA. Phone: +61-3-9282-2400. Fax: +61-3-9282-2490. Email: enquiry@mds.rmit.edu.au. Web: http://www.mds.rmit.edu.au. |
Ace Code Samples
|
||
Ace is a fully functional programming language that can be used for a wide range of applications, with a particular focus on SGML and XML documents. |
This page contains a number of code fragments to help you get a better
idea of what Ace code looks like. Full documentation is available
on the download site.
FactorialThe following program implements a factorial function and demonstrates simple integer arithemtic and string processing.# # Return the factorial of 'n'. # function Integer n.factorial() => Integer begin if n < 1 then throw "n must be >0 for factorial (was " + n.toString() + ")"; end; integer r := 1; for Integer i := 1; i <= n; i++; do r := r * i; end; return r; end; # # Main program # begin StringBuffer s := new StringBuffer(); try s << "5 factorial is " << 5.factorial() << "\n"; s << "0 factorial is " << 0.factorial() << "\n"; catch String message s << "oops:" << message << "\n"; end; return s; end SGML NormalisationThe following program reads an SGML from the command line, parses the SGML document in stream mode, then outputs a normalised version of the document.import ConsoleAccess; begin if argv.size() <> 2 then cerr << "usage: " + argv[0] + " file.sgm\n"; exit(1); end; SgmlEntityManager entMgr := new SgmlEntityManager("file"); SgmlEventStream s := new SgmlEventStream(entMgr, argv[1], "SGML"); SgmlEvent event; String text := entMgr.entity(argv[1]).content(); while (event := s.nextEvent()).type() <> "end" do cout << event.toString(); end; cout << "\n"; return ""; end SGML Tree WalkingThe following example loads XML files and prints the title of all sections in chapters where the title contains 'XML', a form of smart grep.import ConsoleAccess; begin if argv.size() < 2 then cerr << "usage: " + argv[0] + " file.xml ...\n"; exit(1); end; SgmlEntityManager entMgr := new SgmlEntityManager("file"); argv.remove(0); foreach fileName in argv do String fileContents := readFile(fileName); SgmlEntity ent := new SgmlEntity(fileName, fileContents); SgmlDocument doc := new SgmlDocument(entMgr, ent, "XML"); foreach title in doc.root().all("CHAPTER").children("SECTION") .children("TITLE").toIndexString() do if title.matches("XML") then cout << fileName << ": " << title << "\n"; end; end; end; return ""; end The Structured Information Manager is a product of the RMIT Multimedia Database Systems Group. Level 2, 723 Swanston St, Carlton 3053, AUSTRALIA. Phone: +61-3-9282-2400. Fax: +61-3-9282-2490. Email: enquiry@mds.rmit.edu.au. Web: http://www.mds.rmit.edu.au. |