TRANS | 1 Mar 2006 03:22
Picon
Gravatar

Types Making YAML whole unto itself

Thinking about YAML types, wondering how they fit in a wholistic sense
of YAML. Types seem foreign in a way, being defined "out there". So I
was wondering if they could be brough "inside" somehow. In other
words, could it be possible to use YAML to define a type? Well you
sort of see it with Kwaify, albiet that defines a schema for a
document. But surely it could also do the same for just a bit of a
document? So I try this example:

    ---
    customer: !type
      type:       map
      mapping:
        name:
          type:      str
          required:  yes
        email:
          type:      str
          pattern:   / <at> /
        age:
          type:      int
        birth:
          type:      date

    customer1: !customer
      name:  John Doe
      email: john@...
      age:   31
      birth: 1974-10-10

Make senses, but there is a problem here with the name customer being
(Continue reading)

Gustavo Rahal | 1 Mar 2006 05:07

error loading app

Hi

I just starting using yaml3000 and the app on windows runs fine.

When I moved it to a linux box I got the following error:

Failed to load application: Scanner instance has no attribute 'forward'


Any ideas?

Thanks

Gustavo Rahal | 1 Mar 2006 05:56

Re: error loading app

Sorry for my laziness :). Actually I didn't know that when running in the interpreter I would get the traceback.

the preferences.py code is:

import yaml

def load_pref():
    f = open('saleswebservice.conf')
    return yaml.load_document(f.read())


>>> import preferences
>>> d = preferences.load_file()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'load_file'
>>> d = preferences.load_pref()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/sales/saleswebservice/preferences.py", line 21, in load_pref
    return yaml.load_document(f.read())
  File "/home/sales/lib/python2.4/site-packages/yaml/__init__.py", line 31, in load_document
    for document in load(*args, **kwds):
  File "/home/sales/lib/python2.4/site-packages/yaml/constructor.py", line 41, in __iter__
    while self.resolver.check():
  File "/home/sales/lib/python2.4/site-packages/yaml/resolver.py", line 25, in check
    return self.composer.check()
  File "/home/sales/lib/python2.4/site-packages/yaml/composer.py", line 20, in check
    return not self.parser.check(StreamEndEvent)
  File "/home/sales/lib/python2.4/site-packages/yaml/parser.py", line 95, in check
    self.current_event = self.event_generator.next()
  File "/home/sales/lib/python2.4/site-packages/yaml/parser.py", line 148, in parse_stream
    DocumentStartToken, DocumentEndToken, StreamEndToken):
  File "/home/sales/lib/python2.4/site-packages/yaml/scanner.py", line 115, in check
    self.fetch_more_tokens()
  File "/home/sales/lib/python2.4/site-packages/yaml/scanner.py", line 163, in fetch_more_tokens
    self.scan_to_next_token()
  File "/home/sales/lib/python2.4/site-packages/yaml/scanner.py", line 768, in scan_to_next_token
    if self.scan_line_break():
  File "/home/sales/lib/python2.4/site-packages/yaml/scanner.py", line 1401, in scan_line_break
    self.forward(2)
AttributeError: Scanner instance has no attribute 'forward'
>>>


It could be an installation problem because I install with --prefix=$HOME


Thanks for the help
Gustavo

On 3/1/06, Clark C. Evans <cce <at> clarkevans.com> wrote:
I'm not sure what the problem is, pop-in on #yaml at irc.freenode.net?
More information would be helpful ;)

Best,

Clark

David Warring | 1 Mar 2006 06:19
Picon

Re: Types Making YAML whole unto itself

TRANS wrote:
> Thinking about YAML types, wondering how they fit in a wholistic sense
> of YAML. Types seem foreign in a way, being defined "out there". So I
> was wondering if they could be brough "inside" somehow. In other
> words, could it be possible to use YAML to define a type? Well you
> sort of see it with Kwaify, albiet that defines a schema for a
> document. But surely it could also do the same for just a bit of a
> document? So I try this example:
>
>     ---
>     customer: !type
>       type:       map
>       mapping:
>         name:
>           type:      str
>           required:  yes
>         email:
>           type:      str
>           pattern:   / <at> /
>         age:
>           type:      int
>         birth:
>           type:      date
>
>     customer1: !customer
>       name:  John Doe
>       email: john@...
>       age:   31
>       birth: 1974-10-10
>
> Make senses, but there is a problem here with the name customer being
> both form and function within the same document. I.e. What if you
> needed a custmer named customer? So does the type definition need to
> be in a directive? How might that work?
>   

Here's a perlish approach. I've simply adopted the convention that the 
first record is a Params::Validate mask to be applied to each of the 
remaining records:

#!/usr/bin/perl

