Skip to content

Commit 14a0bcc

Browse files
committed
Fix C# property initializer parsing
int Property {get; set;} = 23; The parser was ending the property at the closing bracket, which resulted in the initializer being assigned to the following property.
1 parent 88ff6e5 commit 14a0bcc

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/scanner.l

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6198,6 +6198,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
61986198
}
61996199
}
62006200
<CSAccessorDecl>"{" { curlyCount++; }
6201+
<CSAccessorDecl>"}"{B}*"=" {
6202+
// fall back to next rule if it's not the right bracket
6203+
if (curlyCount != 0) REJECT;
6204+
current->initializer = "=";
6205+
current->endBodyLine=yyLineNr;
6206+
lastInitializerContext = FindMembers;
6207+
BEGIN(ReadInitializer);
6208+
}
62016209
<CSAccessorDecl>"}" {
62026210
if (curlyCount)
62036211
{
@@ -6207,6 +6215,8 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
62076215
{
62086216
mtype = Method;
62096217
virt = Normal;
6218+
// not really important, but while we are at it
6219+
current->endBodyLine=yyLineNr;
62106220
unput(';');
62116221
BEGIN(FindMembers);
62126222
}

testing/066/class_class1.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
3+
<compounddef id="class_class1" kind="class" language="C#" prot="public">
4+
<compoundname>Class1</compoundname>
5+
<sectiondef kind="property">
6+
<memberdef kind="property" id="class_class1_1a6b0b2ab73516e37adb38b8ff33f97c40" prot="public" static="no" readable="no" writable="no" gettable="yes" privategettable="no" protectedgettable="no" settable="no" privatesettable="no" protectedsettable="no">
7+
<type>int</type>
8+
<definition>int Class1.Property1</definition>
9+
<argsstring/>
10+
<name>Property1</name>
11+
<initializer>= 1</initializer>
12+
<briefdescription>
13+
</briefdescription>
14+
<detaileddescription>
15+
</detaileddescription>
16+
<inbodydescription>
17+
</inbodydescription>
18+
<location file="066_property_initializer.cs" line="5" column="1" bodyfile="066_property_initializer.cs" bodystart="5" bodyend="5"/>
19+
</memberdef>
20+
<memberdef kind="property" id="class_class1_1a0d5b843d48ebc2c078e003d6ff3a1610" prot="public" static="no" readable="no" writable="no" gettable="yes" privategettable="no" protectedgettable="no" settable="yes" privatesettable="no" protectedsettable="no">
21+
<type>string</type>
22+
<definition>string Class1.Property2</definition>
23+
<argsstring/>
24+
<name>Property2</name>
25+
<briefdescription>
26+
</briefdescription>
27+
<detaileddescription>
28+
</detaileddescription>
29+
<inbodydescription>
30+
</inbodydescription>
31+
<location file="066_property_initializer.cs" line="6" column="1" bodyfile="066_property_initializer.cs" bodystart="6" bodyend="6"/>
32+
</memberdef>
33+
</sectiondef>
34+
<briefdescription>
35+
</briefdescription>
36+
<detaileddescription>
37+
</detaileddescription>
38+
<location file="066_property_initializer.cs" line="4" column="1" bodyfile="066_property_initializer.cs" bodystart="3" bodyend="7"/>
39+
<listofallmembers>
40+
<member refid="class_class1_1a6b0b2ab73516e37adb38b8ff33f97c40" prot="public" virt="non-virtual">
41+
<scope>Class1</scope>
42+
<name>Property1</name>
43+
</member>
44+
<member refid="class_class1_1a0d5b843d48ebc2c078e003d6ff3a1610" prot="public" virt="non-virtual">
45+
<scope>Class1</scope>
46+
<name>Property2</name>
47+
</member>
48+
</listofallmembers>
49+
</compounddef>
50+
</doxygen>

testing/066_property_initializer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// objective: C# property initializer
2+
// check: class_class1.xml
3+
class Class1
4+
{
5+
public int Property1 { get; } = 1;
6+
public string Property2 { get; set; }
7+
}

0 commit comments

Comments
 (0)