Skip to content

Commit 29ece43

Browse files
committed
fix c grammar for wide string literals
It seems to me that it's impossible to parse wide string literals using c.peg. (i.e. L"foo"). The issue appears to be that the "L" will be captured by the Identifier subrule in PrimaryExpression before StringLiteral can capture it. My fix is to reorder these subrules, putting StringLiteral before Identifier.
1 parent 984ba86 commit 29ece43

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

grammars/c/c.peg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ JumpStatement
313313
#-------------------------------------------------------------------------
314314

315315
PrimaryExpression
316-
<- Identifier
316+
<- StringLiteral
317317
/ Constant
318-
/ StringLiteral
318+
/ Identifier
319319
/ LPAR Expression RPAR
320320

321321
PostfixExpression

grammars/c/c_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,7 @@ func TestCParsing_Long(t *testing.T) {
202202
}
203203
walk("c/")
204204
}
205+
206+
func TestCParsing_WideString(t *testing.T) {
207+
parseC_4t(t, `wchar_t *msg = L"Hello";`);
208+
}

0 commit comments

Comments
 (0)