aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-10-12 14:43:38 +0200
committerLars Knoll <lars.knoll@qt.io>2018-11-02 18:44:01 +0000
commit4241ce2cfc624ae51ac911c11d065fc703dfadc5 (patch)
treedc38661d25230519dbdafa48d2a918c8f95c8e02 /src/qml/parser
parent31a9acd0348750e60feda9bdee07afc7511a6be7 (diff)
Pass the raw string value to template literals
They are required for spec compliance of tagged templates. Change-Id: I8ef8e2314843f07a02d204394400f3f3894f8f91 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r--src/qml/parser/qqmljs.g19
-rw-r--r--src/qml/parser/qqmljsast_p.h5
2 files changed, 20 insertions, 4 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index a7ae664d72..6549e5bfa3 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -392,6 +392,9 @@ protected:
inline QStringRef &stringRef(int index)
{ return string_stack [tos + index - 1]; }
+ inline QStringRef &rawStringRef(int index)
+ { return rawString_stack [tos + index - 1]; }
+
inline AST::SourceLocation &loc(int index)
{ return location_stack [tos + index - 1]; }
@@ -416,6 +419,7 @@ protected:
int *state_stack = nullptr;
AST::SourceLocation *location_stack = nullptr;
QVector<QStringRef> string_stack;
+ QVector<QStringRef> rawString_stack;
AST::Node *program = nullptr;
@@ -427,11 +431,13 @@ protected:
double dval;
AST::SourceLocation loc;
QStringRef spell;
+ QStringRef raw;
};
int yytoken = -1;
double yylval = 0.;
QStringRef yytokenspell;
+ QStringRef yytokenraw;
AST::SourceLocation yylloc;
AST::SourceLocation yyprevlloc;
@@ -493,6 +499,7 @@ void Parser::reallocateStack()
state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (realloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
string_stack.resize(stack_size);
+ rawString_stack.resize(stack_size);
}
Parser::Parser(Engine *engine):
@@ -555,6 +562,7 @@ void Parser::pushToken(int token)
last_token->token = yytoken;
last_token->dval = yylval;
last_token->spell = yytokenspell;
+ last_token->raw = yytokenraw;
last_token->loc = yylloc;
++last_token;
yytoken = token;
@@ -566,6 +574,7 @@ int Parser::lookaheadToken(Lexer *lexer)
yytoken = lexer->lex();
yylval = lexer->tokenValue();
yytokenspell = lexer->tokenSpell();
+ yytokenraw = lexer->rawString();
yylloc = location(lexer);
}
return yytoken;
@@ -618,11 +627,13 @@ bool Parser::parse(int startToken)
yytoken = lexer->lex();
yylval = lexer->tokenValue();
yytokenspell = lexer->tokenSpell();
+ yytokenraw = lexer->rawString();
yylloc = location(lexer);
} else {
yytoken = first_token->token;
yylval = first_token->dval;
yytokenspell = first_token->spell;
+ yytokenraw = first_token->raw;
yylloc = first_token->loc;
++first_token;
if (first_token == last_token)
@@ -643,6 +654,7 @@ bool Parser::parse(int startToken)
yytoken = -1;
sym(1).dval = yylval;
stringRef(1) = yytokenspell;
+ rawStringRef(1) = yytokenraw;
loc(1) = yylloc;
} else {
--tos;
@@ -1889,7 +1901,7 @@ TemplateLiteral: T_NO_SUBSTITUTION_TEMPLATE;
TemplateSpans: T_TEMPLATE_TAIL;
/.
case $rule_number: {
- AST::TemplateLiteral *node = new (pool) AST::TemplateLiteral(stringRef(1), nullptr);
+ AST::TemplateLiteral *node = new (pool) AST::TemplateLiteral(stringRef(1), rawStringRef(1), nullptr);
node->literalToken = loc(1);
sym(1).Node = node;
} break;
@@ -1901,7 +1913,7 @@ TemplateSpans: T_TEMPLATE_MIDDLE Expression TemplateSpans;
TemplateLiteral: T_TEMPLATE_HEAD Expression TemplateSpans;
/.
case $rule_number: {
- AST::TemplateLiteral *node = new (pool) AST::TemplateLiteral(stringRef(1), sym(2).Expression);
+ AST::TemplateLiteral *node = new (pool) AST::TemplateLiteral(stringRef(1), rawStringRef(1), sym(2).Expression);
node->next = sym(3).Template;
node->literalToken = loc(1);
sym(1).Node = node;
@@ -4354,6 +4366,7 @@ ExportSpecifier: IdentifierName T_AS IdentifierName;
tk.token = yytoken;
tk.dval = yylval;
tk.spell = yytokenspell;
+ tk.raw = yytokenraw;
tk.loc = yylloc;
yylloc = yyprevlloc;
@@ -4380,11 +4393,13 @@ ExportSpecifier: IdentifierName T_AS IdentifierName;
token_buffer[0].token = yytoken;
token_buffer[0].dval = yylval;
token_buffer[0].spell = yytokenspell;
+ token_buffer[0].raw = yytokenraw;
token_buffer[0].loc = yylloc;
token_buffer[1].token = yytoken = lexer->lex();
token_buffer[1].dval = yylval = lexer->tokenValue();
token_buffer[1].spell = yytokenspell = lexer->tokenSpell();
+ token_buffer[1].raw = yytokenraw = lexer->rawString();
token_buffer[1].loc = yylloc = location(lexer);
if (t_action(errorState, yytoken)) {
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 72c47cbe32..43aeec6525 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -500,8 +500,8 @@ class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression
public:
QQMLJS_DECLARE_AST_NODE(TemplateLiteral)
- TemplateLiteral(const QStringRef &str, ExpressionNode *e)
- : value(str), expression(e), next(nullptr)
+ TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e)
+ : value(str), rawValue(raw), expression(e), next(nullptr)
{ kind = K; }
SourceLocation firstSourceLocation() const override
@@ -513,6 +513,7 @@ public:
void accept0(Visitor *visitor) override;
QStringRef value;
+ QStringRef rawValue;
ExpressionNode *expression;
TemplateLiteral *next;
SourceLocation literalToken;