2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
48 /**********************************************************
50 **********************************************************/
54 //end of parsed string
58 TOK_NAME, // name test, incl. '*' and 'prefix:*'
59 TOK_AXISNAME, // name followed by ::
60 TOK_NTNAME, // node(), text() etc.
61 TOK_FNAME, // other names followed by (
64 TOK_LPAREN, TOK_RPAREN,
65 TOK_LBRACKET, TOK_RBRACKET,
66 TOK_PERIOD, TOK_DPERIOD,
67 TOK_ATSIGN, TOK_COMMA,
68 TOK_DCOLON, TOK_DSLASH,
71 //variable reference ($...)
80 TOK_OR = TOKGROUP_OPERATORS,
90 TOK_MINUS = TOK_MINUS2,
97 TOK_STAR, // as wildcard in names
101 class TokenItem /* : public SabObj */
107 void speak(DStr &, SpeakMode mode);
110 //ExNodeType is defined in base.h
111 //array exNodeTypeNames in base.cpp
116 Tokenizer(Expression &owner_);
118 int findTop(ExToken token, int from);
119 eFlag tokenize(Sit S, const Str &astring);
120 eFlag getToken(Sit S, char *&, TokenItem&, ExToken);
121 eFlag getDelim(Sit S, int &, Bool = FALSE);
122 eFlag stripParens(Sit S, int &, int &);
124 PList<TokenItem*> items;
126 ExToken tryShort(char *&, ExToken);
127 eFlag lookToken(Sit S, ExToken &, char*, ExToken);
128 eFlag getToken_(Sit S, ExToken &, char*&, ExToken);
129 eFlag getNumber(Sit S, char *&);
130 eFlag getName(Sit S, ExToken&, char *&, ExToken);
131 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
136 XPath expression types. Correspondence to Sablotron classes:
140 NODESET class Context
158 The following enum comprises four categories of "functors":
159 (1) basic (atom, variable reference etc.)
160 (2) operators (EXFO_...)
161 (3) functions in the XPath core library (EXFF_XPATH_...)
162 (4) functions in the XSLT core library (EXFF_XSLT_...)
164 Groups (2) through (4) should be listed in the given order (that is, operators -
165 XPath functions - XSLT functions) and should end with an item ..._Z
181 // EXFO_... (operators)
192 EXFO_MINUS = EXFO_MINUS2,
198 EXFO_Z, //last in group
200 //functions (fall into 2 groups: core XPath and core XSLT)
217 EXFF_SUBSTRING_BEFORE,
218 EXFF_SUBSTRING_AFTER,
221 EXFF_NORMALIZE_SPACE,
243 EXFF_UNPARSED_ENTITY_URI,
245 EXFF_SYSTEM_PROPERTY,
248 EXFF_FUNCTION_AVAILABLE,
249 EXFF_ELEMENT_AVAILABLE,
255 /**********************************************************
257 **********************************************************/
259 class Number /* : public SabObj */
264 Number& operator= (double);
265 Number& operator= (const Str &);
266 operator double () const;
267 Bool operator== (double);
268 Bool operator< (double);
269 Bool operator> (double);
270 Bool operator== (Number&);
271 Bool operator< (Number&);
272 Bool operator> (Number&);
281 /**********************************************************
283 **********************************************************/
288 External() : priv(NULL) {};
289 External(void *prv, void *val);
290 External(External& other);
293 void assign(const External& other);
296 JSExternalPrivate *priv;
300 /**********************************************************
302 **********************************************************/
306 class LocStep /* : public SabObj */
308 friend class Expression;
310 LocStep(Element &ownerV_, ExAxis = AXIS_NONE, ExNodeType = EXNODE_NONE);
312 void set(ExAxis, ExNodeType);
313 eFlag parse(Sit S, Tokenizer&, int&, Bool defaultToo = FALSE);
317 Str piname; //name for the processing-instruction() node test
319 void speak(Sit S, DStr &s, SpeakMode mode);
320 Bool matchesWithoutPreds(Sit S, NodeHandle v);
321 // eFlag createContextNoPreds(Context *&, int);
322 eFlag shift(Sit S, NodeHandle &v, NodeHandle baseV);
324 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
325 Element &getOwnerElement() {return ownerV;}
332 /**********************************************************
334 **********************************************************/
341 Expression(Element & owner_, ExFunctor = EXF_NONE);
344 void setLS(ExAxis, ExNodeType);
345 eFlag speak(Sit S, DStr &,SpeakMode);
346 eFlag parse(Sit S, const DStr &, Bool = FALSE, Bool defaultToo = FALSE);
347 eFlag parse(Sit S, Tokenizer&, int, int, Bool defaultToo = FALSE);
348 eFlag eval(Sit S, Expression &, Context *, Bool resolvingGlobals = FALSE);
349 Number tonumber(Sit S);
351 External toexternal(Sit S);
353 eFlag tostring(Sit S, Str& result);
354 const Str& tostringRef() const;
356 Context& tonodeset();
357 const Context& tonodesetRef();
358 eFlag matchesPattern(Sit S, Context *, Bool &result);
359 eFlag trueFor(Sit S, Context *, Bool&);
364 eFlag createContext(Sit S, Context *&, int = -1);
367 void setAtom(Context*);
368 void setAtom(const Number&);
369 void setAtom(const DStr&);
372 void setAtom(const External&);
377 // optimizePositional() sets usesLast and positional
378 // returns: 2 if pred contains last() ( -> usesLast && positional )
379 // 1 if position() only ( -> positional )
381 int optimizePositional(int level);
383 // optimizePositionBounds() sets optimizePosition...
384 void optimizePositionBounds();
387 // returns 0 if the position is within bounds, -1 if before, 1 if after
388 int inBounds(int position) const;
389 Element& getOwnerElement() const;
390 Tree& getOwnerTree() const;
391 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
392 Bool containsFunctor(ExFunctor func);
397 QName *pName; //of function or variable
401 Context *patomnodeset;
403 External *patomexternal;
406 Bool compareCC(Sit S, ExFunctor, const Context &, const Context &);
407 Bool compareCS(Sit S, ExFunctor, const Context &, const Str &);
408 Bool compareCN(Sit S, ExFunctor, const Context &, const Number &);
409 eFlag compare(Sit S, Bool &, Expression &, ExFunctor);
410 Bool isOp(ExToken, int &);
411 eFlag callOp(Sit S, Expression&, ExprList&);
412 eFlag callFunc(Sit S, Expression&, ExprList&, Context *);
413 eFlag parseBasic(Sit S, Tokenizer &, int, int, Bool defaultToo = FALSE);
414 eFlag parseLP(Sit S, Tokenizer&, int &, Bool dropRoot, Bool defaultToo = FALSE);
415 eFlag matchesSinglePath(Sit S, NodeHandle v, int lastIndex, Bool &result);
416 eFlag matchesSingleStep(Sit S, NodeHandle v, Bool &result);
417 eFlag createLPContextLevel(Sit S, int stepLevel, int stepsCount,
418 NodeHandle base, Context& info, Context *theResult);
419 eFlag createLPContext(Sit S, Context *&, int, NodeHandle globalCurrent = NULL);
420 eFlag createLPContextSum(Sit S, Context *&, NodeHandle globalCurrent = NULL);
421 eFlag getDocument_(Sit S, NodeHandle& newroot,
422 const Str& location, const Str& baseUri, Processor *proc);
426 eFlag patternOK(Sit S);
427 void setAtomNoCopy(Context &);
429 // in a predicate, these give the bounds to context positions that
430 // suffice to be processed
431 int optimizePositionFrom,
434 // in a predicate, this is true iff the predicate depends on last()
441 #endif //ifndef ExprHIncl