use strict;
use YAML;
use Params::Validate;

my ($mask, <at> data) = YAML::Load(q{
---
age:
  regex: '^\d+$'
birth:
  regex: '^\d{4}-\d{2}-\d{2}$'
email:
  regex: \ <at> 
name:
---
age: 31
birth: 1974-10-10
email: john@...
name: John Doe
---
age: 31
birth: 1974-10-bad
email: john@...
name: John Smith
gook: gunk
});

map {validate ( <at> {[$_]}, $mask)}  <at> data;

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Ingy dot Net | 1 Mar 2006 07:10

Re: YAML syntax issues (my proposals for YAML 1.2)

On 28/02/06 21:58 +0200, Kirill Simonov wrote:
> I repost this message, sorry if you get it twice.
> 
> 
> First I'd like to thank everybody for the support I got here and on
> #yaml.

Well thanks for rocking harder than Pat Benetar!

> There are some issues with the YAML grammar that I want to discuss here.

Cool. I want to make a few points before we dive into spec changing waters.

1) As it stands today, all changes to the spec require COI-Consensus.
   That is full agreement between Clark, Oren, and Ingy. Usually this is
   accompanied by some quorum of community consensus, but not always.
2) As one of the 2.5 Major Implementors your voice has major sway. Much
   more sway than in the past, since YAML implementations now hold a
   weight of their own.
3) JSON is here to stay and is a Good Thing(tm). JSON cannot replace
   YAML, because it lacks things like types, references and human
   readablility. Still it is great for light cross language data
   exchange. Supporting JSON will serve YAML well.
4) YAML is in practical use *much* more than when the original
   decisions were made in the dark. We have implementations, use cases
   and real users to weigh against now. Now is more a time for
   pragmatism than idealism.
5) Someone needs to actually make the spec changes. In the past this has
   been Oren, but I think we can safely say he is distracted :) I want
   to open up the spec repository to people interested in helping
   maintain it. Oren can still have ultimate veto power if he wishes,
   but he doesn't need to bottleneck it.

Clark, Oren... any disagreement here? Anything to add. Oren, you might
need to revert from a pumpkin.

> 1. Should indentation be forced for flow collections? The current spec
> requires flow collections to be indented more then the parent block.
> This makes even legitimate-looking documents like
> 
> ---
> simple key: [
>     flow, sequence
> ]   # <--
> 
> to be ill-formed.
> 
> The same question can be asked for this example:
> 
> ---
> block:
>     another block: [
> flow, collection]
> 
> I see the following advantages of allowing such syntax:
> - syck compatibility: syck allows it.
> - Python (a language that has a similar block/flow syntax) allows it.
> - for the scanner, this restriction looks artificial since indentation is
>   not needed for parsing flow collections. Thus removing this restriction
>   will make the scanner more natural.
> 
> On the other hand:
> - it's ugly.
> - noone will really use such syntax. Most likely this indicates a syntax
>   error somewhere (unclosed '[' or '{'). Allowing it will make error
>   messages more confusing.
> 
> So I'm not sure what the best solution is.

I think the answer here is to be lax in what we parse and strict in what we
emit. Emitters should strive to emit in the old style.

> 2. The same question and the same reasons are applicable for quoted
> scalars:
> 
> ---
> block:
>     block: 'quoted
>  scalar'
> 
> Again indentation is not needed for the scanner so such syntax can be
> permitted.

Same answer I think...

> 3. The spec requires scalars to be indended with at least one space. It
> seems this rule was introduced to make the check for '---' and '...'
> indicators easier for the cases like
> 
> ---
> "quoted scalar
> ... <-- invalid indicator"
> 
> But it means that a user is forced to write
> 
> ---
> "quoted
>  scalar"
> 
> which may not look nice. I don't mind to add the check for '---' and
> '...' at the beginning of a line, so I think this restriction can be
> removed. Note that syck does not require it either, although it does not
> check for the indicators.

I defer.

> 4. Tab rules are confusing. Well, it's natural since tabs themselves are
> confusing, but I believe the rules are more confusing than necessary.
> I would like to forbid tabs completely, but it seems it's not an option.
> So where is the confusion? It's explained by this example (tab
> is denoted by '^'):
> 
> --- # ill-formed document (understandable)
> - ^multi line
>    scalar
> --- # again ill-formed document (why?)
> - multi^line
>   scalar
> --- # well-formed document
> - multi line^
>   scalar
> --- # again well-formed document (hmm...)
> - multi line
>   ^scalar
> --- # ill-formed document (?!)
> - multi line
>   scalar^
> 
> I may be wrong in my interpretation of the production rules though, 
> so the above attributions could be wrong. Anyway I'd like to use the
> following rule: tabs cannot be used before block indicators ('-', '?',
> ':', and simple keys) and cannot denote the end of block and plain
> scalars. Well, something like this; I'm not sure that this rule is
> complete or correct. But I'd like to have a rule that can be explained by
> a single sentence.

I wouldn't mind forbidding tabs in every case but the literal block scalar.

The use case is that you can indent any (printable) block of text and
make it literal by slapping

    foo: |

In front of it.

> 5. In the flow context, ':' and ',' should not be allowed for plain
> scalars and should always be separators. This means that the document
> 
> --- [1:2,3:4]
> 
> is the same as
> 
> --- [ 1 : 2 , 3 : 4 ]
> 
> It was already discussed here, I added it for completeness. The
> following two issues assume that this rule is implemented.

I think it must be that way.

I don't see people writing many flow collections by hand anyway.

> 6. 'ns-anchor-name' is too greedy:
> ns-anchor-name  ::=   ns-char+
> 
> It may cause confusion for the documents like
> 
> --- { &A 1,*A,1 }
> 
> I want it to be restricted to 'ns-word-char+'. By the way, why '_' isn't
> included to 'ns-word-char'? It can be useful for identificators.

+1 (on both counts)

'_' is also a word char in all regexp implementations.

> 7. I'd like to forbid empty plain scalars if the anchor or tag is
> specified. For instance, I want to make the following example
> ill-formed:
> 
> ---
> block key: !tag
> ---
> { !perl/A::Package }
> 
> For the latter example, it's not clear if it is
>     { !perl/A::Package '' }
> or
>     { !perl/A: '' : 'Package' }
> This is the reason why I want this rule.

Does this prevent us from using ':' in a tag in a flow collection?

> 8. 'y' and 'n' should be removed from the boolean constants. It was
> already discussed on #yaml.

+1

> That's all so far.

Cool. I will try to get all the spec components checked into
http://svn.yaml.org/spec/ asap. After that I will give commit access to
interested parties.

Cheers, Ingy

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Kirill Simonov | 1 Mar 2006 10:32
Picon

Re: error loading app

Hi Gustavo,

On Wed, Mar 01, 2006 at 01:56:03AM -0300, Gustavo Rahal wrote:
> Sorry for my laziness :). Actually I didn't know that when running in the
> interpreter I would get the traceback.
> 
> the preferences.py code is:

It's a bug, thanks for reporting it. I've commited the fix to SVN.

--

-- 
xi

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
WEBMASTER. | 2 Mar 2006 11:57

Perl on redhat ES3 - Problem installing YAML

Hi,

I want to install the JSAN shell (javascript libraries, openjsan.org), but
it needs YAML and YAML fails one test:

t/node-info..........NOK 9#   Failed test 'Regular Expression'
#   in inc/Test/Base.pm - /Users/ingy/local/lib/perl5/site_perl/5.8.6
/Test/Base.pm at line 337.
#                   'undef;undef;0x9c3f2bc-S'
#     doesn't match '(?-xism:^undef;REGEXP;0x[0-9a-fA-F]+$)'

The "Test::Base package" is up to date:
cpan> install Test::Base
Test::Base is up to date (0.50).

I'm using PERL 5.8.0:
"This is perl, v5.8.0 built for i386-linux-thread-multi"

I know it's an old version but this is the one that comes with RedHat ES3, there's no available update for now.

Do you think the problem with YAML is related to the Perl version?
Has anyone encountered the same problem ?

Thank you for your answers.

Eric.

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Ingy dot Net | 3 Mar 2006 03:59

Re: Perl on redhat ES3 - Problem installing YAML

Perl 5.8.0 is really problematic. I'm sure that is the problem.

On the other hand I wouldn't worry about failing this one test. Go ahead and
install YAML.pm and enjoy your JSAN shell. :)

Cheers, Ingy

On 02/03/06 11:57 +0100, WEBMASTER. wrote:
> Hi,
> 
> I want to install the JSAN shell (javascript libraries, openjsan.org), but
> it needs YAML and YAML fails one test:
> 
> t/node-info..........NOK 9#   Failed test 'Regular Expression'
> #   in inc/Test/Base.pm - /Users/ingy/local/lib/perl5/site_perl/5.8.6
> /Test/Base.pm at line 337.
> #                   'undef;undef;0x9c3f2bc-S'
> #     doesn't match '(?-xism:^undef;REGEXP;0x[0-9a-fA-F]+$)'
> 
> 
> The "Test::Base package" is up to date:
> cpan> install Test::Base
> Test::Base is up to date (0.50).
> 
> I'm using PERL 5.8.0:
> "This is perl, v5.8.0 built for i386-linux-thread-multi"
> 
> I know it's an old version but this is the one that comes with RedHat ES3, there's no available update for now.
> 
> Do you think the problem with YAML is related to the Perl version?
> Has anyone encountered the same problem ?
> 
> Thank you for your answers.
> 
> Eric.
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Yaml-core mailing list
> Yaml-core@...
> https://lists.sourceforge.net/lists/listinfo/yaml-core

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Kirill Simonov | 3 Mar 2006 18:03
Picon

