summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/xml/xpath_grammar.y
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/xml/xpath_grammar.y')
-rw-r--r--chromium/third_party/blink/renderer/core/xml/xpath_grammar.y237
1 files changed, 122 insertions, 115 deletions
diff --git a/chromium/third_party/blink/renderer/core/xml/xpath_grammar.y b/chromium/third_party/blink/renderer/core/xml/xpath_grammar.y
index cf0208370a0..a88d822f1ec 100644
--- a/chromium/third_party/blink/renderer/core/xml/xpath_grammar.y
+++ b/chromium/third_party/blink/renderer/core/xml/xpath_grammar.y
@@ -25,6 +25,30 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/* === NOTA BENE ===
+ * If you modify this file, you must run bison to regenerate the corresponding
+ * .cc and .h files. From chromium's root directory, run the following command
+ * on a system with a modern version of bison (>= 3.4.1):
+ *
+ * $ third_party/blink/renderer/build/scripts/rule_bison.py \
+ * third_party/blink/renderer/core/xml/xpath_grammar.y \
+ * third_party/blink/renderer/core/xml/ \
+ * bison
+ *
+ * This process is not automated because newer bison releases have diverged from
+ * (1) the version included with Xcode and (2) the Windows binary checked into
+ * //third_party/bison. See https://crbug.com/1028421.
+ */
+
+%require "3.4"
+%language "c++"
+
+%code requires {
+
+#include "third_party/blink/renderer/platform/heap/persistent.h"
+
+}
+
%{
#include "third_party/blink/renderer/core/xml/xpath_functions.h"
@@ -35,101 +59,89 @@
#include "third_party/blink/renderer/core/xml/xpath_step.h"
#include "third_party/blink/renderer/core/xml/xpath_variable_reference.h"
-// The union below must be located on the stack because it contains raw
-// pointers to Oilpan objects. crbug.com/961413
-#define YYSTACK_USE_ALLOCA 1
-// Bison's bug? YYSTACK_ALLOC is not defined if _MSC_VER.
-#if defined(_MSC_VER)
-#define YYSTACK_ALLOC _alloca
-#endif
-
#define YYENABLE_NLS 0
-#define YYLTYPE_IS_TRIVIAL 1
+#define YY_EXCEPTIONS 0
#define YYDEBUG 0
-#define YYMAXDEPTH 10000
using blink::xpath::Step;
%}
-%pure-parser
-%parse-param { blink::xpath::Parser* parser }
-
-%union
-{
- blink::xpath::Step::Axis axis;
- blink::xpath::Step::NodeTest* node_test;
- blink::xpath::NumericOp::Opcode num_op;
- blink::xpath::EqTestOp::Opcode eq_op;
- String* str;
- blink::xpath::Expression* expr;
- blink::HeapVector<blink::Member<blink::xpath::Predicate>>* pred_list;
- blink::HeapVector<blink::Member<blink::xpath::Expression>>* arg_list;
- blink::xpath::Step* step;
- blink::xpath::LocationPath* location_path;
+%define api.namespace {xpathyy}
+%define api.parser.class {YyParser}
+%parse-param { blink::xpath::Parser* parser_ }
+
+%define api.value.type variant
+
+%left <blink::xpath::NumericOp::Opcode> kMulOp
+%left <blink::xpath::EqTestOp::Opcode> kEqOp kRelOp
+%left kPlus kMinus
+%left kOr kAnd
+%token <blink::xpath::Step::Axis> kAxisName
+%token <String> kNodeType kPI kFunctionName kLiteral
+%token <String> kVariableReference kNumber
+%token kDotDot kSlashSlash
+%token <String> kNameTest
+%token kXPathError
+
+%type <blink::Persistent<blink::xpath::LocationPath>> LocationPath
+%type <blink::Persistent<blink::xpath::LocationPath>> AbsoluteLocationPath
+%type <blink::Persistent<blink::xpath::LocationPath>> RelativeLocationPath
+%type <blink::Persistent<blink::xpath::Step>> Step
+%type <blink::xpath::Step::Axis> AxisSpecifier
+%type <blink::Persistent<blink::xpath::Step>> DescendantOrSelf
+%type <blink::Persistent<blink::xpath::Step::NodeTest>> NodeTest
+%type <blink::Persistent<blink::xpath::Expression>> Predicate
+%type <blink::Persistent<blink::HeapVector<blink::Member<blink::xpath::Predicate>>>> OptionalPredicateList
+%type <blink::Persistent<blink::HeapVector<blink::Member<blink::xpath::Predicate>>>> PredicateList
+%type <blink::Persistent<blink::xpath::Step>> AbbreviatedStep
+%type <blink::Persistent<blink::xpath::Expression>> Expr
+%type <blink::Persistent<blink::xpath::Expression>> PrimaryExpr
+%type <blink::Persistent<blink::xpath::Expression>> FunctionCall
+%type <blink::Persistent<blink::HeapVector<blink::Member<blink::xpath::Expression>>>> ArgumentList
+%type <blink::Persistent<blink::xpath::Expression>> Argument
+%type <blink::Persistent<blink::xpath::Expression>> UnionExpr
+%type <blink::Persistent<blink::xpath::Expression>> PathExpr
+%type <blink::Persistent<blink::xpath::Expression>> FilterExpr
+%type <blink::Persistent<blink::xpath::Expression>> OrExpr
+%type <blink::Persistent<blink::xpath::Expression>> AndExpr
+%type <blink::Persistent<blink::xpath::Expression>> EqualityExpr
+%type <blink::Persistent<blink::xpath::Expression>> RelationalExpr
+%type <blink::Persistent<blink::xpath::Expression>> AdditiveExpr
+%type <blink::Persistent<blink::xpath::Expression>> MultiplicativeExpr
+%type <blink::Persistent<blink::xpath::Expression>> UnaryExpr
+
+%code {
+
+static int yylex(xpathyy::YyParser::semantic_type* yylval) {
+ return blink::xpath::Parser::Current()->Lex(yylval);
}
-%{
-
-static int xpathyylex(YYSTYPE* yylval) { return blink::xpath::Parser::Current()->Lex(yylval); }
-static void xpathyyerror(void*, const char*) { }
-
-%}
+namespace xpathyy {
+void YyParser::error(const std::string&) { }
+}
-%left <num_op> MULOP
-%left <eq_op> EQOP RELOP
-%left PLUS MINUS
-%left OR AND
-%token <axis> AXISNAME
-%token <str> NODETYPE PI FUNCTIONNAME LITERAL
-%token <str> VARIABLEREFERENCE NUMBER
-%token DOTDOT SLASHSLASH
-%token <str> NAMETEST
-%token XPATH_ERROR
-
-%type <location_path> LocationPath
-%type <location_path> AbsoluteLocationPath
-%type <location_path> RelativeLocationPath
-%type <step> Step
-%type <axis> AxisSpecifier
-%type <step> DescendantOrSelf
-%type <node_test> NodeTest
-%type <expr> Predicate
-%type <pred_list> OptionalPredicateList
-%type <pred_list> PredicateList
-%type <step> AbbreviatedStep
-%type <expr> Expr
-%type <expr> PrimaryExpr
-%type <expr> FunctionCall
-%type <arg_list> ArgumentList
-%type <expr> Argument
-%type <expr> UnionExpr
-%type <expr> PathExpr
-%type <expr> FilterExpr
-%type <expr> OrExpr
-%type <expr> AndExpr
-%type <expr> EqualityExpr
-%type <expr> RelationalExpr
-%type <expr> AdditiveExpr
-%type <expr> MultiplicativeExpr
-%type <expr> UnaryExpr
+}
%%
Expr:
OrExpr
{
- parser->top_expr_ = $1;
+ parser_->top_expr_ = $1;
+ $$ = $1;
}
;
LocationPath:
RelativeLocationPath
{
+ $$ = $1;
$$->SetAbsolute(false);
}
|
AbsoluteLocationPath
{
+ $$ = $1;
$$->SetAbsolute(true);
}
;
@@ -161,11 +173,13 @@ RelativeLocationPath:
|
RelativeLocationPath '/' Step
{
+ $$ = $1;
$$->AppendStep($3);
}
|
RelativeLocationPath DescendantOrSelf Step
{
+ $$ = $1;
$$->AppendStep($2);
$$->AppendStep($3);
}
@@ -180,12 +194,12 @@ Step:
$$ = blink::MakeGarbageCollected<Step>(Step::kChildAxis, *$1);
}
|
- NAMETEST OptionalPredicateList
+ kNameTest OptionalPredicateList
{
AtomicString local_name;
AtomicString namespace_uri;
- if (!parser->ExpandQName(*$1, local_name, namespace_uri)) {
- parser->got_namespace_error_ = true;
+ if (!parser_->ExpandQName($1, local_name, namespace_uri)) {
+ parser_->got_namespace_error_ = true;
YYABORT;
}
@@ -193,7 +207,6 @@ Step:
$$ = blink::MakeGarbageCollected<Step>(Step::kChildAxis, Step::NodeTest(Step::NodeTest::kNameTest, local_name, namespace_uri), *$2);
else
$$ = blink::MakeGarbageCollected<Step>(Step::kChildAxis, Step::NodeTest(Step::NodeTest::kNameTest, local_name, namespace_uri));
- parser->DeleteString($1);
}
|
AxisSpecifier NodeTest OptionalPredicateList
@@ -204,12 +217,12 @@ Step:
$$ = blink::MakeGarbageCollected<Step>($1, *$2);
}
|
- AxisSpecifier NAMETEST OptionalPredicateList
+ AxisSpecifier kNameTest OptionalPredicateList
{
AtomicString local_name;
AtomicString namespace_uri;
- if (!parser->ExpandQName(*$2, local_name, namespace_uri)) {
- parser->got_namespace_error_ = true;
+ if (!parser_->ExpandQName($2, local_name, namespace_uri)) {
+ parser_->got_namespace_error_ = true;
YYABORT;
}
@@ -217,14 +230,13 @@ Step:
$$ = blink::MakeGarbageCollected<Step>($1, Step::NodeTest(Step::NodeTest::kNameTest, local_name, namespace_uri), *$3);
else
$$ = blink::MakeGarbageCollected<Step>($1, Step::NodeTest(Step::NodeTest::kNameTest, local_name, namespace_uri));
- parser->DeleteString($2);
}
|
AbbreviatedStep
;
AxisSpecifier:
- AXISNAME
+ kAxisName
|
'@'
{
@@ -233,29 +245,24 @@ AxisSpecifier:
;
NodeTest:
- NODETYPE '(' ')'
+ kNodeType '(' ')'
{
- if (*$1 == "node")
+ if ($1 == "node")
$$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kAnyNodeTest);
- else if (*$1 == "text")
+ else if ($1 == "text")
$$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kTextNodeTest);
- else if (*$1 == "comment")
+ else if ($1 == "comment")
$$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kCommentNodeTest);
-
- parser->DeleteString($1);
}
|
- PI '(' ')'
+ kPI '(' ')'
{
$$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kProcessingInstructionNodeTest);
- parser->DeleteString($1);
}
|
- PI '(' LITERAL ')'
+ kPI '(' kLiteral ')'
{
- $$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kProcessingInstructionNodeTest, $3->StripWhiteSpace());
- parser->DeleteString($1);
- parser->DeleteString($3);
+ $$ = blink::MakeGarbageCollected<Step::NodeTest>(Step::NodeTest::kProcessingInstructionNodeTest, $3.StripWhiteSpace());
}
;
@@ -266,6 +273,9 @@ OptionalPredicateList:
}
|
PredicateList
+ {
+ $$ = $1;
+ }
;
PredicateList:
@@ -277,6 +287,7 @@ PredicateList:
|
PredicateList Predicate
{
+ $$ = $1;
$$->push_back(blink::MakeGarbageCollected<blink::xpath::Predicate>($2));
}
;
@@ -289,7 +300,7 @@ Predicate:
;
DescendantOrSelf:
- SLASHSLASH
+ kSlashSlash
{
$$ = blink::MakeGarbageCollected<Step>(Step::kDescendantOrSelfAxis, Step::NodeTest(Step::NodeTest::kAnyNodeTest));
}
@@ -301,17 +312,16 @@ AbbreviatedStep:
$$ = blink::MakeGarbageCollected<Step>(Step::kSelfAxis, Step::NodeTest(Step::NodeTest::kAnyNodeTest));
}
|
- DOTDOT
+ kDotDot
{
$$ = blink::MakeGarbageCollected<Step>(Step::kParentAxis, Step::NodeTest(Step::NodeTest::kAnyNodeTest));
}
;
PrimaryExpr:
- VARIABLEREFERENCE
+ kVariableReference
{
- $$ = blink::MakeGarbageCollected<blink::xpath::VariableReference>(*$1);
- parser->DeleteString($1);
+ $$ = blink::MakeGarbageCollected<blink::xpath::VariableReference>($1);
}
|
'(' Expr ')'
@@ -319,36 +329,32 @@ PrimaryExpr:
$$ = $2;
}
|
- LITERAL
+ kLiteral
{
- $$ = blink::MakeGarbageCollected<blink::xpath::StringExpression>(*$1);
- parser->DeleteString($1);
+ $$ = blink::MakeGarbageCollected<blink::xpath::StringExpression>($1);
}
|
- NUMBER
+ kNumber
{
- $$ = blink::MakeGarbageCollected<blink::xpath::Number>($1->ToDouble());
- parser->DeleteString($1);
+ $$ = blink::MakeGarbageCollected<blink::xpath::Number>($1.ToDouble());
}
|
FunctionCall
;
FunctionCall:
- FUNCTIONNAME '(' ')'
+ kFunctionName '(' ')'
{
- $$ = blink::xpath::CreateFunction(*$1);
+ $$ = blink::xpath::CreateFunction($1);
if (!$$)
YYABORT;
- parser->DeleteString($1);
}
|
- FUNCTIONNAME '(' ArgumentList ')'
+ kFunctionName '(' ArgumentList ')'
{
- $$ = blink::xpath::CreateFunction(*$1, *$3);
+ $$ = blink::xpath::CreateFunction($1, *$3);
if (!$$)
YYABORT;
- parser->DeleteString($1);
}
;
@@ -361,6 +367,7 @@ ArgumentList:
|
ArgumentList ',' Argument
{
+ $$ = $1;
$$->push_back($3);
}
;
@@ -414,7 +421,7 @@ FilterExpr:
OrExpr:
AndExpr
|
- OrExpr OR AndExpr
+ OrExpr kOr AndExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::LogicalOp>(blink::xpath::LogicalOp::kOP_Or, $1, $3);
}
@@ -423,7 +430,7 @@ OrExpr:
AndExpr:
EqualityExpr
|
- AndExpr AND EqualityExpr
+ AndExpr kAnd EqualityExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::LogicalOp>(blink::xpath::LogicalOp::kOP_And, $1, $3);
}
@@ -432,7 +439,7 @@ AndExpr:
EqualityExpr:
RelationalExpr
|
- EqualityExpr EQOP RelationalExpr
+ EqualityExpr kEqOp RelationalExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::EqTestOp>($2, $1, $3);
}
@@ -441,7 +448,7 @@ EqualityExpr:
RelationalExpr:
AdditiveExpr
|
- RelationalExpr RELOP AdditiveExpr
+ RelationalExpr kRelOp AdditiveExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::EqTestOp>($2, $1, $3);
}
@@ -450,12 +457,12 @@ RelationalExpr:
AdditiveExpr:
MultiplicativeExpr
|
- AdditiveExpr PLUS MultiplicativeExpr
+ AdditiveExpr kPlus MultiplicativeExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::NumericOp>(blink::xpath::NumericOp::kOP_Add, $1, $3);
}
|
- AdditiveExpr MINUS MultiplicativeExpr
+ AdditiveExpr kMinus MultiplicativeExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::NumericOp>(blink::xpath::NumericOp::kOP_Sub, $1, $3);
}
@@ -464,7 +471,7 @@ AdditiveExpr:
MultiplicativeExpr:
UnaryExpr
|
- MultiplicativeExpr MULOP UnaryExpr
+ MultiplicativeExpr kMulOp UnaryExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::NumericOp>($2, $1, $3);
}
@@ -473,7 +480,7 @@ MultiplicativeExpr:
UnaryExpr:
UnionExpr
|
- MINUS UnaryExpr
+ kMinus UnaryExpr
{
$$ = blink::MakeGarbageCollected<blink::xpath::Negative>();
$$->AddSubExpression($2);