Commit dc7b6ca6 authored by Francois Ferrand's avatar Francois Ferrand
Browse files

C++: fix lexing POUND_POUND token with digraphs.



Change-Id: I9204b827c60b283cc4e6b88c810b31eb7587c7db
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 41b23296
......@@ -263,8 +263,8 @@ void Lexer::scan_helper(Token *tok)
case '#':
if (_yychar == '#') {
tok->f.kind = T_POUND_POUND;
yyinp();
tok->f.kind = T_POUND_POUND;
} else {
tok->f.kind = T_POUND;
}
......@@ -515,7 +515,13 @@ void Lexer::scan_helper(Token *tok)
tok->f.kind = T_RBRACE;
} else if (_yychar == ':') {
yyinp();
tok->f.kind = T_POUND;
if (_yychar == '%' && *(_currentChar + 1) == ':') {
yyinp();
yyinp();
tok->f.kind = T_POUND_POUND;
} else {
tok->f.kind = T_POUND;
}
} else {
tok->f.kind = T_PERCENT;
}
......
......@@ -70,6 +70,8 @@ private slots:
void literals_data();
void preprocessor();
void preprocessor_data();
void digraph();
void digraph_data();
void trigraph();
void trigraph_data();
......@@ -740,6 +742,36 @@ void tst_SimpleLexer::incremental_data()
<< (TokenKindList() << T_IDENTIFIER);
}
void tst_SimpleLexer::digraph()
{
QFETCH(QByteArray, source);
QFETCH(TokenKindList, expectedTokenKindList);
run(source, toTokens(expectedTokenKindList), false, CompareKind);
}
void tst_SimpleLexer::digraph_data()
{
QTest::addColumn<QByteArray>("source");
QTest::addColumn<TokenKindList>("expectedTokenKindList");
QTest::newRow("lbracket_digraph") << _("<:") << (TokenKindList() << T_LBRACKET);
QTest::newRow("rbracket_digraph") << _(":>") << (TokenKindList() << T_RBRACKET);
QTest::newRow("lbrace_digraph") << _("<%") << (TokenKindList() << T_LBRACE);
QTest::newRow("rbrace_digraph") << _("%>") << (TokenKindList() << T_RBRACE);
QTest::newRow("pound_digraph") << _("%:") << (TokenKindList() << T_POUND);
QTest::newRow("pound_pound_digraph") << _("%:%:") << (TokenKindList() << T_POUND_POUND);
QTest::newRow("pound_pound_mixed_digraph_1") << _("#%:") << (TokenKindList() << T_POUND << T_POUND);
QTest::newRow("pound_pound_mixed_digraph_2") << _("%:#") << (TokenKindList() << T_POUND << T_POUND);
}
void tst_SimpleLexer::trigraph()
{
QFETCH(QByteArray, source);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment