Re: Autodetection of primitive scalar types: does YAML provide this or not?
Ingy dot Net <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <CAHJtQJ5RAJ=yu+LUa-cWhvPaJkiWxQevAusL1gdtFvfNLzHp1Q@mail.gmail.com> |
It is important to understand that YAML processing is a stack of layers or processing, between YAML serialization text and native language vm's in-memory object graphs. There is conceptually a Load stack and a Dump stack. See http://www.yaml.org/spec/1.2/spec.html#id2762107 libyaml only implements the lowest layers: parser and emitter, which convert between yaml text and events. It is not even correct to say that libyaml produces strings vs numbers, bools etc. In say, Python or Perl or whatever, type resolution and transformation to/from a usable String object in the target language, is done at levels above libyaml. libyaml deals with event structs the contain all the information needed to do type resolution. It is really up to the implementation to decide how resolution is handled for its purposes. In a generic language Loader/Dumper implementation, we suggest the default to be the same as JSON, ie Str, Bool, Num, Null. libyaml sounds perfect for your Fortran use case, but it is a low level API. You'll need to implement the other layers yourself. Look at PyYaml for a decent reference implementation. In real life you don't have to implement every layer distinctly to make a loader/dumper. It's only really useful if you plan to expose all the layers in an API. Hope that helps. On Sun, Jul 3, 2011 at 1:49 PM, Neil Carlson <[email protected]>wrote: > I essentially asked this question in a post from a week or so ago > (Basic question about scalar types and libyaml) but only got one > response which confirmed my findings that libyaml returns all data > as strings, leaving it up to the user to figure out whether it's an int, > double, etc. > > The wikipedia page on YAML (for what it's worth) suggests that > simple types (int, float, bool, string) should be auto-detected > by a YAML parser, so that an explicit type tag is not required. > > Is this incorrect? Is it something new to the 1.2 spec (libyaml > says it is 1.1)? Is this only available from other parsers for other > languages? I'd *greatly* appreciate someone cluing me into > what the situation is -- I'm looking at YAML for the first time and > am very confused. > > I'm looking for a C parser (not C++) that I can use as the base > for a Fortran library. Since I sent the first email I've created > Fortran bindings for the yajl JSON library and it works well, but > the YAML file format sounds like it will be *much* better suited > for my purposes (scientific code input format). > > Thanks in advance for your comments, > > -Neil > > > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2d-c2 > _______________________________________________ > Yaml-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/yaml-core > > ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2 _______________________________________________ Yaml-core mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/yaml-core