使用 'keys' 作为规则元素标签
Use 'keys' as rule element label
在我的项目中,我编写了一种用于处理键值对的语言。所以我有一些规则来匹配多个键 keysList
和一个值 valuesList
。现在我想在另一个规则中使用它们
operationExpression
: keysList CompareOperator valuesList
;
效果很好。
我认为将这些规则元素命名为 keys
和 values
会很好
operationExpression
: keys=keysList CompareOperator values=valueList
;
当我现在尝试编译我的项目时,我遇到了一千个抱怨缺少分号的错误。当我查看生成的代码时,我发现 Antlr 为这些上下文提供了奇怪的名称。我希望它们是 keys
和 values
但它们似乎是每个 C# 关键字(并且值之间有一些 @s)。
public KeysListContext structexterndoushortfloatwhileoperatorrefprotectedreadonlycontinueelsecheckedlockcatchifcasenewusingstaticvoidinsizeofbytedoublesealedfinallythisuncheckedisparamsenumexplicitasnulltruefixedtrydecimalobjectimplicitinternalprivatevirtualboolconststringforinterfaceunsafelongoutswitchdelegateforeachdefaultulonggotopublicstackallocoverrideeventclasstypeofbreakfalsevolatileabstractuintintthrowcharnamespacesbyteshortreturnbase;
public ValuesListContext @struct@extern@do@ushort@float@while@operator@ref@protected@readonly@continue@else@checked@lock@catch@if@case@new@using@static@void@in@sizeof@byte@double@sealed@finally@this@unchecked@is@params@enum@explicit@as@null@true@fixed@try@decimal@object@implicit@internal@private@virtual@bool@const@string@for@interface@unsafe@long@out@switch@delegate@foreachkey@ulong@goto@public@stackalloc@override@event@class@typeof@break@false@volatile@abstract@uint@int@throw@char@namespace@sbyte@short@return@base;
其他名字似乎都可以。为什么 Antlr 这样做以及为什么我不允许使用 keys
和 values
作为规则元素标签?
我想这是告诉您您使用保留关键字作为标签名称的一种方式。由于您已经发现其他名称也可以正常工作,因此请改用与您的语言的保留字不冲突的名称。
这是一个错误:Issue 1125。
似乎在某处有一张地图,其中用户定义的标识符可能会与地图中已经存在的某些键(包括 keys
和 values
)发生冲突。
因此,在等待错误修复期间,您必须使用不同的名称。
在我的项目中,我编写了一种用于处理键值对的语言。所以我有一些规则来匹配多个键 keysList
和一个值 valuesList
。现在我想在另一个规则中使用它们
operationExpression
: keysList CompareOperator valuesList
;
效果很好。
我认为将这些规则元素命名为 keys
和 values
operationExpression
: keys=keysList CompareOperator values=valueList
;
当我现在尝试编译我的项目时,我遇到了一千个抱怨缺少分号的错误。当我查看生成的代码时,我发现 Antlr 为这些上下文提供了奇怪的名称。我希望它们是 keys
和 values
但它们似乎是每个 C# 关键字(并且值之间有一些 @s)。
public KeysListContext structexterndoushortfloatwhileoperatorrefprotectedreadonlycontinueelsecheckedlockcatchifcasenewusingstaticvoidinsizeofbytedoublesealedfinallythisuncheckedisparamsenumexplicitasnulltruefixedtrydecimalobjectimplicitinternalprivatevirtualboolconststringforinterfaceunsafelongoutswitchdelegateforeachdefaultulonggotopublicstackallocoverrideeventclasstypeofbreakfalsevolatileabstractuintintthrowcharnamespacesbyteshortreturnbase;
public ValuesListContext @struct@extern@do@ushort@float@while@operator@ref@protected@readonly@continue@else@checked@lock@catch@if@case@new@using@static@void@in@sizeof@byte@double@sealed@finally@this@unchecked@is@params@enum@explicit@as@null@true@fixed@try@decimal@object@implicit@internal@private@virtual@bool@const@string@for@interface@unsafe@long@out@switch@delegate@foreachkey@ulong@goto@public@stackalloc@override@event@class@typeof@break@false@volatile@abstract@uint@int@throw@char@namespace@sbyte@short@return@base;
其他名字似乎都可以。为什么 Antlr 这样做以及为什么我不允许使用 keys
和 values
作为规则元素标签?
我想这是告诉您您使用保留关键字作为标签名称的一种方式。由于您已经发现其他名称也可以正常工作,因此请改用与您的语言的保留字不冲突的名称。
这是一个错误:Issue 1125。
似乎在某处有一张地图,其中用户定义的标识符可能会与地图中已经存在的某些键(包括 keys
和 values
)发生冲突。
因此,在等待错误修复期间,您必须使用不同的名称。