Skip to content

Commit bc9715b

Browse files
committed
Add C/C++ literal char encoding prefixes
1 parent c9f0014 commit bc9715b

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎src/parser/TextLexer.g‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ NAME options { testLiterals = true; } :
151151
{ text == "L"sv || text == "U"sv || text == "u"sv || text == "u8"sv }?
152152
{ $setType(STRING_START); } STRING_START |
153153

154+
{ (inLanguage(LANGUAGE_C) || inLanguage(LANGUAGE_CXX))
155+
&& (text == "L"sv || text == "U"sv || text == "u"sv || text == "u8"sv) }?
156+
{ $setType(CHAR_START); } CHAR_START |
157+
154158
{ inLanguage(LANGUAGE_CXX) && (text == "R"sv || text == "u8R"sv || text == "LR"sv || text == "UR"sv || text == "uR"sv) }?
155159
{ $setType(STRING_START); } RAW_STRING_START |
156160

‎test/parser/testsuite/expression_c.c.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,20 @@
2525
<expr_stmt><expr><call><name>a</name><argument_list>(<argument><expr><call><call><name>b</name><argument_list>()</argument_list></call><argument_list>()</argument_list></call></expr></argument>)</argument_list></call></expr>;</expr_stmt>
2626
</unit>
2727

28+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C">
29+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">L'x'</literal></expr>;</expr_stmt>
30+
</unit>
31+
32+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C">
33+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">u'x'</literal></expr>;</expr_stmt>
34+
</unit>
35+
36+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C">
37+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">U'x'</literal></expr>;</expr_stmt>
38+
</unit>
39+
40+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C">
41+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">u8'x'</literal></expr>;</expr_stmt>
42+
</unit>
43+
2844
</unit>

‎test/parser/testsuite/literal_cpp.cpp.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
<expr_stmt><expr><literal type="string">U"This is a UTF-32 string."</literal></expr>;</expr_stmt>
2222
</unit>
2323

24+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++">
25+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">L'x'</literal></expr>;</expr_stmt>
26+
</unit>
27+
28+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++">
29+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">u'x'</literal></expr>;</expr_stmt>
30+
</unit>
31+
32+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++">
33+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">U'x'</literal></expr>;</expr_stmt>
34+
</unit>
35+
36+
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++">
37+
<expr_stmt><expr><name>c</name> <operator>=</operator> <literal type="char">u8'x'</literal></expr>;</expr_stmt>
38+
</unit>
39+
2440
<unit xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++">
2541
<expr_stmt><expr><literal type="string">R"()"</literal></expr>;</expr_stmt>
2642
</unit>

0 commit comments

Comments
 (0)