Candle (programming language)
Encyclopedia
Candle is a high-level general-purpose scripting language for both desktop and Internet applications. It unifies the core features of many XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 related technologies like XQuery
XQuery
- Features :XQuery provides the means to extract and manipulate data from XML documents or any data source that can be viewed as XML, such as relational databases or office documents....

, XSLT
XSLT
XSLT is a declarative, XML-based language used for the transformation of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one. The new document may be serialized by the processor in standard XML syntax or in another format,...

, RELAX NG
RELAX NG
In computing, RELAX NG is a schema language for XML, based on Murata Makoto's RELAX and James Clark's TREX. A RELAX NG schema specifies a pattern for the structure and content of an XML document...

. Its first public beta release was on 12 Oct 2005. And the planned formal release is in Jan 2012.

Candle Markup

Candle Markup is a subset of the Candle language that is used as a document format for static data. The syntax of Candle Markup is designed based on XML. And it also supports an object notation similar to JavaFX
JavaFX
JavaFX is a software platform for creating and delivering rich Internet applications that can run across a wide variety of connected devices....

 object notation. Below is an example of an object in 3 notations:
Candle Element Notation Candle Object Notation Similar JavaFX Literal Object

<Customer
firstName = "John"
lastName = "Doe"
phoneNum = "9555-0101"
address = <Address
street = "1 Main Street"
city = "Santa Clara"
state = "CA"
zip = "95050" />
>
"a text node"
</Customer>



Customer {
firstName = "John"
lastName = "Doe"
phoneNum = "9555-0101"
address = Address {
street = "1 Main Street"
city = "Santa Clara"
state = "CA"
zip = "95050"
}
"a text node"
}


Customer {
firstName: "John";
lastName: "Doe";
phoneNum: "9555-0101";
address: Address {
street: "1 Main Street";
city: "Santa Clara";
state: "CA";
zip: "95050";
}
/* text node not supported*/
}



The major advantages of Candle over XML are:
  • whitespace non-ambiguity: in XML, the whitespaces between the elements can be ambiguous as whether they are text nodes or just pure formatting whitespaces that can be ignored. Candle requires text nodes to be explicitly quoted, thus cleanly solves the problem.
  • cleaner namespace syntax: Candle supports a hierarchical namespace similar to Java. A fully expanded Qname in Candle looks like ns:domain:foo:bar.
  • strongly typed literal values: Candle uses unique syntax to denote the type of a literal value. Thus Candle is always strongly typed, whereas XML is only weakly typed without schema.
  • complex attribute content: attributes in Candle can accept complex content like an element.

Candle Script

Some of the distinctive features of Candle are:
  • Candle unifies XML markup data model with OOP object data model. In Candle, an attribute can have complex content like element. And an object can have child nodes like an element.
  • Candle unifies XQuery and XSLT as one coherent query language for hierarchical data processing.
  • Candle defines a pattern language which cleanly unifies several pattern-related DSLs (including RegEx, RELAX NG
    RELAX NG
    In computing, RELAX NG is a schema language for XML, based on Murata Makoto's RELAX and James Clark's TREX. A RELAX NG schema specifies a pattern for the structure and content of an XML document...

    , EBNF, XQuery Sequence Type). It can easily match on sequence of items, nodes and characters.
  • Candle's action model is based on a mechanism called separation-of-side-effects, which is conceptually similar to command-query separation
    Command-query separation
    Command-query separation is a principle of imperative computer programming. It was devised by Bertrand Meyer as part of his pioneering work on the Eiffel programming language....

    . In Candle, routines are divided into functions and methods. Functions are routines without side-effects and methods are routines with side-effects. The rule of separation-of-side-effects is that methods can call functions, but not vice versa. In this way, pure functional islands are well-preserved in the sea of procedural program.

Sample code

Here's an example of Candle script generating the lyrics of the song '99 Bottles of Beer':

<?csp1.0?>
function nil:bottles($n as integer) {
if ($n

1) { "1 bottle" }
else if ($n

0) { "no more bottles" }
else { {$n + " bottles"} }
}

template <song> {
<html>
<body>
<h1>"Lyrics of the song " {@title?string}</h1>
apply;
</body>
</html>
}

template <verse> {
<p> apply; </p>
}

template <line> {
apply; <br/>
}

function main {
apply to
<song title="99 Bottles of Beer">
for $b in reverse(0 to 99) {
<verse>
<line>{replace(nil:bottles($b), "n", "N")} " of beer on the wall, " nil:bottles($b); " of beer."</line>
if ($b != 0) {
<line>"Take one down and pass it around, " nil:bottles($b - 1); " of beer on the wall."</line>
} else {
<line>"Go to the store and buy some more, 99 bottles of beer on the wall."</line>
}
</verse>
}
</song>;
}

Candle Runtime

Candle runtime currently runs on Windows and Linux (Ubuntu). The runtime is very lightweight, being only 2MB compressed.

The runtime can run in 3 modes: command line mode, desktop GUI mode or web server mode.

Further Reading


External Links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK