618
618
//# X P A T H G R A M M A R P A R S I N G
619
619
//#########################################################################
622
void XPathParser::tokAdd(Token *tok)
621
//## Various shorthand methods to add a token to the list
622
void XPathParser::tokAdd(const Token &tok)
627
void XPathParser::tokAdd(int type)
629
tokens.add(Token::create(type));
632
void XPathParser::tokAdd(int type, long val)
634
tokens.add(Token::create(type, val));
637
void XPathParser::tokAdd(int type, double val)
639
tokens.add(Token::create(type, val));
642
void XPathParser::tokAdd(int type, const DOMString &val)
644
tokens.add(Token::create(type, val));
651
//########################################
652
//# Grammar - specific parsing
653
//########################################
628
656
* [1] LocationPath ::=
629
657
* RelativeLocationPath
831
859
switch (axisType)
833
861
case ANCESTOR_OR_SELF:
834
tokAdd(new TokAxisAncestorOrSelf());
862
tokAdd(Token::TOK_AXIS_ANCESTOR_OR_SELF);
836
tokAdd(new TokAxisAncestor());
865
tokAdd(Token::TOK_AXIS_ANCESTOR);
838
tokAdd(new TokAxisAttribute());
868
tokAdd(Token::TOK_AXIS_ATTRIBUTE);
840
tokAdd(new TokAxisChild());
871
tokAdd(Token::TOK_AXIS_CHILD);
841
873
case DESCENDANT_OR_SELF:
842
tokAdd(new TokAxisDescendantOrSelf());
874
tokAdd(Token::TOK_AXIS_DESCENDANT_OR_SELF);
844
tokAdd(new TokAxisDescendant());
877
tokAdd(Token::TOK_AXIS_DESCENDANT);
845
879
case FOLLOWING_SIBLING:
846
tokAdd(new TokAxisFollowingSibling());
880
tokAdd(Token::TOK_AXIS_FOLLOWING_SIBLING);
848
tokAdd(new TokAxisFollowing());
883
tokAdd(Token::TOK_AXIS_FOLLOWING);
850
tokAdd(new TokAxisNamespace());
886
tokAdd(Token::TOK_AXIS_NAMESPACE);
852
tokAdd(new TokAxisParent());
889
tokAdd(Token::TOK_AXIS_PARENT);
853
891
case PRECEDING_SIBLING:
854
tokAdd(new TokAxisPrecedingSibling());
892
tokAdd(Token::TOK_AXIS_PRECEDING_SIBLING);
856
tokAdd(new TokAxisPreceding());
895
tokAdd(Token::TOK_AXIS_PRECEDING);
858
tokAdd(new TokAxisSelf());
898
tokAdd(Token::TOK_AXIS_SELF);
861
902
error("unknown axis type %d", axisType);
1196
1237
// Function names from http://www.w3.org/TR/xpath#NT-FunctionName
1197
1238
if (name == "last")
1198
tokens.add(new TokFuncLast());
1239
tokAdd(Token::TOK_FUNC_LAST);
1199
1240
else if (name == "position")
1200
tokens.add(new TokFuncPosition());
1241
tokAdd(Token::TOK_FUNC_POSITION);
1201
1242
else if (name == "count")
1202
tokens.add(new TokFuncCount());
1243
tokAdd(Token::TOK_FUNC_COUNT);
1203
1244
else if (name == "id")
1204
tokens.add(new TokFuncId());
1245
tokAdd(Token::TOK_FUNC_ID);
1205
1246
else if (name == "local-name")
1206
tokens.add(new TokFuncLocalName());
1247
tokAdd(Token::TOK_FUNC_LOCAL_NAME);
1207
1248
else if (name == "namespace-uri")
1208
tokens.add(new TokFuncNamespaceUri());
1249
tokAdd(Token::TOK_FUNC_NAMESPACE_URI);
1209
1250
else if (name == "name")
1210
tokens.add(new TokFuncName());
1251
tokAdd(Token::TOK_FUNC_NAME);
1211
1252
else if (name == "string")
1212
tokens.add(new TokFuncString());
1253
tokAdd(Token::TOK_FUNC_STRING);
1213
1254
else if (name == "concat")
1214
tokens.add(new TokFuncConcat());
1255
tokAdd(Token::TOK_FUNC_CONCAT);
1215
1256
else if (name == "starts-with")
1216
tokens.add(new TokFuncStartsWith());
1257
tokAdd(Token::TOK_FUNC_STARTS_WITH);
1217
1258
else if (name == "contains")
1218
tokens.add(new TokFuncContains());
1259
tokAdd(Token::TOK_FUNC_CONTAINS);
1219
1260
else if (name == "substring-before")
1220
tokens.add(new TokFuncSubstringBefore());
1261
tokAdd(Token::TOK_FUNC_SUBSTRING_BEFORE);
1221
1262
else if (name == "substring-after")
1222
tokens.add(new TokFuncSubstringAfter());
1263
tokAdd(Token::TOK_FUNC_SUBSTRING_AFTER);
1223
1264
else if (name == "substring")
1224
tokens.add(new TokFuncSubstring());
1265
tokAdd(Token::TOK_FUNC_SUBSTRING);
1225
1266
else if (name == "string-length")
1226
tokens.add(new TokFuncStringLength());
1267
tokAdd(Token::TOK_FUNC_STRING_LENGTH);
1227
1268
else if (name == "normalize-space")
1228
tokens.add(new TokFuncNormalizeSpace());
1269
tokAdd(Token::TOK_FUNC_NORMALIZE_SPACE);
1229
1270
else if (name == "translate")
1230
tokens.add(new TokFuncTranslate());
1271
tokAdd(Token::TOK_FUNC_TRANSLATE);
1231
1272
else if (name == "boolean")
1232
tokens.add(new TokFuncBoolean());
1273
tokAdd(Token::TOK_FUNC_BOOLEAN);
1233
1274
else if (name == "not")
1234
tokens.add(new TokFuncNot());
1275
tokAdd(Token::TOK_FUNC_NOT);
1235
1276
else if (name == "true")
1236
tokens.add(new TokFuncTrue());
1277
tokAdd(Token::TOK_FUNC_TRUE);
1237
1278
else if (name == "false")
1238
tokens.add(new TokFuncFalse());
1279
tokAdd(Token::TOK_FUNC_FALSE);
1239
1280
else if (name == "lang")
1240
tokens.add(new TokFuncLang());
1281
tokAdd(Token::TOK_FUNC_LANG);
1241
1282
else if (name == "number")
1242
tokens.add(new TokFuncNumber());
1283
tokAdd(Token::TOK_FUNC_NUMBER);
1243
1284
else if (name == "sum")
1244
tokens.add(new TokFuncSum());
1285
tokAdd(Token::TOK_FUNC_SUM);
1245
1286
else if (name == "floor")
1246
tokens.add(new TokFuncFloor());
1287
tokAdd(Token::TOK_FUNC_FLOOR);
1247
1288
else if (name == "ceiling")
1248
tokens.add(new TokFuncCeiling());
1289
tokAdd(Token::TOK_FUNC_CEILING);
1249
1290
else if (name == "round")
1250
tokens.add(new TokFuncRound());
1291
tokAdd(Token::TOK_FUNC_ROUND);
1253
1294
error("unknown function name:'%s'", name.c_str());