From: Rolf V. <rol...@he...> - 2002-08-23 10:41:05
|
Rolf Veen wrote: > It would be nice to have a schema syntax that is close > to the final document, so the parser can follow it exactly > while requesting elements from the incomming document. Literals > appear as is, while type definitions are sort of variables > in the schema definition. Also a benefit for readability. > > A way to escape type definitions is needed. Some possibilities: > > schema: > Firstname: !def string > LastName: !def string="Evans"|"Smith"|"Jones" > Children: > - !defup { max: 10 } > - !def string > > schema: > Firstname: !str ? > LastName: !str "Evans"|"Smith"|"Jones" > Children: > - !attr {max: 10} > - !str ? Oops, invalid YAML. Well, you get the idea :-). Rolf. > where '?' stands for any string. > > We could also think about integrating EBNF in some way, because > it is compact and clean. James Clark has used it in its > schema language for XML, Relax NG, compact version: > > http://www.oasis-open.org/committees/relax-ng/compact-20020607.html > > > The structure of the Java parser is such that it would be > easy to make a pull parser extension. I'll take note. > > Cheers. > Rolf. > > -- > > Steve Howell wrote: > > I am starting to think about how I would write a validating YAML > parser on top > > of PyYaml. There are two major issues here--how do you define the > schemas, and > > how do you implement the parser. Just to get the discussion rolling, > let me > > throw out a really simple example: > > > > SCHEMA: > > > > allowed: > > - type: map > > - keys: > > - type: string > > name: FirstName > > - type: string > > name: LastName > > validation: | > > (value in ['Evans', 'Smith', 'Jones']) > > - type: string > > seq: 1 > > name: Children > > max: 10 > > > > CONFORMING YAML: > > > > --- > > FirstName: John > > LastName: Smith > > Children: > > - Billy > > - Mary > > > > A validating parser would want to have a pull interface to the base > parser. (I > > don't believe any existing YAML implementations provide such an > interface. Most > > implementations load the whole document at once.) On the particular > data set > > that I've given, the validating layer might make the following calls > into a pull > > parser: > > > > > >>>>parser.isStartMap() > >>> > > 1 > > > >>>>parser.getKey() > >>> > > 'FirstName' > > > >>>>parser.getScalar() > >>> > > 'John' > > > >>>>parser.getScalar() > >>> > > 'Smith' > > > >>>>parser.getStartMap() > >>> > > 1 > > > >>>>parser.getKey() > >>> > > 'Children' > > > >>>>parser.isStartMap() > >>> > > 1 > > > >>>>parser.isStartList() > >>> > > 1 > > > >>>>parser.getScalar() > >>> > > 'Billy' > > > >>>>parser.getScalar() > >>> > > 'Mary' > > > >>>>parser.getScalar() > >>> > > StopIteration exception thrown > > > >>>>parser.getKey() > >>> > > StopIteration exception thrown > > > >>>>parser.getKey() > >>> > > StopIteration exception thrown > > > > Does this make sense so far? > > > > Once you implemented all the methods for a pull parser, you would > probably want > > to implement the all-the-data-at-once yaml.load() method on top of > the pull > > parser methods. Since the generic load call would not have a schema > to drive > > the parsing process, you would need some sort of node-testing method(s). > > > > > >>>>parser.getNodeType() > >>> > > 'map' > > > >>>>parser.getNodeType() > >>> > > 'scalar' > > > >>>>parser.getScalar() > >>> > > 'FirstName' > > > >>>>parser.getNodeType() > >>> > > 'scalar' > > > >>>>parser.getScalar() > >>> > > 'John' > > # etc. > > > > Thanks, > > > > Steve > > > > > > > > > > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by: OSDN - Tired of that same old > > cell phone? Get a new here for FREE! > > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > > _______________________________________________ > > Yaml-core mailing list > > Yam...@li... > > https://lists.sourceforge.net/lists/listinfo/yaml-core > > > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Yaml-core mailing list > Yam...@li... > https://lists.sourceforge.net/lists/listinfo/yaml-core > > > |