From 14a0bcc74a121525917aefc8c9034e283e94884b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Szyde=C5=82ko?= Date: Sat, 20 May 2017 08:14:27 +0200 Subject: 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. --- src/scanner.l | 10 ++++++++ testing/066/class_class1.xml | 50 +++++++++++++++++++++++++++++++++++++ testing/066_property_initializer.cs | 7 ++++++ 3 files changed, 67 insertions(+) create mode 100644 testing/066/class_class1.xml create mode 100644 testing/066_property_initializer.cs diff --git a/src/scanner.l b/src/scanner.l index 9ff082d..632c8a5 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -6198,6 +6198,14 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) } } "{" { curlyCount++; } +"}"{B}*"=" { + // fall back to next rule if it's not the right bracket + if (curlyCount != 0) REJECT; + current->initializer = "="; + current->endBodyLine=yyLineNr; + lastInitializerContext = FindMembers; + BEGIN(ReadInitializer); + } "}" { if (curlyCount) { @@ -6207,6 +6215,8 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP}) { mtype = Method; virt = Normal; + // not really important, but while we are at it + current->endBodyLine=yyLineNr; unput(';'); BEGIN(FindMembers); } diff --git a/testing/066/class_class1.xml b/testing/066/class_class1.xml new file mode 100644 index 0000000..008bcc6 --- /dev/null +++ b/testing/066/class_class1.xml @@ -0,0 +1,50 @@ + + + + Class1 + + + int + int Class1.Property1 + + Property1 + = 1 + + + + + + + + + + string + string Class1.Property2 + + Property2 + + + + + + + + + + + + + + + + + Class1 + Property1 + + + Class1 + Property2 + + + + diff --git a/testing/066_property_initializer.cs b/testing/066_property_initializer.cs new file mode 100644 index 0000000..d5b5c59 --- /dev/null +++ b/testing/066_property_initializer.cs @@ -0,0 +1,7 @@ +// objective: C# property initializer +// check: class_class1.xml +class Class1 +{ + public int Property1 { get; } = 1; + public string Property2 { get; set; } +} -- cgit v0.12