Re: YAML syntax issues (my proposals for YAML 1.2)

On Tue, Feb 28, 2006 at 10:10:38PM -0800, Ingy dot Net wrote:
> On 28/02/06 21:58 +0200, Kirill Simonov wrote:
> > I repost this message, sorry if you get it twice.
> > 
> > 
> > First I'd like to thank everybody for the support I got here and on
> > #yaml.
> 
> Well thanks for rocking harder than Pat Benetar!
> 
> > There are some issues with the YAML grammar that I want to discuss here.
> 
> Cool. I want to make a few points before we dive into spec changing waters.
> 
> 1) As it stands today, all changes to the spec require COI-Consensus.
>    That is full agreement between Clark, Oren, and Ingy. Usually this is
>    accompanied by some quorum of community consensus, but not always.
> 2) As one of the 2.5 Major Implementors your voice has major sway. Much
>    more sway than in the past, since YAML implementations now hold a
>    weight of their own.
> 3) JSON is here to stay and is a Good Thing(tm). JSON cannot replace
>    YAML, because it lacks things like types, references and human
>    readablility. Still it is great for light cross language data
>    exchange. Supporting JSON will serve YAML well.
> 4) YAML is in practical use *much* more than when the original
>    decisions were made in the dark. We have implementations, use cases
>    and real users to weigh against now. Now is more a time for
>    pragmatism than idealism.
> 5) Someone needs to actually make the spec changes. In the past this has
>    been Oren, but I think we can safely say he is distracted :) I want
>    to open up the spec repository to people interested in helping
>    maintain it. Oren can still have ultimate veto power if he wishes,
>    but he doesn't need to bottleneck it.

Thanks for clarifying this.

I don't think that YAML requires major changes. What I want to see is
fixes for some corner cases which affect parsers, but are not interesting
for most users.

> > 7. I'd like to forbid empty plain scalars if the anchor or tag is
> > specified. For instance, I want to make the following example
> > ill-formed:
> > 
> > ---
> > block key: !tag
> > ---
> > { !perl/A::Package }
> > 
> > For the latter example, it's not clear if it is
> >     { !perl/A::Package '' }
> > or
> >     { !perl/A: '' : 'Package' }
> > This is the reason why I want this rule.
> 
> Does this prevent us from using ':' in a tag in a flow collection?

Yes. Since it's planned to make ':' an indicator in the flow context
(as opposed to ': '), you need either forbid ':' in tags or forbid empty
plain scalars in flow collections.

--

-- 
xi

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Poprádi Árpád | 3 Mar 2006 23:15
Picon
Favicon

problem at transfer with self-reference of domain types

Hi.
I try to use Yaml to store gnomecanvas items, where a group item has 
other items, that refer to the group, but the 
object created in my YAML::add_domain_type gets lost and instead of 
that I get an other one from YAML.

A simple self-reference is enough for the same phenomena.

require "yaml"

class Foo
  attr_accessor :point

  def to_yaml_type
  	"!Foo,2006/Foo"
  end
end

YAML::add_domain_type( 'Foo,2006', 'Foo' ) do |type, val|
  obj = Foo.new
  obj.point = obj
  p "object created in add_domain_type " + obj.inspect
  obj
end

#create an object with self ref
myFoo = Foo.new
myFoo.point = myFoo

yaml_Foo = myFoo.to_yaml
p yaml_Foo

restored_obj = YAML::load(yaml_Foo)
p "restored_obj " + restored_obj.inspect

the output:

"--- &id001 !Foo,2006/Foo \npoint: *id001\n"
"object created in add_domain_type #<Foo:0x402cb1f8  <at> point=#<Foo:
0x402cb1f8 ...>>"
"restored_obj #<Foo:0x402cb694>"

My created object is destroyed but an other unusable one is alive.
The problem seems to be that the alias as BadAlias marked as my block 
is called and I have no chance this point of view of Syck to change.
not even if I put the newly created object to val["point"] back.

What can I do? Should I emit direct? For that I have no doc found.

I use Yaml in Ruby 1.8.4 on Linux.

Arpad Popradi

___________________________________________________________________________
[origo] Ingatlan apró – Óriási lehetőség
Több mint 120.000 új és használt ingatlan! http://ingatlanbazis.origo.hu

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642

Gmane