WMLScript Primer: Compilation Units and Pragmas | WebReference

WMLScript Primer: Compilation Units and Pragmas


WMLScript Primer

Compilation Units and Pragmas

WMLScript is a compiled language and uses Compilation Units and Pragmas. A certain application may include separate scripts that were individually and independently compiled. A compilation unit can call functions that are defined in another compilation unit. WMLScript uses pragmas to identify other compilation units that it uses.

The use url pragma specifies the location (URL) of the external WMLScript resource and gives it a local name. This name can then be used inside a function declarations to make external function calls. Let's examine the following example:

use url DocJS "https://www.docjavascript.com/mylibs/mywmlscript"
function divide(nom, denom) {
  if (denominator == 0) return invalid;
  return DocJS#mydiv(nom, denom);
}

The sequence of operations that take place here is fairly intuitive. The use url pragma specifies a URL to a WMLScript compilation unit, https://www.docjavascript.com/mylibs/mywmlscript. If the file extension is omitted (as above), the user agent will look for the extension .wmlsc, i.e. it will look for https://www.docjavascript.com/mylibs/mywmlscript.wmlsc. As we explained in our previous column, WMLScript scripts are stored under .wmls file extension and their compilation results are stored under .wmlsc.

Once the file is found, the function call DocJS#mydiv() triggers the loading of the external compilation unit, https://www.docjavascript.com/mylibs/mywmlscript.wmlsc. Upon successful loading of the external resource, its content is verified to have the definition of the mydiv() function, and it is actually executed with the calling parameters, mydiv(nom, denom). The use url pragma has its own name space for local names, but they must be unique within the same compilation unit.

Another type of pragma is the access control pragma. Every compilation unit can have only one access control pragma. The access control pragram specify which URLs can call the external functions in the access-controlled compilation unit. The syntax of access control pragma may be specified in any one of the following forms:

use access domain 
use access domain ;
use access path ;
use access domain  path ;

The referring compilation unit's URL must match the access control specification. A URL consists of a domain name and a path. The referring compilation unit's domain name is matched with the access domain specification, while the compilation unit's path is matched with the access path specification. The domain matching is guided by two principles. First, they are suffix matched, i.e. matching is done from right to left. Secondly, entire sub-domain elements mush match. Given the following access control for a compilation unit:

use access domain "webreference.com" path "/js";

The following URLs would be allowed to call the external function in the access-controlled compilation unit above:

https://webreference.com/js/tips.cgi
https://www.webreference.com/js/categories.wmlsc
https://www.webreference.com/js/tools/newtool.cgi?x=123<y=456

But the following URLs would not be allowed to call the external functions:

https://www.microsoft.com/javascript
https://www.webreference.com/dhtml/mytool.cgi

As you can notice, the access path is prefix-matched, i.e. from left to right. The same principles hold here as well, including that entire sub elements must be matched. The path /js will not match /j/mytools, for example. By default, access control is disabled, so all external functions have public access.

The third type of pragmas is the meta information pragma. It conveys information between different players of the wireless communication: originating servers, connecting servers, and user agents. The name meta pragma may be used by the originating servers for different kind of information. Here is an example:

use meta name "Created" "22-May-00";

The HTTP equiv meta pragma is used to specify HTTP header information for those mediating servers that transfer the compilation unit. Here is an example:

use meta http equiv "Keywords" "Script, Language";

And finally, the user agent should also be able to receive information from the server. Here is an example:

use meta user agent "Type" "Test"

Next: How to read the Mortgage example

https://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

Created: May 22, 2000
Revised: May 22, 2000

URL: https://www.webreference.com/js/column62/4.html