mkrf 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/MIT-LICENSE +7 -0
- data/README +54 -0
- data/Rakefile +107 -0
- data/lib/mkrf.rb +4 -0
- data/lib/mkrf/availability.rb +219 -0
- data/lib/mkrf/generator.rb +146 -0
- data/test/abstract_unit.rb +4 -0
- data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
- data/test/fixtures/stdmkrf.h +1 -0
- data/test/sample_files/libtrivial/Rakefile +31 -0
- data/test/sample_files/libtrivial/extconf.rb +3 -0
- data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
- data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
- data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
- data/test/sample_files/libtrivial/mkrf.log +1 -0
- data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
- data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
- data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
- data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
- data/test/sample_files/syck-0.55/CHANGELOG +186 -0
- data/test/sample_files/syck-0.55/COPYING +54 -0
- data/test/sample_files/syck-0.55/Makefile +582 -0
- data/test/sample_files/syck-0.55/Makefile.am +5 -0
- data/test/sample_files/syck-0.55/Makefile.in +582 -0
- data/test/sample_files/syck-0.55/README +105 -0
- data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
- data/test/sample_files/syck-0.55/README.EXT +444 -0
- data/test/sample_files/syck-0.55/RELEASE +123 -0
- data/test/sample_files/syck-0.55/TODO +25 -0
- data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
- data/test/sample_files/syck-0.55/bootstrap +7 -0
- data/test/sample_files/syck-0.55/config.h +79 -0
- data/test/sample_files/syck-0.55/config.h.in +78 -0
- data/test/sample_files/syck-0.55/config.status +1197 -0
- data/test/sample_files/syck-0.55/config/README +14 -0
- data/test/sample_files/syck-0.55/config/depcomp +529 -0
- data/test/sample_files/syck-0.55/config/install-sh +323 -0
- data/test/sample_files/syck-0.55/config/missing +357 -0
- data/test/sample_files/syck-0.55/configure +6728 -0
- data/test/sample_files/syck-0.55/configure.in +36 -0
- data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
- data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
- data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
- data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
- data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
- data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
- data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
- data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
- data/test/sample_files/syck-0.55/lib/Makefile +497 -0
- data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
- data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
- data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
- data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
- data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
- data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
- data/test/sample_files/syck-0.55/lib/gram.h +79 -0
- data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
- data/test/sample_files/syck-0.55/lib/gram.y +481 -0
- data/test/sample_files/syck-0.55/lib/handler.c +174 -0
- data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
- data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
- data/test/sample_files/syck-0.55/lib/node.c +407 -0
- data/test/sample_files/syck-0.55/lib/syck.c +504 -0
- data/test/sample_files/syck-0.55/lib/syck.h +458 -0
- data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
- data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
- data/test/sample_files/syck-0.55/lib/token.c +2707 -0
- data/test/sample_files/syck-0.55/lib/token.re +1139 -0
- data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
- data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
- data/test/sample_files/syck-0.55/stamp-h1 +1 -0
- data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
- data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
- data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
- data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
- data/test/sample_files/syck-0.55/tests/Makefile +480 -0
- data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
- data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
- data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
- data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
- data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
- data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
- data/test/test_availability.rb +68 -0
- data/test/test_generator.rb +74 -0
- metadata +252 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
$Id: README.EXT,v 1.5 2005/05/19 04:51:31 why Exp $
|
|
2
|
+
|
|
3
|
+
This is the documentation for libsyck and describes how to extend it.
|
|
4
|
+
|
|
5
|
+
= Overview =
|
|
6
|
+
|
|
7
|
+
Syck is designed to take a YAML stream and a symbol table and move
|
|
8
|
+
data between the two. Your job is to simply provide callback functions which
|
|
9
|
+
understand the symbol table you are keeping.
|
|
10
|
+
|
|
11
|
+
Syck also includes a simple symbol table implementation.
|
|
12
|
+
|
|
13
|
+
== About the Source ==
|
|
14
|
+
|
|
15
|
+
The Syck distribution is laid out as follows:
|
|
16
|
+
|
|
17
|
+
lib/ libsyck source (core API)
|
|
18
|
+
bytecode.re lexer for YAML bytecode (re2c)
|
|
19
|
+
emitter.c emitter functions
|
|
20
|
+
gram.y grammar for YAML documents (bison)
|
|
21
|
+
handler.c internal handlers which glue the lexer and grammar
|
|
22
|
+
implicit.re lexer for builtin YAML types (re2c)
|
|
23
|
+
node.c node allocation and access
|
|
24
|
+
syck.c parser funcs, central funcs
|
|
25
|
+
syck.h libsyck definitions
|
|
26
|
+
syck_st.c symbol table functions
|
|
27
|
+
syck_st.h symbol table definitions
|
|
28
|
+
token.re lexer for YAML plaintext (re2c)
|
|
29
|
+
yaml2byte.c simple bytecode emitter
|
|
30
|
+
ext/ ruby, python, php, cocoa extensions
|
|
31
|
+
tests/ unit tests for libsyck
|
|
32
|
+
YTS.c.rb generates YAML Testing Suite unit test
|
|
33
|
+
(use: ruby YTS.c.rb > YTS.c)
|
|
34
|
+
Basic.c allocation and buffering tests
|
|
35
|
+
Parse.c parser sanity
|
|
36
|
+
Emit.c emitter sanity
|
|
37
|
+
|
|
38
|
+
== Using SyckNodes ==
|
|
39
|
+
|
|
40
|
+
The SyckNode is the structure which YAML data is loaded into
|
|
41
|
+
while parsing. It's also a good structure to use while emitting,
|
|
42
|
+
however you may choose to emit directly from your native types
|
|
43
|
+
if your extension is very small.
|
|
44
|
+
|
|
45
|
+
SyckNodes are designed to be used in conjunction with a symbol
|
|
46
|
+
table. More on that in a moment. For now, think of a symbol
|
|
47
|
+
table as a library which stores nodes, assigning each node a
|
|
48
|
+
unique identifier.
|
|
49
|
+
|
|
50
|
+
This identifier is called the SYMID in Syck. Nodes refer to
|
|
51
|
+
each other by SYMIDs, rather than pointers. This way, the
|
|
52
|
+
nodes can be free'd as the parser goes.
|
|
53
|
+
|
|
54
|
+
To be honest, SYMIDs are used because this is the way Ruby
|
|
55
|
+
works. And this technique means Syck can use Ruby's symbol
|
|
56
|
+
table directly. But the included symbol table is lightweight,
|
|
57
|
+
solves the problem of keeping too much data in memory, and
|
|
58
|
+
simply pairs SYMIDs with your native object type (such as
|
|
59
|
+
PyObject pointers.)
|
|
60
|
+
|
|
61
|
+
Three kinds of SyckNodes are available:
|
|
62
|
+
|
|
63
|
+
1. scalar nodes (syck_str_kind):
|
|
64
|
+
These nodes store a string, a length for the string
|
|
65
|
+
and a style (indicating the format used in the YAML
|
|
66
|
+
document).
|
|
67
|
+
|
|
68
|
+
2. sequence nodes (syck_seq_kind):
|
|
69
|
+
Sequences are YAML's array or list type.
|
|
70
|
+
These nodes store a list of items, which allocation
|
|
71
|
+
is handled by syck functions.
|
|
72
|
+
|
|
73
|
+
3. mapping nodes (syck_map_kind):
|
|
74
|
+
Mappings are YAML's dictionary or hashtable type.
|
|
75
|
+
These nodes store a list of pairs, which allocation
|
|
76
|
+
is handled by syck functions.
|
|
77
|
+
|
|
78
|
+
The syck_kind_tag enum specifies the above enumerations,
|
|
79
|
+
which can be tested against the SyckNode.kind field.
|
|
80
|
+
|
|
81
|
+
PLEASE leave the SyckNode.shortcut field alone!! It's
|
|
82
|
+
used by the parser to workaround parser ambiguities!!
|
|
83
|
+
|
|
84
|
+
=== Node API ===
|
|
85
|
+
|
|
86
|
+
SyckNode *
|
|
87
|
+
syck_alloc_str()
|
|
88
|
+
syck_alloc_seq()
|
|
89
|
+
syck_alloc_str()
|
|
90
|
+
|
|
91
|
+
Allocates a node of a given type and initializes its
|
|
92
|
+
internal union to emptiness. When left as-is, these
|
|
93
|
+
nodes operate as a valid empty string, empty sequence
|
|
94
|
+
and empty map.
|
|
95
|
+
|
|
96
|
+
Remember that the node's id (SYMID) isn't set by the
|
|
97
|
+
allocation functions OR any other node functions herein.
|
|
98
|
+
It's up to your handler function to do that.
|
|
99
|
+
|
|
100
|
+
void
|
|
101
|
+
syck_free_node( SyckNode *n )
|
|
102
|
+
|
|
103
|
+
While the Syck parser will free nodes it creates, use
|
|
104
|
+
this to free your own nodes. This function will free
|
|
105
|
+
all of its internals, its type_id and its anchor. If
|
|
106
|
+
you don't need those members free, please be sure they
|
|
107
|
+
are set to NULL.
|
|
108
|
+
|
|
109
|
+
SyckNode *
|
|
110
|
+
syck_new_str( char *str, enum scalar_style style )
|
|
111
|
+
syck_new_str2( char *str, long len, enum scalar_style style )
|
|
112
|
+
|
|
113
|
+
Creates scalar nodes from C strings. The first function
|
|
114
|
+
will call strlen() to determine length.
|
|
115
|
+
|
|
116
|
+
void
|
|
117
|
+
syck_replace_str( SyckNode *n, char *str, enum scalar_style style )
|
|
118
|
+
syck_replace_str2( SyckNode *n, char *str, long len, enum scalar_style style )
|
|
119
|
+
|
|
120
|
+
Replaces the string content of a node `n', while keeping
|
|
121
|
+
the node's type_id, anchor and id.
|
|
122
|
+
|
|
123
|
+
char *
|
|
124
|
+
syck_str_read( SyckNode *n )
|
|
125
|
+
|
|
126
|
+
Returns a pointer to the null-terminated string inside scalar node
|
|
127
|
+
`n'. Normally, you might just want to use:
|
|
128
|
+
|
|
129
|
+
char *ptr = n->data.str->ptr
|
|
130
|
+
long len = n->data.str->len
|
|
131
|
+
|
|
132
|
+
SyckNode *
|
|
133
|
+
syck_new_map( SYMID key, SYMID value )
|
|
134
|
+
|
|
135
|
+
Allocates a new map with an initial pair of nodes.
|
|
136
|
+
|
|
137
|
+
void
|
|
138
|
+
syck_map_empty( SyckNode *n )
|
|
139
|
+
|
|
140
|
+
Empties the set of pairs for a mapping node.
|
|
141
|
+
|
|
142
|
+
void
|
|
143
|
+
syck_map_add( SyckNode *n, SYMID key, SYMID value )
|
|
144
|
+
|
|
145
|
+
Pushes a key-value pair on the mapping. While the ordering
|
|
146
|
+
of pairs DOES affect the ordering of pairs on output, loaded
|
|
147
|
+
nodes are deliberately out of order (since YAML mappings do
|
|
148
|
+
not preserve ordering.)
|
|
149
|
+
|
|
150
|
+
See YAML's builtin !omap type for ordering in mapping nodes.
|
|
151
|
+
|
|
152
|
+
SYMID
|
|
153
|
+
syck_map_read( SyckNode *n, enum map_part, long index )
|
|
154
|
+
|
|
155
|
+
Loads a specific key or value from position `index' within
|
|
156
|
+
a mapping node. Great for iteration:
|
|
157
|
+
|
|
158
|
+
for ( i = 0; i < syck_map_count( n ); i++ ) {
|
|
159
|
+
SYMID key = sym_map_read( n, map_key, i );
|
|
160
|
+
SYMID val = sym_map_read( n, map_value, i );
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
void
|
|
164
|
+
syck_map_assign( SyckNode *n, enum map_part, long index, SYMID id )
|
|
165
|
+
|
|
166
|
+
Replaces a specific key or value at position `index' within
|
|
167
|
+
a mapping node. Useful for replacement only, will not allocate
|
|
168
|
+
more room when assigned beyond the end of the pair list.
|
|
169
|
+
|
|
170
|
+
long
|
|
171
|
+
syck_map_count( SyckNode *n )
|
|
172
|
+
|
|
173
|
+
Returns a count of the pairs contained by the mapping node.
|
|
174
|
+
|
|
175
|
+
void
|
|
176
|
+
syck_map_update( SyckNode *n, SyckNode *n2 )
|
|
177
|
+
|
|
178
|
+
Combines all pairs from mapping node `n2' into mapping node
|
|
179
|
+
`n'.
|
|
180
|
+
|
|
181
|
+
SyckNode *
|
|
182
|
+
syck_new_seq( SYMID val )
|
|
183
|
+
|
|
184
|
+
Allocates a new seq with an entry `val'.
|
|
185
|
+
|
|
186
|
+
void
|
|
187
|
+
syck_seq_empty( SyckNode *n )
|
|
188
|
+
|
|
189
|
+
Empties a sequence node `n'.
|
|
190
|
+
|
|
191
|
+
void
|
|
192
|
+
syck_seq_add( SyckNode *n, SYMID val )
|
|
193
|
+
|
|
194
|
+
Pushes a new item `val' onto the end of the sequence.
|
|
195
|
+
|
|
196
|
+
void
|
|
197
|
+
syck_seq_assign( SyckNode *n, long index, SYMID val )
|
|
198
|
+
|
|
199
|
+
Replaces the item at position `index' in the sequence
|
|
200
|
+
node with item `val'. Useful for replacement only, will not allocate
|
|
201
|
+
more room when assigned beyond the end of the pair list.
|
|
202
|
+
|
|
203
|
+
SYMID
|
|
204
|
+
syck_seq_read( SyckNode *n, long index )
|
|
205
|
+
|
|
206
|
+
Reads the item at position `index' in the sequence node.
|
|
207
|
+
Again, for iteration:
|
|
208
|
+
|
|
209
|
+
for ( i = 0; i < syck_seq_count( n ); i++ ) {
|
|
210
|
+
SYMID val = sym_seq_read( n, i );
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
long
|
|
214
|
+
syck_seq_count( SyckNode *n )
|
|
215
|
+
|
|
216
|
+
Returns a count of items contained by sequence node `n'.
|
|
217
|
+
|
|
218
|
+
== YAML Parser ==
|
|
219
|
+
|
|
220
|
+
Syck's YAML parser is extremely simple. After setting up a
|
|
221
|
+
SyckParser struct, along with callback functions for loading
|
|
222
|
+
node data, use syck_parse() to start reading data. Since
|
|
223
|
+
syck_parse() only reads single documents, the stream can be
|
|
224
|
+
managed by calling syck_parse() repeatedly for an IO source.
|
|
225
|
+
|
|
226
|
+
The parser has four callbacks: one for reading from the IO
|
|
227
|
+
source, one for handling errors that show up, one for
|
|
228
|
+
handling nodes as they come in, one for handling bad
|
|
229
|
+
anchors in the document. Nodes are loaded in the order they
|
|
230
|
+
appear in the YAML document, however nested nodes are loaded
|
|
231
|
+
before their parent.
|
|
232
|
+
|
|
233
|
+
=== How to Write a Node Handler ===
|
|
234
|
+
|
|
235
|
+
Inside the node handler, the normal process should be:
|
|
236
|
+
|
|
237
|
+
1. Convert the SyckNode data to a structure meaningful
|
|
238
|
+
to your application.
|
|
239
|
+
|
|
240
|
+
2. Check for the bad anchor caveat described in the
|
|
241
|
+
next section.
|
|
242
|
+
|
|
243
|
+
3. Add the new structure to the symbol table attached
|
|
244
|
+
to the parser. Found at parser->syms.
|
|
245
|
+
|
|
246
|
+
4. Return the SYMID reserved in the symbol table.
|
|
247
|
+
|
|
248
|
+
=== Nodes and Memory Allocation ===
|
|
249
|
+
|
|
250
|
+
One thing about SyckNodes passed into your handler:
|
|
251
|
+
Syck WILL free the node once your handler is done with it.
|
|
252
|
+
The node is temporary. So, if you plan on keeping a node
|
|
253
|
+
around, you'll need to make yourself a new copy.
|
|
254
|
+
|
|
255
|
+
And you'll probably need to reassign all the items
|
|
256
|
+
in a sequence and pairs in a map. You can do this
|
|
257
|
+
with syck_seq_assign() and syck_map_assign(). But, before
|
|
258
|
+
you do that, you might consider using your own node structure
|
|
259
|
+
that fits your application better.
|
|
260
|
+
|
|
261
|
+
=== A Note About Anchors in Parsing ===
|
|
262
|
+
|
|
263
|
+
YAML anchors can be recursive. This means deeper alias nodes
|
|
264
|
+
can be loaded before the anchor. This is the trickiest part
|
|
265
|
+
of the loading process.
|
|
266
|
+
|
|
267
|
+
Assuming this YAML document:
|
|
268
|
+
|
|
269
|
+
--- &a [*a]
|
|
270
|
+
|
|
271
|
+
The loading process is:
|
|
272
|
+
|
|
273
|
+
1. Load alias *a by calling parser->bad_anchor_handler, which
|
|
274
|
+
reserves a SYMID in the symbol table.
|
|
275
|
+
|
|
276
|
+
2. The `a' anchor is added to Syck's own anchor table,
|
|
277
|
+
referencing the SYMID above.
|
|
278
|
+
|
|
279
|
+
3. When the anchor &a is found, the SyckNode created is
|
|
280
|
+
given the SYMID of the bad anchor node above. (Usually
|
|
281
|
+
nodes created at this stage have the `id' blank.)
|
|
282
|
+
|
|
283
|
+
4. The parser->handler function is called with that node.
|
|
284
|
+
Check for node->id in the handler and overwrite the
|
|
285
|
+
bad anchor node with the new node.
|
|
286
|
+
|
|
287
|
+
=== Parser API ===
|
|
288
|
+
|
|
289
|
+
See <syck.h> for layouts of SyckParser and SyckNode.
|
|
290
|
+
|
|
291
|
+
SyckParser *
|
|
292
|
+
syck_new_parser()
|
|
293
|
+
|
|
294
|
+
Creates a new Syck parser.
|
|
295
|
+
|
|
296
|
+
void
|
|
297
|
+
syck_free_parser( SyckParser *p )
|
|
298
|
+
|
|
299
|
+
Frees the parser, as well as associated symbol tables
|
|
300
|
+
and buffers.
|
|
301
|
+
|
|
302
|
+
void
|
|
303
|
+
syck_parser_implicit_typing( SyckParser *p, int on )
|
|
304
|
+
|
|
305
|
+
Toggles implicit typing of builtin YAML types. If
|
|
306
|
+
this is passed a zero, YAML builtin types will be
|
|
307
|
+
ignored (!int, !float, etc.) The default is 1.
|
|
308
|
+
|
|
309
|
+
void
|
|
310
|
+
syck_parser_taguri_expansion( SyckParser *p, int on )
|
|
311
|
+
|
|
312
|
+
Toggles expansion of types in full taguri. This
|
|
313
|
+
defaults to 1 and is recommended to stay as 1.
|
|
314
|
+
Turning this off removes a layer of abstraction
|
|
315
|
+
that will cause incompatibilities between YAML
|
|
316
|
+
documents of differing versions.
|
|
317
|
+
|
|
318
|
+
void
|
|
319
|
+
syck_parser_handler( SyckParser *p, SyckNodeHandler h )
|
|
320
|
+
|
|
321
|
+
Assign a callback function as a node handler. The
|
|
322
|
+
SyckNodeHandler signature looks like this:
|
|
323
|
+
|
|
324
|
+
SYMID node_handler( SyckParser *p, SyckNode *n )
|
|
325
|
+
|
|
326
|
+
void
|
|
327
|
+
syck_parser_error_handler( SyckParser *p, SyckErrorHandler h )
|
|
328
|
+
|
|
329
|
+
Assign a callback function as an error handler. The
|
|
330
|
+
SyckErrorHandler signature looks like this:
|
|
331
|
+
|
|
332
|
+
void error_handler( SyckParser *p, char *str )
|
|
333
|
+
|
|
334
|
+
void
|
|
335
|
+
syck_parser_bad_anchor_handler( SyckParser *p, SyckBadAnchorHandler h )
|
|
336
|
+
|
|
337
|
+
Assign a callback function as a bad anchor handler.
|
|
338
|
+
The SyckBadAnchorHandler signature looks like this:
|
|
339
|
+
|
|
340
|
+
SyckNode *bad_anchor_handler( SyckParser *p, char *anchor )
|
|
341
|
+
|
|
342
|
+
void
|
|
343
|
+
syck_parser_file( SyckParser *p, FILE *f, SyckIoFileRead r )
|
|
344
|
+
|
|
345
|
+
Assigns a FILE pointer as an IO source and a callback function
|
|
346
|
+
which handles buffering of that IO source.
|
|
347
|
+
|
|
348
|
+
The SyckIoFileRead signature looks like this:
|
|
349
|
+
|
|
350
|
+
long SyckIoFileRead( char *buf, SyckIoFile *file, long max_size, long skip );
|
|
351
|
+
|
|
352
|
+
Syck comes with a default FILE handler named `syck_io_file_read'. You
|
|
353
|
+
can assign this default handler explicitly or by simply passing in NULL
|
|
354
|
+
as the `r' parameter.
|
|
355
|
+
|
|
356
|
+
void
|
|
357
|
+
syck_parser_str( SyckParser *p, char *ptr, long len, SyckIoStrRead r )
|
|
358
|
+
|
|
359
|
+
Assigns a string as the IO source with a callback function `r'
|
|
360
|
+
which handles buffering of the string.
|
|
361
|
+
|
|
362
|
+
The SyckIoStrRead signature looks like this:
|
|
363
|
+
|
|
364
|
+
long SyckIoFileRead( char *buf, SyckIoStr *str, long max_size, long skip );
|
|
365
|
+
|
|
366
|
+
Syck comes with a default string handler named `syck_io_str_read'. You
|
|
367
|
+
can assign this default handler explicitly or by simply passing in NULL
|
|
368
|
+
as the `r' parameter.
|
|
369
|
+
|
|
370
|
+
void
|
|
371
|
+
syck_parser_str_auto( SyckParser *p, char *ptr, SyckIoStrRead r )
|
|
372
|
+
|
|
373
|
+
Same as the above, but uses strlen() to determine string size.
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
SYMID
|
|
377
|
+
syck_parse( SyckParser *p )
|
|
378
|
+
|
|
379
|
+
Parses a single document from the YAML stream, returning the SYMID for
|
|
380
|
+
the root node.
|
|
381
|
+
|
|
382
|
+
== YAML Emitter ==
|
|
383
|
+
|
|
384
|
+
Since the YAML 0.50 release, Syck has featured a new emitter API. The idea
|
|
385
|
+
here is to let Syck figure out shortcuts that will clean up output, detect
|
|
386
|
+
builtin YAML types and -- especially -- determine the best way to format
|
|
387
|
+
outgoing strings.
|
|
388
|
+
|
|
389
|
+
The trick with the emitter is to learn its functions and let it do its
|
|
390
|
+
job. If you don't like the formatting Syck is producing, please get in
|
|
391
|
+
contact the author and pitch your ideas!!
|
|
392
|
+
|
|
393
|
+
Like the YAML parser, the emitter has a couple of callbacks: namely,
|
|
394
|
+
one for IO output and one for handling nodes. Nodes aren't necessarily
|
|
395
|
+
SyckNodes. Since we're ultimately worried about creating a string, SyckNodes
|
|
396
|
+
become sort of unnecessary.
|
|
397
|
+
|
|
398
|
+
=== The Emitter Process ===
|
|
399
|
+
|
|
400
|
+
1. Traverse the structure you will be emitting, registering all nodes
|
|
401
|
+
with the emitter using syck_emitter_mark_node(). This step will
|
|
402
|
+
determine anchors and aliases in advance.
|
|
403
|
+
|
|
404
|
+
2. Call syck_emit() to begin emitting the root node.
|
|
405
|
+
|
|
406
|
+
3. Within your emitter handler, use the syck_emit_* convenience methods
|
|
407
|
+
to build the document.
|
|
408
|
+
|
|
409
|
+
4. Call syck_emit_flush() to end the document and push the remaining
|
|
410
|
+
document to the IO stream. Or continue to add documents to the output
|
|
411
|
+
stream with syck_emit().
|
|
412
|
+
|
|
413
|
+
=== Emitter API ===
|
|
414
|
+
|
|
415
|
+
See <syck.h> for the layout of SyckEmitter.
|
|
416
|
+
|
|
417
|
+
SyckEmitter *
|
|
418
|
+
syck_new_emitter()
|
|
419
|
+
|
|
420
|
+
Creates a new Syck emitter.
|
|
421
|
+
|
|
422
|
+
SYMID
|
|
423
|
+
syck_emitter_mark_node( SyckEmitter *e, st_data_t node )
|
|
424
|
+
|
|
425
|
+
Adds an outgoing node to the symbol table, allocating an anchor
|
|
426
|
+
for it if it has repeated in the document and scanning the type
|
|
427
|
+
tag for auto-shortcut.
|
|
428
|
+
|
|
429
|
+
void
|
|
430
|
+
syck_output_handler( SyckEmitter *e, SyckOutputHandler out )
|
|
431
|
+
|
|
432
|
+
Assigns a callback as the output handler.
|
|
433
|
+
|
|
434
|
+
void *out_handler( SyckEmitter *e, char * ptr, long len );
|
|
435
|
+
|
|
436
|
+
Receives the emitter object, pointer to the buffer and a count
|
|
437
|
+
of bytes which should be read from the buffer.
|
|
438
|
+
|
|
439
|
+
void
|
|
440
|
+
syck_emitter_handler( SyckEmitter *e, SyckEmitterHandler
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
void
|
|
444
|
+
syck_free_emitter
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
released: { name: Syck, version: 0.54 }
|
|
2
|
+
for: [ Ruby, PHP, Python ]
|
|
3
|
+
by: why the lucky stiff
|
|
4
|
+
about: >
|
|
5
|
+
|
|
6
|
+
Syck is a YAML parser, an extension for scripting
|
|
7
|
+
languages, written in C.
|
|
8
|
+
|
|
9
|
+
So what is YAML? YAML is a new language for data.
|
|
10
|
+
Describe objects in plain text. Load the data into
|
|
11
|
+
your scripting language as arrays, dictionaries,
|
|
12
|
+
classes, or primitives.
|
|
13
|
+
|
|
14
|
+
links:
|
|
15
|
+
YAML: http://www.yaml.org/
|
|
16
|
+
YAML Cookbook: http://yaml4r.sf.net/cookbook/
|
|
17
|
+
YAML Type Repository: http://yaml.org/type/
|
|
18
|
+
YAML Specification: http://yaml.org/spec/
|
|
19
|
+
Syck: http://www.whytheluckystiff.net/syck/
|
|
20
|
+
Syck Benchmarks: http://www.whytheluckystiff.net/arch/2003/03/19
|
|
21
|
+
|
|
22
|
+
status: >
|
|
23
|
+
|
|
24
|
+
Syck is about 95% compliant with the YAML spec. Largely, small
|
|
25
|
+
issues remain.
|
|
26
|
+
|
|
27
|
+
The extensions are quite usable. Ruby, PHP and Python
|
|
28
|
+
can load from a string containing YAML.
|
|
29
|
+
|
|
30
|
+
Ruby has support for stream loading, type handling, YPath, Okay.
|
|
31
|
+
This release includes an amount of Ruby code comprising the 0.60
|
|
32
|
+
release of YAML.rb.
|
|
33
|
+
|
|
34
|
+
benchmarks: >
|
|
35
|
+
|
|
36
|
+
Syck is quite speedy, although not as swift as most language's
|
|
37
|
+
native serialization.
|
|
38
|
+
|
|
39
|
+
Syck runs at about:
|
|
40
|
+
|
|
41
|
+
50-60% of the speed of Ruby's Marshal.
|
|
42
|
+
65-90% of the speed of PHP's deserialize().
|
|
43
|
+
600% of the speed of Python's Pickle.
|
|
44
|
+
50-60% of the speed of Python's cPickle.
|
|
45
|
+
|
|
46
|
+
(Based on various types of structured data.)
|
|
47
|
+
|
|
48
|
+
installation: >
|
|
49
|
+
|
|
50
|
+
Syck contains working extensions for the Ruby, PHP, and Python
|
|
51
|
+
languages. Each requires compilation of the libsyck library,
|
|
52
|
+
followed by compilation of the extension.
|
|
53
|
+
|
|
54
|
+
To compile libsyck, first download libsyck.
|
|
55
|
+
|
|
56
|
+
tar xzvf syck-0.54.tar.gz
|
|
57
|
+
cd syck-0.54
|
|
58
|
+
./configure
|
|
59
|
+
make
|
|
60
|
+
sudo make install
|
|
61
|
+
|
|
62
|
+
To install the Ruby extension:
|
|
63
|
+
|
|
64
|
+
cd ext/ruby
|
|
65
|
+
ruby install.rb config
|
|
66
|
+
ruby install.rb setup
|
|
67
|
+
sudo ruby install.rb install
|
|
68
|
+
|
|
69
|
+
To install the Python extension:
|
|
70
|
+
|
|
71
|
+
cd ext/python
|
|
72
|
+
python setup.py build
|
|
73
|
+
sudo python setup.py install
|
|
74
|
+
|
|
75
|
+
To install the PHP extension:
|
|
76
|
+
|
|
77
|
+
sh make_module.sh
|
|
78
|
+
sudo make install (if you weren't root during make_module.sh)
|
|
79
|
+
php -q syck.php
|
|
80
|
+
|
|
81
|
+
examples:
|
|
82
|
+
|
|
83
|
+
To load this document in Ruby: |
|
|
84
|
+
|
|
85
|
+
($:~)$ irb
|
|
86
|
+
>> require 'yaml'
|
|
87
|
+
=> true
|
|
88
|
+
>> YAML::load( File.open( 'RELEASE' ) )
|
|
89
|
+
=> {"status"=>"Syck is about 60% compliant ..."}
|
|
90
|
+
|
|
91
|
+
To load this document in PHP: |
|
|
92
|
+
|
|
93
|
+
($:~)$ php -a
|
|
94
|
+
Interactive mode enabled
|
|
95
|
+
|
|
96
|
+
<? dl( 'syck.so' ); print_r( syck_load( implode( '', file( 'RELEASE' ) ) ) ); ?>
|
|
97
|
+
|
|
98
|
+
.. php then outputs ..
|
|
99
|
+
|
|
100
|
+
X-Powered-By: PHP/4.2.3
|
|
101
|
+
Content-type: text/html
|
|
102
|
+
|
|
103
|
+
Array
|
|
104
|
+
(
|
|
105
|
+
[released] => Array
|
|
106
|
+
(
|
|
107
|
+
[name] => Syck
|
|
108
|
+
[version] => 0.54
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
.. and so on ..
|
|
112
|
+
|
|
113
|
+
To load this document in Python: |
|
|
114
|
+
|
|
115
|
+
($:~)$ python
|
|
116
|
+
Python 2.1.3 (#1, Jul 11 2002, 17:52:24)
|
|
117
|
+
[GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4
|
|
118
|
+
Type "copyright", "credits" or "license" for more information.
|
|
119
|
+
>>> import syck
|
|
120
|
+
>>> f = open( 'RELEASE' )
|
|
121
|
+
>>> syck.load( f.read() )
|
|
122
|
+
{'by': 'why the lucky stiff', ... }
|
|
123
|
+
|