Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / xml / XPathGrammar.y
blob6774e5d043b15a813a7ac5fd577e2107587a7889
1 /*
2 * Copyright 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "config.h"
32 #include "core/xml/XPathFunctions.h"
33 #include "core/xml/XPathNSResolver.h"
34 #include "core/xml/XPathParser.h"
35 #include "core/xml/XPathPath.h"
36 #include "core/xml/XPathPredicate.h"
37 #include "core/xml/XPathStep.h"
38 #include "core/xml/XPathVariableReference.h"
39 #include "wtf/FastMalloc.h"
41 #define YYMALLOC fastMalloc
42 #define YYFREE fastFree
44 #define YYENABLE_NLS 0
45 #define YYLTYPE_IS_TRIVIAL 1
46 #define YYDEBUG 0
47 #define YYMAXDEPTH 10000
49 using namespace blink;
50 using namespace XPath;
54 %pure-parser
55 %parse-param { blink::XPath::Parser* parser }
57 %union
59 blink::XPath::Step::Axis axis;
60 blink::XPath::Step::NodeTest* nodeTest;
61 blink::XPath::NumericOp::Opcode numop;
62 blink::XPath::EqTestOp::Opcode eqop;
63 String* str;
64 blink::XPath::Expression* expr;
65 blink::HeapVector<blink::Member<blink::XPath::Predicate>>* predList;
66 blink::HeapVector<blink::Member<blink::XPath::Expression>>* argList;
67 blink::XPath::Step* step;
68 blink::XPath::LocationPath* locationPath;
73 static int xpathyylex(YYSTYPE* yylval) { return Parser::current()->lex(yylval); }
74 static void xpathyyerror(void*, const char*) { }
78 %left <numop> MULOP
79 %left <eqop> EQOP RELOP
80 %left PLUS MINUS
81 %left OR AND
82 %token <axis> AXISNAME
83 %token <str> NODETYPE PI FUNCTIONNAME LITERAL
84 %token <str> VARIABLEREFERENCE NUMBER
85 %token DOTDOT SLASHSLASH
86 %token <str> NAMETEST
87 %token XPATH_ERROR
89 %type <locationPath> LocationPath
90 %type <locationPath> AbsoluteLocationPath
91 %type <locationPath> RelativeLocationPath
92 %type <step> Step
93 %type <axis> AxisSpecifier
94 %type <step> DescendantOrSelf
95 %type <nodeTest> NodeTest
96 %type <expr> Predicate
97 %type <predList> OptionalPredicateList
98 %type <predList> PredicateList
99 %type <step> AbbreviatedStep
100 %type <expr> Expr
101 %type <expr> PrimaryExpr
102 %type <expr> FunctionCall
103 %type <argList> ArgumentList
104 %type <expr> Argument
105 %type <expr> UnionExpr
106 %type <expr> PathExpr
107 %type <expr> FilterExpr
108 %type <expr> OrExpr
109 %type <expr> AndExpr
110 %type <expr> EqualityExpr
111 %type <expr> RelationalExpr
112 %type <expr> AdditiveExpr
113 %type <expr> MultiplicativeExpr
114 %type <expr> UnaryExpr
118 Expr:
119 OrExpr
121 parser->m_topExpr = $1;
125 LocationPath:
126 RelativeLocationPath
128 $$->setAbsolute(false);
131 AbsoluteLocationPath
133 $$->setAbsolute(true);
137 AbsoluteLocationPath:
140 $$ = new LocationPath;
143 '/' RelativeLocationPath
145 $$ = $2;
148 DescendantOrSelf RelativeLocationPath
150 $$ = $2;
151 $$->insertFirstStep($1);
155 RelativeLocationPath:
156 Step
158 $$ = new LocationPath;
159 $$->appendStep($1);
162 RelativeLocationPath '/' Step
164 $$->appendStep($3);
167 RelativeLocationPath DescendantOrSelf Step
169 $$->appendStep($2);
170 $$->appendStep($3);
174 Step:
175 NodeTest OptionalPredicateList
177 if ($2)
178 $$ = new Step(Step::ChildAxis, *$1, *$2);
179 else
180 $$ = new Step(Step::ChildAxis, *$1);
183 NAMETEST OptionalPredicateList
185 AtomicString localName;
186 AtomicString namespaceURI;
187 if (!parser->expandQName(*$1, localName, namespaceURI)) {
188 parser->m_gotNamespaceError = true;
189 YYABORT;
192 if ($2)
193 $$ = new Step(Step::ChildAxis, Step::NodeTest(Step::NodeTest::NameTest, localName, namespaceURI), *$2);
194 else
195 $$ = new Step(Step::ChildAxis, Step::NodeTest(Step::NodeTest::NameTest, localName, namespaceURI));
196 parser->deleteString($1);
199 AxisSpecifier NodeTest OptionalPredicateList
201 if ($3)
202 $$ = new Step($1, *$2, *$3);
203 else
204 $$ = new Step($1, *$2);
207 AxisSpecifier NAMETEST OptionalPredicateList
209 AtomicString localName;
210 AtomicString namespaceURI;
211 if (!parser->expandQName(*$2, localName, namespaceURI)) {
212 parser->m_gotNamespaceError = true;
213 YYABORT;
216 if ($3)
217 $$ = new Step($1, Step::NodeTest(Step::NodeTest::NameTest, localName, namespaceURI), *$3);
218 else
219 $$ = new Step($1, Step::NodeTest(Step::NodeTest::NameTest, localName, namespaceURI));
220 parser->deleteString($2);
223 AbbreviatedStep
226 AxisSpecifier:
227 AXISNAME
231 $$ = Step::AttributeAxis;
235 NodeTest:
236 NODETYPE '(' ')'
238 if (*$1 == "node")
239 $$ = new Step::NodeTest(Step::NodeTest::AnyNodeTest);
240 else if (*$1 == "text")
241 $$ = new Step::NodeTest(Step::NodeTest::TextNodeTest);
242 else if (*$1 == "comment")
243 $$ = new Step::NodeTest(Step::NodeTest::CommentNodeTest);
245 parser->deleteString($1);
248 PI '(' ')'
250 $$ = new Step::NodeTest(Step::NodeTest::ProcessingInstructionNodeTest);
251 parser->deleteString($1);
254 PI '(' LITERAL ')'
256 $$ = new Step::NodeTest(Step::NodeTest::ProcessingInstructionNodeTest, $3->stripWhiteSpace());
257 parser->deleteString($1);
258 parser->deleteString($3);
262 OptionalPredicateList:
263 /* empty */
265 $$ = 0;
268 PredicateList
271 PredicateList:
272 Predicate
274 $$ = new blink::HeapVector<blink::Member<Predicate>>;
275 $$->append(new Predicate($1));
278 PredicateList Predicate
280 $$->append(new Predicate($2));
284 Predicate:
285 '[' Expr ']'
287 $$ = $2;
291 DescendantOrSelf:
292 SLASHSLASH
294 $$ = new Step(Step::DescendantOrSelfAxis, Step::NodeTest(Step::NodeTest::AnyNodeTest));
298 AbbreviatedStep:
301 $$ = new Step(Step::SelfAxis, Step::NodeTest(Step::NodeTest::AnyNodeTest));
304 DOTDOT
306 $$ = new Step(Step::ParentAxis, Step::NodeTest(Step::NodeTest::AnyNodeTest));
310 PrimaryExpr:
311 VARIABLEREFERENCE
313 $$ = new VariableReference(*$1);
314 parser->deleteString($1);
317 '(' Expr ')'
319 $$ = $2;
322 LITERAL
324 $$ = new StringExpression(*$1);
325 parser->deleteString($1);
328 NUMBER
330 $$ = new Number($1->toDouble());
331 parser->deleteString($1);
334 FunctionCall
337 FunctionCall:
338 FUNCTIONNAME '(' ')'
340 $$ = createFunction(*$1);
341 if (!$$)
342 YYABORT;
343 parser->deleteString($1);
346 FUNCTIONNAME '(' ArgumentList ')'
348 $$ = createFunction(*$1, *$3);
349 if (!$$)
350 YYABORT;
351 parser->deleteString($1);
355 ArgumentList:
356 Argument
358 $$ = new blink::HeapVector<blink::Member<Expression>>;
359 $$->append($1);
362 ArgumentList ',' Argument
364 $$->append($3);
368 Argument:
369 Expr
372 UnionExpr:
373 PathExpr
375 UnionExpr '|' PathExpr
377 $$ = new Union;
378 $$->addSubExpression($1);
379 $$->addSubExpression($3);
383 PathExpr:
384 LocationPath
386 $$ = $1;
389 FilterExpr
391 FilterExpr '/' RelativeLocationPath
393 $3->setAbsolute(true);
394 $$ = new Path($1, $3);
397 FilterExpr DescendantOrSelf RelativeLocationPath
399 $3->insertFirstStep($2);
400 $3->setAbsolute(true);
401 $$ = new Path($1, $3);
405 FilterExpr:
406 PrimaryExpr
408 PrimaryExpr PredicateList
410 $$ = new Filter($1, *$2);
414 OrExpr:
415 AndExpr
417 OrExpr OR AndExpr
419 $$ = new LogicalOp(LogicalOp::OP_Or, $1, $3);
423 AndExpr:
424 EqualityExpr
426 AndExpr AND EqualityExpr
428 $$ = new LogicalOp(LogicalOp::OP_And, $1, $3);
432 EqualityExpr:
433 RelationalExpr
435 EqualityExpr EQOP RelationalExpr
437 $$ = new EqTestOp($2, $1, $3);
441 RelationalExpr:
442 AdditiveExpr
444 RelationalExpr RELOP AdditiveExpr
446 $$ = new EqTestOp($2, $1, $3);
450 AdditiveExpr:
451 MultiplicativeExpr
453 AdditiveExpr PLUS MultiplicativeExpr
455 $$ = new NumericOp(NumericOp::OP_Add, $1, $3);
458 AdditiveExpr MINUS MultiplicativeExpr
460 $$ = new NumericOp(NumericOp::OP_Sub, $1, $3);
464 MultiplicativeExpr:
465 UnaryExpr
467 MultiplicativeExpr MULOP UnaryExpr
469 $$ = new NumericOp($2, $1, $3);
473 UnaryExpr:
474 UnionExpr
476 MINUS UnaryExpr
478 $$ = new Negative;
479 $$->addSubExpression($2);