这是什么一个叹号YAML吗? [英] What does a single exclamation mark do in YAML?

查看:1605
本文介绍了这是什么一个叹号YAML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与 YamlDotNet 图书馆,我加载YAML文件时,收到此错误:

  

在解析一个标记,没有找到预期的标签URI。

在YAML文件应该是良好的,因为它涉及直接从回报率。错误似乎是由这个code触发:

 格式:
  默认: ! %D-%M-%Y'
  长: ! %D%B,%Y'
  短: ! %D%B'
 

我不是专家,但我从YAML规范,您可以使用感叹号,表示自定义对象/类型看,和两个感叹号,表明一个明确的内置式。

  OBJ1:自定义#什么
OBJ2:!! STR我的字符串
 

不过,我一直没能找到任何提及作为上述感叹号。这是什么意思,为什么YAML库我使用似乎并没有能够解析呢?需要注意的是,如果我删除这些感叹号,将解析该文件的罚款。

解决方案

这!是非特异性标签。

YAML规范1.2 住宿(也的 1.1 ):

  

通过明确地指定一个!非特定标签属性,节点   将被解析为一个香草的序列,映射,或字符串,   从其类。

看看这里标签语法:

 无:未指定标签(由应用程序自动解决)。
! :非特异性标记(默认情况下,!!图/!序列/!!海峡)。
'富!:主(按照惯例,这意味着一个局部变量富!)。
'!!富':中学(按照惯例,意思是标签:yaml.org,2002:富)。
!^ h富':需要%TAG H< preFIX>! (然后表示< preFIX>富)。
!<富>':威宝标签(通常意味着富)。
 

为什么YamlDotNet抛出一个错误?我不能100%肯定,但我认为你发现了一个bug。

YamlDotNet是 LibYAML 的端口,所以很容易进行比较的来源。

scanner.c 2635线(LibYAML):

  / *检查标签非空。 * /
如果(!长){
 

Scanner.cs 2146线(YamlDotNet):

  //检查标签非空。
如果(tag.Length == 0)
 

我知道,这两个看起来非常相似,但在这一点长度 1和 tag.Length 0 。原来的C code照顾最初的! (全长),但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".

YAML specification 1.2 stays (also 1.1):

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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