mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
Fix by renaming enumerants that happen to be keywords.
This fixes e.g. the compilation of capnp/schema.capnp.
This commit is contained in:
parent
1aff615036
commit
8d9c3a8b57
@ -2,8 +2,12 @@
|
|||||||
{
|
{
|
||||||
class Enumerant
|
class Enumerant
|
||||||
{
|
{
|
||||||
|
string _literal;
|
||||||
public TypeDefinition TypeDefinition { get; set; }
|
public TypeDefinition TypeDefinition { get; set; }
|
||||||
public string Literal { get; set; }
|
public string Literal {
|
||||||
|
get => _literal;
|
||||||
|
set => _literal = IdentifierRenamer.ToNonKeyword(value);
|
||||||
|
}
|
||||||
public ushort? Ordinal { get; set; }
|
public ushort? Ordinal { get; set; }
|
||||||
public int CodeOrder { get; set; }
|
public int CodeOrder { get; set; }
|
||||||
}
|
}
|
||||||
|
22
capnpc-csharp/Model/IdentifierRenamer.cs
Normal file
22
capnpc-csharp/Model/IdentifierRenamer.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CapnpC.Model
|
||||||
|
{
|
||||||
|
public class IdentifierRenamer
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user