From: Alexander K. <kw...@ah...> - 2004-04-27 11:08:07
|
Colin Paul Adams wrote: > Eric wants ${NAME} syntax for compatibility with pre-existing XACE > files. This syntax is not valid XPath syntax. I would suggest > pre-processing the strings to strip the {}, using gelex. I guess, the pre-processor should issue a warning message in this case. And, if I'm not mistaken, the expression "${A}=b" should be rewritten as "$A='b'" or (with pre-processing turned on) as "${A}='b'". > Some time ago, Alexander suggested that I provide an option for all > missing XPath variables to be automatically declared as of type > xs:boolean, and to have a value of False. It allows writing something like <option name="debugger" if="$DEBUG"/> without raising an error if DEBUG is not declared. > I have not implemented this directly. > The class XM_XPATH_STATIC_CONTEXT has two deferred features: > > is_variable_declared (a_fingerprint: INTEGER): BOOLEAN is > -- Does `a_fingerprint' represent a variable declared in the static context? > require > positive_fingerprint: a_fingerprint >= 0 > deferred > end > > and > > bind_variable (a_fingerprint: INTEGER) is > -- Bind variable to it's declaration. > require > variable_declared: is_variable_declared (a_fingerprint) > deferred > ensure > variable_bound: last_bound_variable /= Void > end It might make sense to have a feature bind_variable (a_fingerprint: INTEGER) is -- Bind variable to it's declaration. require valid_fingerprint: ... (a_fingerprint) deferred ensure variable_bound: is_variable_bound implies last_bound_variable /= Void end and is_variable_bound: BOOLEAN -- Is a variable bound by last call to `bind_variable'? like it is done with "bind_function". BTW, how does one get an actual variable name from `a_fingerprint'? Using XM_XPATH_NAME_POOL's features `namespace_uri_from_name_code' and `local_name_from_name_code'? And what happens if there are two namespaces with the same URI, say `a' and `b' with the URI "http://ab" and the feature `declare_variable' of XM_XPATH_STAND_ALONE_CONTEXT is called: declare_variable ("a:x", ...) declare_variable ("b:x", ...) As far as I can see, the precondition allows this. But should not it be the same variable instead? > The stand alone evaluator has a routine: > > set_static_context (a_static_context: XM_XPATH_STAND_ALONE_CONTEXT) is It looks like no specific XM_XPATH_STAND_ALONE_CONTEXT features are used. Would it make sense to use XM_XPATH_STATIC_CONTEXT? > My suggestion for how this should work is as follows: > > 1) XACE to have it's own static context class, as a descendant of > XM_XPATH_STAND_ALONE_CONTEXT (for the rest of this, I shall call it ET_XACE_XPATH_CONTEXT). > 2) ET_XACE_XPATH_CONTEXT redefines the routine is_variable_declared to > always return True. > 3) ET_XACE_XPATH_CONTEXT redefines the routine bind_variable to check > if a definition for the variable exists. If not, then it creates one > with it's initial value as an instance of XM_XPATH_BOOLEAN_VALUE (with > the value set to False). > 4) At execution time, when XACE encounters an XPath string that needs > evaluation, it creates an instance of ET_XACE_XPATH_CONTEXT, declares > any variables known to XACE by calling declare_variable (this is > going to need a little more re-definition, as it has a precondition > which ultimately calls not is_variable_declared), but a simple require > else will solve that), creates an instance of XM_XPATH_EVALUATOR, > calls set_static_context upon it, and then calls evaluate. > 5) XACE will check that the returned sequence from evaluate has only 1 > item, (after first checking the evaluation was not in error), and then > access this item with an assignement attempt to XM_XPATH_BOOLEAN_VALUE > (I'm assuming we are evaluating an if or unless attribute). This > assignment attempt suceeds (so a check statement is appropriate), and > then you can retrieve the BOOLEAN result. The last step could be simplified if the expression E in "if"/"unless" is translated into an expression "boolean(E)" before passing it to XM_XPATH_EVALUATOR. Then if this expression evaluates without errors, it will give only 1 item of type boolean. Alexander Kogtenkov |