Skip to content

Commit 3be4488

Browse files
committed
Fixed the string literal issue, #5.
Updated Sprache to the stable version.
1 parent b69a8e9 commit 3be4488

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

ApexParser/ApexParser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.9.0" />
9-
<PackageReference Include="Sprache" Version="2.1.3-develop-00021" />
9+
<PackageReference Include="Sprache" Version="2.2.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

ApexParser/Visitors/CSharpCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public override void VisitExpression(ExpressionSyntax node)
494494
}
495495

496496
protected override void AppendStringLiteral(string literal) =>
497-
Append("\"{0}\"", literal.Substring(1, literal.Length - 2));
497+
Append("\"{0}\"", literal.Substring(1, literal.Length - 2).Replace("\"", "\\\""));
498498

499499
protected override void AppendSoqlQuery(string soqlQuery)
500500
{

ApexParserTest/ApexParserTest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
<Reference Include="RestSharp, Version=106.5.2.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
5757
<HintPath>..\packages\RestSharp.106.5.2\lib\net452\RestSharp.dll</HintPath>
5858
</Reference>
59-
<Reference Include="Sprache, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
60-
<HintPath>..\packages\Sprache.2.1.3-develop-00021\lib\net45\Sprache.dll</HintPath>
59+
<Reference Include="Sprache, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
60+
<HintPath>..\packages\Sprache.2.2.0\lib\net45\Sprache.dll</HintPath>
6161
</Reference>
6262
<Reference Include="System" />
6363
<Reference Include="System.AppContext">

ApexParserTest/Visitors/CSharpGeneratorTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ public void T()
14311431
}");
14321432
}
14331433

1434-
[TestCase]
1434+
[Test]
14351435
public void LocalizeSObjectsNamespaceIgnoresInvalidParameters()
14361436
{
14371437
Func<IEnumerable<string>, string, IEnumerable<string>> loc = CSharpCodeGenerator.LocalizeSObjectNamespace;
@@ -1442,7 +1442,7 @@ public void LocalizeSObjectsNamespaceIgnoresInvalidParameters()
14421442
Assert.AreEqual(new[] { "SObjects" }, loc(new[] { "SObjects" }, null));
14431443
}
14441444

1445-
[TestCase]
1445+
[Test]
14461446
public void LocalizeSObjectsNamespaceAppendsTheFirstPartOfTheNamespaceBeforeTheSObjectsConstant()
14471447
{
14481448
Func<IEnumerable<string>, string, IEnumerable<string>> loc = CSharpCodeGenerator.LocalizeSObjectNamespace;
@@ -1453,5 +1453,24 @@ public void LocalizeSObjectsNamespaceAppendsTheFirstPartOfTheNamespaceBeforeTheS
14531453
Assert.AreEqual(new[] { "Something", "Hello.SObjects" }, loc(new[] { "Something", "SObjects" }, "Hello"));
14541454
Assert.AreEqual(new[] { "Something", "Hello.SObjects" }, loc(new[] { "Something", "SObjects" }, "Hello.There"));
14551455
}
1456+
1457+
[Test]
1458+
public void StringLiteralsShouldEscapeTheDoubleQuotes()
1459+
{
1460+
var decl = new VariableDeclarationSyntax
1461+
{
1462+
Type = new TypeSyntax("string"),
1463+
Variables = new List<VariableDeclaratorSyntax>
1464+
{
1465+
new VariableDeclaratorSyntax
1466+
{
1467+
Identifier = "json",
1468+
Expression = new ExpressionSyntax("'{ name: \"value\" }'")
1469+
}
1470+
}
1471+
};
1472+
1473+
Check(decl, @"string json = ""{ name: \""value\"" }"";");
1474+
}
14561475
}
14571476
}

ApexParserTest/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.CodeAnalysis.CSharp" version="2.9.0" targetFramework="net462" />
66
<package id="NUnit" version="3.11.0" targetFramework="net462" />
77
<package id="RestSharp" version="106.5.2" targetFramework="net462" />
8-
<package id="Sprache" version="2.1.3-develop-00021" targetFramework="net462" />
8+
<package id="Sprache" version="2.2.0" targetFramework="net462" />
99
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
1010
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
1111
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />

Playground/Playground.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</PropertyGroup>
3838
<ItemGroup>
3939
<Reference Include="ApexParser, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
40-
<HintPath>..\packages\ApexParser.0.6.8\lib\netstandard2.0\ApexParser.dll</HintPath>
40+
<HintPath>..\packages\ApexParser.0.6.10\lib\netstandard2.0\ApexParser.dll</HintPath>
4141
</Reference>
4242
<Reference Include="FastColoredTextBox, Version=2.16.21.0, Culture=neutral, PublicKeyToken=fb8aa12b994ef61b, processorArchitecture=MSIL">
4343
<HintPath>..\packages\FCTB.2.16.21.0\lib\FastColoredTextBox.dll</HintPath>
@@ -48,8 +48,8 @@
4848
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4949
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.9.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
5050
</Reference>
51-
<Reference Include="Sprache, Version=2.1.3.0, Culture=neutral, processorArchitecture=MSIL">
52-
<HintPath>..\packages\Sprache.2.1.3-develop-00021\lib\net45\Sprache.dll</HintPath>
51+
<Reference Include="Sprache, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Sprache.2.2.0\lib\net45\Sprache.dll</HintPath>
5353
</Reference>
5454
<Reference Include="System" />
5555
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

Playground/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="ApexParser" version="0.6.8" targetFramework="net461" />
3+
<package id="ApexParser" version="0.6.10" targetFramework="net461" />
44
<package id="FCTB" version="2.16.21.0" targetFramework="net462" />
55
<package id="Microsoft.CodeAnalysis.Analyzers" version="2.6.2" targetFramework="net461" developmentDependency="true" />
66
<package id="Microsoft.CodeAnalysis.Common" version="2.9.0" targetFramework="net461" />
77
<package id="Microsoft.CodeAnalysis.CSharp" version="2.9.0" targetFramework="net461" />
8-
<package id="Sprache" version="2.1.3-develop-00021" targetFramework="net461" />
8+
<package id="Sprache" version="2.2.0" targetFramework="net461" />
99
<package id="System.AppContext" version="4.3.0" targetFramework="net461" />
1010
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
1111
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />

0 commit comments

Comments
 (0)