2019-09-06 19:25:54 +02:00
|
|
|
|
using Microsoft.CodeAnalysis.CSharp;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace CapnpC.CSharp.Generator.Model
|
|
|
|
|
{
|
2020-04-25 15:52:58 +02:00
|
|
|
|
class IdentifierRenamer
|
2019-09-06 19:25:54 +02:00
|
|
|
|
{
|
|
|
|
|
public static bool IsAnyKeyword(string str)
|
|
|
|
|
{
|
|
|
|
|
return SyntaxFacts.GetKeywordKind(str) != SyntaxKind.None
|
|
|
|
|
|| SyntaxFacts.GetContextualKeywordKind(str) != SyntaxKind.None;
|
|
|
|
|
}
|
|
|
|
|
public static string ToNonKeyword(string str)
|
|
|
|
|
{
|
|
|
|
|
// Capnp schema identifiers should be already valid, but could be a keyword
|
|
|
|
|
if (IsAnyKeyword(str)) return $"@{str}";
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|