Symbol Table

The symbol table stores the defined variables (constants), parameters, procs, and matches that have been declared in the stylesheet.

There is an important caveat here. Rexsel treats the definition of symbols as a combined space rather than as a set of mutually exclusive ones. So in XSLT named templates (proc) can have the same name as a variable without any error. Rexsel assumes that all symbols/names should be different. This way a consistent symbol table with references can be produced. This is not a particularly onerous thing to do since it aids stylesheets that are unambiguous. However although Rexsel may report multiple definition errors it will still generate XSLT code. so a named template can have the same name as a variable, Rexsel wuill report the error but XSTL code will still be produced.

The symbol table is output in a simple format:

Symbols in context "<context hame>" found: <number of symbols found in that context> [<type of symbol 1>] <symbol name 1> in line <line where symbol declared 1> <where used> [<type of symbol 2>] <symbol name 2> in line <line where symbol declared 2> <where used>

where a context is defined as the locality within a proc (function) etc. that provides the scope of each variable.

The symbol type can be proc (F), key (K), variable/constant (V), attribute-set (A), parameter (P), or match (M). Where the symbol type is associated with a match the XPath expression and the scope are used together in the format "xpath::scope". For example if the source is.

match using "node() | @*" priority "-1" scope "inline-text" {

the symbol table entry would be, for example

[M] node() | @*/::inline-text in line 20

A variable used within a particular scope has access to defined variables and parameters inherited from its parent scope and then up to the top level. By definition the top level (within stylesheet) is global and all enclosed variables/parameters have access to those declared global.

For example the symbol table for the extended example tangle.rxsl would be

Symbols in stylesheet context in line 1, found: 6 symbols [M] "/" in line 20 [M] "node() | @*" in line 90 [P] endCommentString in line 15 used in line(s) 57 [P] rootChunk in line 13 used in line(s) 22, 25, 29 [P] startCommentString in line 14 used in line(s) 54 [F] process-code in line 47 used in line(s) 36, 70 Symbols in foreach context //aw:chunk[(@name = '*' or @name = $rootChunk) and @type = 'code'] in line 22, found: 2 symbols [V] firstChunkPosition in line 34 used in line(s) 37 [V] rootName in line 23 used in line(s) 39 Symbols in proc context process-code in line 47, found: 3 symbols [P] chunkNode in line 49 used in line(s) 52 [P] isFirstChunk in line 48 used in line(s) 53 [P] name in line 50 used in line(s) 57 Symbols in when context name() = 'aw:include' in line 65, found: 1 symbol [V] chunkRef in line 68 used in line(s) 72, 73

To show a more contrived example to illustrate more complex contexts

stylesheet { version "1.0" parameter param-1 variable globalConstant-0 "$globalConstant-2" variable globalConstant-1 { variable localConstant-2 "'Inner String 1'" value "$localConstant-2” } variable globalConstant-2 { variable localConstant-5 "'xxx'" variable localConstant-6 { variable localConstant-7 "'yyy" value "$globalConstant-1" variable localConstant-8 { variable localConstant-9 "$localConstant-7" value "$localConstant-9" value "$localConstant-2" } } } }

Compiling this with

crexsel tangle.rxsl --errors --symbols

gives

**** (116) Could not find "localConstant-2" in line 22 Check "localConstant-2" is defined in current block/context. Symbols in stylesheet context in line 1, found: 4 symbols [P] param-1 in line 4 not used [V] globalConstant-0 in line 6 not used [V] globalConstant-1 in line 8 used in line(s) 17 [V] globalConstant-2 in line 13 used in line(s) 6 Symbols in variable context globalConstant-1 in line 8, found: 1 symbol [V] localConstant-2 in line 9 used in line(s) 10 Symbols in variable context globalConstant-2 in line 13, found: 2 symbols [V] localConstant-5 in line 14 not used [V] localConstant-6 in line 15 not used Symbols in variable context localConstant-6 in line 15, found: 2 symbols [V] localConstant-7 in line 16 used in line(s) 20 [V] localConstant-8 in line 19 not used Symbols in variable context localConstant-8 in line 19, found: 1 symbol [V] localConstant-9 in line 20 used in line(s) 21

This shows that localConstant-2 in the globalConstant-1 context cannot be accessed in the globalConstant-2 context.

Copyright 2024 Hugh Field-Richards. All Rights Reserved.