问题描述
我正在使用 YamlDotNet 库,但在加载 YAML 文件时出现此错误:
<块引用>解析标签时,未找到预期的标签 URI.
YAML 文件应该格式正确,因为它来自 就在 RoR.错误似乎是由这段代码触发的:
格式:默认: !'%d-%m-%Y'长: !%d %B, %Y"短的: !'%D b'
我不是专家,但我从 YAML 规范中看到,您可以使用感叹号表示自定义对象/类型,使用两个感叹号表示明确的内置类型.
obj1: !custom # 不管obj2: !!str "我的字符串"
但是,我无法找到对上述使用的感叹号的任何引用.这是什么意思,为什么我使用的 YAML 库似乎无法解析它?请注意,如果我删除了这些感叹号,则该文件被解析得很好.
那个!
是非特定标签.
YAML 规范 1.2(以及之前的 1.1) 说:
<块引用>通过明确指定!"非特定标签属性,节点然后将被解析为香草"序列、映射或字符串,各从其类.
查看这里标签语法":
<块引用>none :未指定的标签(由应用程序自动解析).'!': 非特定标签(默认情况下,!!map"/!!seq"/!!str").'!foo' :主要的(按照惯例,表示本地的!foo"标签).'!!foo' :次要的(按照惯例,表示tag:yaml.org,2002:foo").'!h!foo': 需要 "%TAG !h!<前缀>"(然后表示<prefix>foo").'!':逐字标记(始终表示foo").
为什么 YamlDotNet 会抛出错误?我不能 100% 确定,但我认为你发现了一个错误.
YamlDotNet 是 LibYAML 的端口,因此很容易比较来源.
scanner.c (LibYAML) 的第 2635 行:
/* 检查标签是否为非空.*/如果(!长度){
Scanner.cs (YamlDotNet) 的第 2146 行:
//检查标签是否为非空.if (tag.Length == 0)
我知道,两者看起来非常相似,但此时 length
为 1,tag.Length
为 0.原始 C 代码负责初始的!"(全长)但 C# 不这样做(只是标签名称"长度).
向项目提交问题.
I'm working with the YamlDotNet library and I'm getting this error when loading a YAML file:
While parsing a tag, did not find expected tag URI.
The YAML file is supposed to be well-formed because it comes right from RoR. The error seems to be triggered by this code:
formats:
default: ! '%d-%m-%Y'
long: ! '%d %B, %Y'
short: ! '%d %b'
I'm not an expert, but I see from the YAML spec that you can use an exclamation mark to indicate a custom object/type, and two exclamation marks to indicate an explicit built-in type.
obj1: !custom # whatever
obj2: !!str "My string"
However I haven't been able to find any reference to an exclamation mark used as above. What does that mean, and why the YAML library I use doesn't seem able to parse it? Note that if I remove those exclamation marks, the file is parsed fine.
That !
is the non-specific tag.
The YAML specification 1.2 (as well as the previous 1.1) says that :
By explicitly specifying a "!" non-specific tag property, the node would then be resolved to a "vanilla" sequence, mapping, or string, according to its kind.
Take a look here to the tag "grammar":
none : Unspecified tag (automatically resolved by application). '!' : Non-specific tag (by default, "!!map"/"!!seq"/"!!str"). '!foo' : Primary (by convention, means a local "!foo" tag). '!!foo' : Secondary (by convention, means "tag:yaml.org,2002:foo"). '!h!foo': Requires "%TAG !h! <prefix>" (and then means "<prefix>foo"). '!<foo>': Verbatim tag (always means "foo").
Why is YamlDotNet throwing a error? I can't be 100% sure, but I think you found a bug.
YamlDotNet is a port of LibYAML, so it's easy to compare sources.
Line 2635 of scanner.c (LibYAML):
/* Check if the tag is non-empty. */
if (!length) {
Line 2146 of Scanner.cs (YamlDotNet ):
// Check if the tag is non-empty.
if (tag.Length == 0)
I know, both looks very similar, but at this point length
is 1 and tag.Length
is 0. Original C code takes care of the initial "!" (whole length) but C# doesn't do it (just the tag "name" length).
File an issue to the project.
这篇关于YAML 中的单个感叹号有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!