Compare commits

...

43 Commits

Author SHA1 Message Date
Tina Müller
840b65c406 Fix closing flow sequence after explicit key
The fix in #295 was not correct.

    # cat a.yaml
    ---
    [?]

    # Before
    % ./tests/run-parser-test-suite --flow keep < a.yaml
    +STR
    +DOC ---
    +SEQ []
    +MAP {}
    -SEQ
    -DOC
    -STR

    % ./tests/run-loader a.yaml
    [1] Loading 'a.yaml': run-loader: loader.c:470: yaml_parser_load_sequence_end: Assertion `parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE' failed.
    [1]    21446 IOT instruction (core dumped)  ./tests/run-loader a.yaml

    # After
    % ./tests/run-parser-test-suite --flow keep < a.yaml
    +STR
    +DOC ---
    +SEQ []
    +MAP {}
    =VAL :
    =VAL :
    -MAP
    -SEQ
    -DOC
    -STR

    % ./tests/run-loader a.yaml
    [1] Loading 'a.yaml': SUCCESS (1 documents)
2024-05-20 04:21:56 +02:00
Tina Müller
588eabff23 Handle closing flow sequence after explicit key
Currently after an explicit flow key '?' in a flow sequence, an immediately
following closing ] is ignored by the parser:

    % echo '[ ? ]' | ./tests/run-parser-test-suite --flow keep
    +STR
    +DOC
    +SEQ []
    +MAP {}
    =VAL :
    =VAL :
    -MAP
    Parse error: did not find expected ',' or ']'
    Line: 2 Column: 1
    % echo '[ ? ] ]' | ./tests/run-parser-test-suite --flow keep
    +STR
    +DOC
    +SEQ []
    +MAP {}
    =VAL :
    =VAL :
    -MAP
    -SEQ
    -DOC
    -STR

It is read correctly by the scanner as a YAML_FLOW_SEQUENCE_END_TOKEN, and
the flow_level is decreased. Then it is passed to the parser where it gets
ignored.
This leads to invalid YAML being accepted, and valid YAML resulting in an
error.

Also the flow_level is incorrectly decreased, so you can nest sequences
like that without running in to the MAX_NESTING_LEVEL.
2024-05-06 19:19:08 +02:00
Tina Müller
abd744ec2f ci: Install libtool on macOS
configure.ac:56: error: possibly undefined macro: AC_PROG_LIBTOOL
2024-04-28 17:59:32 +02:00
Ryuta Kamizono
1e66c1e13a Fix some typos 2024-04-08 18:33:30 +02:00
Tina Müller
51843fe482 Limit depth of nesting by default
Each nesting level increases the stack and the number of previous
starting events that the parser has to check.

The default maximum is 1000 and can be set via yaml_set_max_nest_level()

I also added new options to run-parser and run-parser-test-suite:
* --max-level: you can now try out this feature on the command line
* --show-error: By default, run-parser doesn't show errors. The new option
  helps with debugging
2024-04-08 18:12:59 +02:00
Tina Müller
fb57d89c04 Update Github actions 2024-04-02 00:57:46 +02:00
Tina Müller (tinita)
f8f760f738
ci: Fix build on macOS (#230)
add-path was deprecated, see
https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
2021-11-10 18:03:02 +01:00
Tina Müller
acd6f6f014 Add workflow for creating release tarballs
Also minor cleanup of .github/workflows/main.yml
2020-06-22 10:21:14 -07:00
Tina Müller
2c891fc7a7 Changes for v0.2.5 release 2020-06-01 23:19:50 +02:00
Ingy döt Net
d12ce2aa88 Allow test suite runner to come from a different repo 2020-06-01 21:52:12 +02:00
Ingy döt Net
00780e83d2
A couple patches to improve test suite support (#191)
* Need newer bash and make for Macos testing

* Allow override of the run-test-suite branch
2020-06-01 21:33:39 +02:00
Tina Müller (tinita)
1008696708
Allow question marks in plain scalars in flow collections (#105)
See http://yaml.org/spec/1.1/#id907281

The question mark isn't mentioned as something special here, only
,[]{}

This commit will allow

[foo?bar]
[foo ? bar]

The PR does only change the behaviour when the question mark is in the middle or
at the end of the string, not at the beginning, e.g. [?foo] is handled by
a different part of the code.
2020-06-01 21:28:43 +02:00
Tina Müller (tinita)
7eb01976a0
Emitter: Don't output trailing space for empty scalar nodes (#186)
See issue #46

Passing emitter tests:
* 2XXW: Spec Example 2.25. Unordered Sets
* 5WE3: Spec Example 8.17. Explicit Block Mapping Entries
* 6KGN: Anchor for empty node
* 6XDY: Two document start markers
* 7W2P: Block Mapping with Missing Values
* 8KB6: Multiline plain flow mapping key without value
* 9BXH: Multiline doublequoted flow mapping key without value
* C2DT: Spec Example 7.18. Flow Mapping Adjacent Values
* JTV5: Block Mapping with Multiline Scalars
* KK5P: Various combinations of explicit block mappings
* LE5A: Spec Example 7.24. Flow Nodes
* UT92: Spec Example 9.4. Explicit Documents
* W42U: Spec Example 8.15. Block Sequence Entry Types
* W4TN: Spec Example 9.5. Directives Documents
* ZWK4: Key with anchor after missing explicit mapping value
2020-06-01 16:41:23 +02:00
Tina Müller (tinita)
6e2fa9786a
Emitter: Output space after an alias mapping key (#185)
Before:
    a: &b x
    *b: c

Now:
    a: &b x
    *b : c

Passing tests:
* 26DV: Whitespace around colon in mappings
* E76Z: Aliases in Implicit Block Mapping
* X38W: Aliases in Flow Objects

Test manually because `make test-suite` will overwrite changes in the skiplist:

    ./tests/run-parser-test-suite tests/run-test-suite/data/26DV/in.yaml | ./tests/run-emitter-test-suite
    ./tests/run-parser-test-suite tests/run-test-suite/data/E76Z/in.yaml | ./tests/run-emitter-test-suite
    ./tests/run-parser-test-suite tests/run-test-suite/data/X38W/in.yaml | ./tests/run-emitter-test-suite

Or edit tests/run-test-suite/test/blacklist/libyaml-emitter and do:

    (cd tests/run-test-suite; prove -lv test)

Also I added some newlines to yaml.h to help identifying states by number.
2020-06-01 11:55:55 +02:00
Tina Müller (tinita)
f41d3600d6 Flow indicators can not be part of local or shorthand tags (#179)
Spec: https://yaml.org/spec/1.2/spec.html#ns-tag-char
Test: https://github.com/yaml/yaml-test-suite/blob/master/test/WZ62.tml
2020-06-01 00:50:31 +02:00
Tina Müller (tinita)
cf53b3b5f9
Add -h and --flow (on|off|keep) to run-*-test-suite (#187)
With `--flow (keep|on)` run-parser-test-suite will output:

    +MAP {}
    +SEQ []

run-emitter-test-suite will then emit flow style collections if requested:

    echo 'foo: [bar, {x: y}]' | ./tests/run-parser-test-suite | ./tests/run-emitter-test-suite
    echo 'foo: [bar, {x: y}]' | ./tests/run-parser-test-suite \
        --flow keep | ./tests/run-emitter-test-suite --flow keep

Also: add that yaml_private.h include again that I had thrown out. Needed
for printing directives.
Wonder if there is a way to create a directive without using the private api.
2020-06-01 00:47:25 +02:00
Tina Müller (tinita)
9deee01508
Use GitHub Actions (#184) 2020-05-29 21:39:56 +02:00
Tina Müller
0032321756 Remove unnecessary include and malloc 2020-05-21 18:10:59 +02:00
Tina Müller
ce8357938c Add specific files back to .gitignore
Seems this was an oversight in d050fe3f3006b55edf33a2ef91019a67d6c3fb10.
We don't want to ignore all those file, but only the compiled executables.

Also added '/' to several files.
2020-05-21 18:04:15 +02:00
Tina Müller
fec20d3fe6 Output error position in run-parser-test-suite.c 2020-05-21 14:50:20 +02:00
Tina Müller
72e2f75277 Changes for v0.2.4 release 2020-04-19 13:15:10 +02:00
Tina Müller
3694a4af7d Fix logic for document end before directive
open_ended can have three states now:
0: The previous document was ended explicitly with '...'
1: The previous document wasn't ended with '...'
2: The last scalar event was a block scalar with trailing empty lines |+, and
   last document wasn't ended with '...'.
   Important at stream end.

This was broken in the past, and fixed in fa1293a.
With my last PR #162 I added the faulty behaviour again.

The problematic behaviour showed only when all of the following conditions were
true:
* writing YAML directives
* writing unquoted top level scalars
* writing more than one document

================== BROKEN ==============================

The first example shows that the document end marker is not emitted before
the next document. This would be valid in YAML 1.1 if the scalar was quoted,
but not if it is plain.

This commit fixes this.

echo '--- foo
--- bar
' | ./tests/run-parser-test-suite  | ./tests/run-emitter-test-suite  --directive 1.1

%YAML 1.1
--- foo
%YAML 1.1
--- bar

================== FIXED ==============================

echo '--- foo
--- bar
' | ./tests/run-parser-test-suite  | ./tests/run-emitter-test-suite  --directive 1.1
%YAML 1.1
--- foo
...
%YAML 1.1
--- bar

=======================================================

Other examples which should look like this (and were correct already before
this fix):

Open ended scalars like |+ need '...' at the end of the stream:

echo '--- |+
  a

--- |+
  a

' | ./tests/run-parser-test-suite  | ./tests/run-emitter-test-suite
--- |+
  a

--- |+
  a

...

=======================================================

If a document is ended with an explicit '...', the code should not
print '...' twice:

echo '--- foo
...
--- bar
' | ./tests/run-parser-test-suite  | ./tests/run-emitter-test-suite --directive 1.1
%YAML 1.1
--- foo
...
%YAML 1.1
--- bar

==========================================================
2020-04-19 12:47:41 +02:00
Tina Müller
4e5cea6419 Allow emitting 1.2 directive
Before `1.1` was hardcoded in the emitter.

* Also add --directive option to run-emitter-test-suite
  Allows to easily test how output looks like if %YAML directives
  are output.
2020-04-19 12:47:41 +02:00
Tina Müller (tinita)
47bf3f086f
Add packaging/docker-dist to Makefile.am (#143) 2020-04-19 12:36:01 +02:00
Tina Müller
bf52902899 Changes for v0.2.3 release 2020-04-11 19:08:22 +02:00
Mark Sheahan
a1dc7861f8 Change dllexport controlling macro to use _WIN32
(provided by msvc compiler) instead of WIN32 (which is user configurable, and
omitted by default on some x64 builds); this fixes an issue with 64 bit windows
static library builds (#66)

Co-authored-by: Mark Sheahan <mark.sheahan@upguard.com>
2020-04-11 16:10:50 +02:00
Tina Müller (tinita)
3d5b7e65db
Support %YAML 1.2 directives (#172)
This will simply allow `%YAML 1.2` directives additionally to `%YAML 1.1`.
There is no change in behaviour.

See also #20

No changes are needed regarding tag directives.

In YAML 1.2 tag directives are for the following document only.
This is already implemented like that in libyaml.

We would rather have to fix the code if we want to have the correct behaviour
(global directives) in YAML 1.1. This would be a bit more complicated, as we
would have to save the default version and the current version in the parser
object.

New passing parser tests:

* 27NA: Spec Example 5.9. Directive Indicator
* 6ZKB: Spec Example 9.6. Stream
* 9DXL: Spec Example 9.6. Stream [1.3]
* RTP8: Spec Example 9.2. Document Markers

New failing error parser tests (before they were errors for the wrong reason):

* EB22: Missing document-end marker before directive
* RHX7: YAML directive without document end marker
2020-04-10 21:45:15 +02:00
Michael Drake
1b5bac0d3d
Avoid recursion in the document loader. (#127)
The document loading API (yaml_parser_load) was susseptable to a
stack overflow issue when given input data which opened many
mappings and/or sequences without closing them.

This was due to the use of recurion in the implementation.

With this change, we avoid recursion, and maintain our own loader
context stack on the heap.

The loader context contains a stack of document node indexes.
Each time a sequence or mapping start event is encountered,
the node index corrasponding to the event is pushed to the
stack.  Each time a sequence or mapping end event is encountered,
the corrasponding node's index is popped from the stack.

The yaml_parser_load_nodes() function sits on the event stream,
issuing events to the appropriate handlers by type.

When an event handler function constructs a node, it needs to
connect the new node to its parent (unless it's the root node).
This is where the loader context stack is used to find the
parent node.  The way that the new node is added to the tree
depends on whether the parent node is a mapping (with a
yaml_node_pair_t to fill), or a sequence (with a yaml_node_item_t).

Fixes: https://github.com/yaml/libyaml/issues/107
2020-04-10 21:30:28 +02:00
Ashutosh Chauhan
d0cb513b33
Fix missing token in example (#169) 2020-04-10 21:28:01 +02:00
Junde Yhi
e0b9e42d82
include/yaml.h: fix comments (#155)
* include/yaml.h: fix indentation of comments

* include/yaml.h: fix documentation style comment

* include/yaml.h: fix doc command returns

* include/yaml.h: fix typo
2020-03-28 18:17:28 +01:00
Liao Tonglang
9f9e4a29b7
Change cmake target name from libOFF.a to libyaml.a (#157)
option can only be ON or OFF. Use set() instead of option() to set default name of target.
2020-03-28 18:12:22 +01:00
Tina Müller (tinita)
fa1293a11f
Output document end marker after open ended scalars (#162) 2020-03-28 18:06:58 +01:00
Tina Müller
9afa10a8b0 Always output document end before directive (YAML 1.2 compatibility)
In YAML 1.1, the document end marker `...` is optional even if the next document starts with a directive:
https://github.com/yaml/pyyaml/blob/master/tests/data/spec-07-09.canonical
```
%YAML 1.1
---
!!str "foo"
%YAML 1.1
---
!!str "bar"
%YAML 1.1
---
!!str "baz"
```
It is only required if the scalar is "open ended", for example for plain scalars.

In YAML 1.2 the `...` marker is always required before a directive.

My suggestion would be to make the output 1.2 compatible. It will still be 1.1 compatible, so that shouldn't be a problem.

I believe this will also make it easier to fix #123 which was introduced with the last fixes regarding `open_ended`. I think I can make a fix for this soon after this issue is fixed.
Fixing #123 without this would be a bit more complicated.

If we do this, we also need to adjust PyYAML to behave the same.

Related issues/commits:
- https://github.com/yaml/libyaml/issues/60
- https://github.com/yaml/libyaml/pull/122
- 56400d9, 8ee83c0, 56f4b17
2020-03-26 22:28:39 +01:00
Tina Müller (tinita)
21429b031f Add CHANGES file (#159) 2020-03-26 22:24:32 +01:00
Ingy döt Net
42a370d6b0 Move appveyor.yml to .appveyor.yml 2020-03-26 22:20:56 +01:00
Ingy döt Net
94ecadc50e Makefile test-suite rule builds libyaml first 2019-12-21 11:11:26 -08:00
HonkingGoose
53f5b86823 Fix spelling 2019-07-25 11:59:16 +02:00
Michael Drake
aa2e89362f Squash a couple of warnings in example-deconstructor-alt
example-deconstructor-alt.c: In function ‘main’:
example-deconstructor-alt.c:649:51: warning:
  comparison between ‘yaml_sequence_style_t {aka enum yaml_sequence_style_e}’
  and ‘enum yaml_mapping_style_e’ [-Wenum-compare]

example-deconstructor-alt.c:650:36: warning:
  comparison between ‘yaml_sequence_style_t {aka enum yaml_sequence_style_e}’
  and ‘enum yaml_mapping_style_e’ [-Wenum-compare]
2019-06-06 20:20:58 +02:00
criptych
a21fc21697 Use pointer to const for strings that aren't/shouldn't be modified 2019-06-06 19:25:18 +02:00
林博仁(Buo-ren Lin)
b4ca139010 Fix typo in comment
s/intendation/indentation/

Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
2019-06-06 19:11:29 +02:00
SHIBATA Hiroshi
567353cee9 Fixed typo. 2019-06-06 19:08:57 +02:00
Tina Mueller
641adbf244 Fix typo in README 2019-06-06 15:28:02 +02:00
Tina Mueller
fce3597003 Add required packages to README 2019-06-06 14:52:59 +02:00
33 changed files with 1337 additions and 264 deletions

View File

@ -1,4 +1,4 @@
version: 0.2.2.{build}
version: 0.2.5.{build}
image:
- Visual Studio 2015

28
.github/workflows/dist.yaml vendored Normal file
View File

@ -0,0 +1,28 @@
name: dist
on:
push:
branches: [ release/* ]
jobs:
dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: env | sort
- name: Get image
run: |
time docker pull yamlio/libyaml-dev
docker images | grep libyaml
- run: |
make -C pkg/docker libyaml-dist-ci
ls -l pkg/docker/output
- uses: actions/upload-artifact@v2
with:
name: release
path: pkg/docker/output/yaml-0*

54
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,54 @@
name: linux/mac
on:
push:
branches: [ '*' ]
pull_request:
branches: [ master ]
jobs:
build:
env:
CC: ${{ matrix.compiler }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
compiler:
- gcc
- clang
os:
- ubuntu-latest
- macOS-latest
steps:
- uses: actions/checkout@v4
- run: env | sort
- name: Install software
if: ${{ matrix.os == 'macOS-latest' }}
run: |
brew install automake bash coreutils make libtool
echo "/usr/local/opt/coreutils/libexec/gnubin" >> $GITHUB_PATH
echo "/usr/local/opt/make/libexec/gnubin" >> $GITHUB_PATH
- name: Fetch branches
run: |
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch --unshallow
- run: ./bootstrap
- run: ./configure
- run: make
- run: make test-all
- run: |
git clean -d -x -f
rm -fr tests/run-test-suite
git worktree prune
- name: Compiler version
run: ${{ matrix.compiler }} --version
- run: cmake .
- run: make
- run: make test

31
.gitignore vendored
View File

@ -14,21 +14,32 @@
.deps/
.libs/
/Testing/
libtool
/libtool
CMakeCache.txt
CMakeFiles/
GNUmakefile
Makefile
Makefile.in
aclocal.m4
autom4te.cache
config
/aclocal.m4
/autom4te.cache
/config
config.h*
config.status
configure
example-deconstructor*
example-reformatter*
run*
/config.status
/configure
stamp-h1
test-*
!config/config.h.in
/tests/run-dumper
/tests/run-emitter
/tests/run-emitter-test-suite
/tests/run-loader
/tests/run-parser
/tests/run-parser-test-suite
/tests/run-scanner
/tests/example-deconstructor
/tests/example-deconstructor-alt
/tests/example-reformatter
/tests/example-reformatter-alt
/tests/run-test-suite
/tests/test-reader
/tests/test-version
/dist/

View File

@ -23,6 +23,8 @@ MAKE_TARGETS := \
all \
all-am \
all-recursive \
docker-build \
docker-dist \
install \
test \
test-all \

View File

@ -18,6 +18,7 @@ before_install:
# Travis branch-specific clone problem workaround:
- git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
- git fetch
- env | sort
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
pip install --user scikit-ci-addons==0.15.0;

View File

@ -4,11 +4,11 @@ project (yaml C)
set (YAML_VERSION_MAJOR 0)
set (YAML_VERSION_MINOR 2)
set (YAML_VERSION_PATCH 2)
set (YAML_VERSION_PATCH 5)
set (YAML_VERSION_STRING "${YAML_VERSION_MAJOR}.${YAML_VERSION_MINOR}.${YAML_VERSION_PATCH}")
option(BUILD_SHARED_LIBS "Build libyaml as a shared library" OFF)
option(YAML_STATIC_LIB_NAME "base name of static library output" yaml)
set(YAML_STATIC_LIB_NAME "yaml" CACHE STRING "Base name of static library output")
#
# Output directories for a build tree

372
Changes Normal file
View File

@ -0,0 +1,372 @@
0.2.5 2020-06-01
https://github.com/yaml/libyaml/pull/105
Allow question marks in plain scalars in flow collections
https://github.com/yaml/libyaml/pull/186
Emitter: Don't output trailing space for empty scalar nodes
https://github.com/yaml/libyaml/pull/185
Emitter: Output space after an alias mapping key
https://github.com/yaml/libyaml/pull/187
Add -h and --flow (on|off|keep) to run-*-test-suite
https://github.com/yaml/libyaml/pull/182
Remove unnecessary include and malloc
https://github.com/yaml/libyaml/pull/177
Add specific files back to .gitignore
https://github.com/yaml/libyaml/pull/181
Output error position in run-parser-test-suite.c
https://github.com/yaml/libyaml/pull/191
A couple patches to improve test suite support
0.2.4 2020-04-19
- https://github.com/yaml/libyaml/pull/143
Add packaging/docker-dist to Makefile.am
- https://github.com/yaml/libyaml/pull/174
Fix logic for document end before directive
0.2.3 2020-04-11
- https://github.com/yaml/libyaml/pull/130
Fixed typo.
- https://github.com/yaml/libyaml/pull/144
Fix typo in comment
- https://github.com/yaml/libyaml/pull/140
Use pointer to const for strings that aren't/shouldn't be modified
- https://github.com/yaml/libyaml/pull/128
Squash a couple of warnings in example-deconstructor-alt
- https://github.com/yaml/libyaml/pull/151
Fix spelling for error message
- https://github.com/yaml/libyaml/pull/161
Make appveyor config be a hidden file
- https://github.com/yaml/libyaml/pull/159
Add CHANGES file
- https://github.com/yaml/libyaml/pull/160
Always output document end before directive (YAML 1.2 compatibility)
- https://github.com/yaml/libyaml/pull/162
Output document end marker after open ended scalars
- https://github.com/yaml/libyaml/pull/157
change cmake target name from libOFF.a to libyaml.a
- https://github.com/yaml/libyaml/pull/155
include/yaml.h: fix comments
- https://github.com/yaml/libyaml/pull/169
Fixed missing token in example
- https://github.com/yaml/libyaml/pull/127
Avoid recursion in the document loader.
- https://github.com/yaml/libyaml/pull/172
Support %YAML 1.2 directives
- https://github.com/yaml/libyaml/pull/66
Change dllexport controlling macro to use _WIN32
0.2.2 2019-03-12
- https://github.com/yaml/libyaml/pull/95
build: do not install config.h
- https://github.com/yaml/libyaml/pull/97
appveyor.yml: fix Release build
- https://github.com/yaml/libyaml/pull/103
Remove unused code in yaml_document_delete
- https://github.com/yaml/libyaml/pull/104
Allow colons in plain scalars inside flow collections
- https://github.com/yaml/libyaml/pull/109
Fix comparison in tests/run-emitter.c
- https://github.com/yaml/libyaml/pull/117
Fix typo error
- https://github.com/yaml/libyaml/pull/119
The closing single quote needs to be indented...
- https://github.com/yaml/libyaml/pull/121
fix token name typos in comments
- https://github.com/yaml/libyaml/pull/122
Revert removing of open_ended after top level plain scalar
- https://github.com/yaml/libyaml/pull/125
Cherry-picks from PR 27
- https://github.com/yaml/libyaml/pull/135
Windows/C89 compatibility
- https://github.com/yaml/libyaml/pull/136
allow override of Windows static lib name
0.2.1 2018-06-24
- https://github.com/yaml/libyaml/pull/10
Support static and dynamic libraries
- https://github.com/yaml/libyaml/pull/12
Use .gitignore instead of .hgignore
- https://github.com/yaml/libyaml/pull/13
Add support for `make test` and travis
- https://github.com/yaml/libyaml/pull/14
Dockerfile for testing
- https://github.com/yaml/libyaml/pull/15
Apply old fix for `\/` that is not in master.
- https://github.com/yaml/libyaml/pull/17
Update license to include all years until now.
- https://github.com/yaml/libyaml/pull/18
Port bug fix from Perl binding
- https://github.com/yaml/libyaml/pull/22
Fix misspell: preceed
- https://github.com/yaml/libyaml/pull/23
Removed trailing-whitespaces
- https://github.com/yaml/libyaml/pull/24
Fix typo
- https://github.com/yaml/libyaml/pull/25
added an examples directory with a few yaml examples
- https://github.com/yaml/libyaml/pull/26
Added missing Cflags path in pkg-config file
- https://github.com/yaml/libyaml/pull/31
add unit tests to cmake configuration
- https://github.com/yaml/libyaml/pull/32
Include an example of a custom tag from Python
- https://github.com/yaml/libyaml/pull/33
Include an example of a %YAML tag
- https://github.com/yaml/libyaml/pull/34
Added an example of using a global tag
- https://github.com/yaml/libyaml/pull/36
Fix -Wformat compilation errors in tests
- https://github.com/yaml/libyaml/pull/37
Update bug report URL in LibYAML
- https://github.com/yaml/libyaml/pull/38
Use AM_CPPFLAGS since autotools deprecated INCLUDE
- https://github.com/yaml/libyaml/pull/39
Update bug report URL in README
- https://github.com/yaml/libyaml/pull/41
Add travis and Makefile support for libyaml-test
- https://github.com/yaml/libyaml/pull/43
Add Dockerfile for Fedora 25
- https://github.com/yaml/libyaml/pull/44
WIP: Enable all warnings (-Wall) in libyaml and tests
- https://github.com/yaml/libyaml/pull/45
Fix typo
- https://github.com/yaml/libyaml/pull/47
Move travis script guts to separate file
- https://github.com/yaml/libyaml/pull/48
`yaml/libyaml-test` should become part of `yaml/libyaml`
- https://github.com/yaml/libyaml/pull/50
Add a GNUMakefile for immediate make targets
- https://github.com/yaml/libyaml/pull/53
Switch from test blacklist to whitelist
- https://github.com/yaml/libyaml/pull/55
Update defs for MingGW support on Windows
- https://github.com/yaml/libyaml/pull/58
Improve CMakeLists
- https://github.com/yaml/libyaml/pull/64
README: Update libyaml link
- https://github.com/yaml/libyaml/pull/69
Skip 5 tests in libyaml-emitter.list
- https://github.com/yaml/libyaml/pull/74
Forbid escaped singlequote in doublequotes
- https://github.com/yaml/libyaml/pull/76
Rewrite make test-suite
- https://github.com/yaml/libyaml/pull/77
Undefined PTRDIFF_MAX on HP-UX
- https://github.com/yaml/libyaml/pull/78
Fixed most compiler warnings -Wall -Wextra
- https://github.com/yaml/libyaml/pull/82
Move yaml-test-suite integration onto a separate branch.
- https://github.com/yaml/libyaml/pull/86
Fix problems in CI failures (travis and semaphore)
- https://github.com/yaml/libyaml/pull/87
appveyor.yml: add mingw-w64 builds
- https://github.com/yaml/libyaml/pull/88
add -no-undefined to src/Makefile.am
- https://github.com/yaml/libyaml/pull/89
Added alpine linux testing to dockerfiles
- https://github.com/yaml/libyaml/pull/93
remove need for PTRDIFF_MAX
- https://github.com/yaml/libyaml/pull/94
.gitignore: major cleanup
- https://github.com/yaml/libyaml/pull/120
Fix doc.
0.1.7 2016-08-27
- Fixed segfault in yaml_string_write_handler.
- Fixed invalid simple key assertion.
- Fixed error handling in some examples (thank to Mathias Svensson).
- Removed obsolete VS project files.
0.1.6 2014-03-26
- https://github.com/yaml/libyaml/commit/d1003a9
Fixed heap overflow in yaml_parser_scan_uri_escapes (Thanks
Ivan Fratric of the Google Security Team).
- https://github.com/yaml/libyaml/commit/662f4be
Added tag 0.1.5 for changeset a5142b24428b
0.1.5 2014-02-03
- https://github.com/yaml/libyaml/commit/303b455
Manually define PTRDIFF_MAX for VS C compiler.
- https://github.com/yaml/libyaml/commit/1ef1171
Forgot to set the error state.
- https://github.com/yaml/libyaml/commit/c9479c7
Limit input size to SIZE_MAX/2.
- https://github.com/yaml/libyaml/commit/c201bf6
Guard against overflows in indent and flow_level.
- https://github.com/yaml/libyaml/commit/bb8ab82
Added .hgignore.
- https://github.com/yaml/libyaml/commit/2d94fc5
Prevent node index overflow (Reported by Florian Weimer).
- https://github.com/yaml/libyaml/commit/df33f25
Bumped the version number.
- https://github.com/yaml/libyaml/commit/f56726b
Fixed invalid size_t->int cast (Thank to Florian Weimer).
- https://github.com/yaml/libyaml/commit/01e8dad
Added a basic CMake project.
- https://github.com/yaml/libyaml/commit/f54fc40
Added tag 0.1.4 for changeset 3e6507fa0c26
0.1.4 2012-12-24
- Fixed a bug that prevented an empty mapping being used as a simple key
(thank to spitzak(at)rhythm(dot)com).
- Fixed pointer overflow when calculating the position of a potential
simple key (thank to ppelletier(at)oblong(dot)com).
- Fixed yaml.dll not exporting any symbols
(thank to pxn11432(at)nifty(dot)com).
- Added pkg-config support (thank to rainwoodman(at)gmail(dot)com).
0.1.3 2009-08-29
- This release fixes non-standard structure initialization and
a streaming-related issue.
0.1.2 2008-12-27
- Minor bugfix release
0.1.1 2006-08-01
- https://github.com/yaml/libyaml/commit/5e52c31
Fixed a problem when the DOCUMENT-END event is not emitted until
the beginning of the next document is available. Fixed #51.
Thanks edward(at)sweetbytes.net for the bug report.
- https://github.com/yaml/libyaml/commit/dd71484
Add project files for Visual Studio 2003.
- https://github.com/yaml/libyaml/commit/ce8a93e
Fix the example_deconstructor project.
- https://github.com/yaml/libyaml/commit/c9b74de
Eliminate some warnings and add more doxygen definitions.
- https://github.com/yaml/libyaml/commit/0122490
Undefine the NDEBUG directive for the test programs.
- https://github.com/yaml/libyaml/commit/071329a
Fix a bug in the emitter introduced while fixing warnings for VC6.
- https://github.com/yaml/libyaml/commit/6f6bbb8
Add VC6 projects for the test executables.
- https://github.com/yaml/libyaml/commit/0174ed6
Add win32 fixes and project files for VC6.
- https://github.com/yaml/libyaml/commit/e27a3c8
Add functions for constructing, parsing and emitting YAML documents.
- https://github.com/yaml/libyaml/commit/a907bf8
Add `const` qualifier for `yaml_parser_set_input_string` parameter `input`.
- https://github.com/yaml/libyaml/commit/c83b67a
Force a new line at the end of the input stream even if there
are no a new line character. This fixes a nasty bug when libyaml hangs on
documents like `[[[[`. Thanks ciaranm for reporting the bug.
- https://github.com/yaml/libyaml/commit/609cce0
Older versions of gcc do not know about -Wno-pointer-sign.
0.0.1 2006-08-01
- Initial release

View File

@ -1,4 +1,4 @@
Copyright (c) 2017-2019 Ingy döt Net
Copyright (c) 2017-2020 Ingy döt Net
Copyright (c) 2006-2016 Kirill Simonov
Permission is hereby granted, free of charge, to any person obtaining a copy of

View File

@ -3,7 +3,11 @@
SUBDIRS = include src . tests
EXTRA_DIST = README LICENSE CMakeLists.txt doc/doxygen.cfg
EXTRA_DIST = Changes ReadMe.md License CMakeLists.txt doc/doxygen.cfg
LIBYAML_TEST_SUITE_RUN_REPO_DEFAULT := https://github.com/yaml/libyaml
LIBYAML_TEST_SUITE_RUN_REPO ?= $(LIBYAML_TEST_SUITE_RUN_REPO_DEFAULT)
LIBYAML_TEST_SUITE_RUN_BRANCH ?= run-test-suite
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = yaml-0.1.pc
@ -25,12 +29,23 @@ bootstrap: maintainer-clean
test: all
make -C tests check-TESTS
test-suite: tests/run-test-suite
test-suite: tests/run-test-suite all
make -C $< test
test-all: test test-suite
tests/run-test-suite:
-git branch --track run-test-suite origin/run-test-suite
-git worktree prune
git worktree add $@ run-test-suite
ifeq ($(LIBYAML_TEST_SUITE_RUN_REPO),$(LIBYAML_TEST_SUITE_RUN_REPO_DEFAULT))
-git branch --track $(LIBYAML_TEST_SUITE_RUN_BRANCH) origin/$(LIBYAML_TEST_SUITE_RUN_BRANCH)
-git worktree prune
git worktree add $@ $(LIBYAML_TEST_SUITE_RUN_BRANCH)
else
git clone --branch $(LIBYAML_TEST_SUITE_RUN_BRANCH) $(LIBYAML_TEST_SUITE_RUN_REPO) $@
endif
docker-build:
make -C pkg/docker build
docker-dist:
make -C pkg/docker libyaml-dist

32
README
View File

@ -1,32 +0,0 @@
LibYAML - A C library for parsing and emitting YAML.
To build and install the library, run:
$ ./configure
$ make
# make install
If you checked the source code from the Git repository, run
$ ./bootstrap
$ ./configure
$ make
# make install
For more information, check the LibYAML homepage:
'https://github.com/yaml/libyaml'.
Discuss LibYAML with the maintainers in IRC #libyaml irc.freenode.net.
You may also use the YAML-Core mailing list:
'http://lists.sourceforge.net/lists/listinfo/yaml-core'.
Submit bug reports and feature requests to the LibYAML bug tracker:
'https://github.com/yaml/libyaml/issues/new'.
This project was developed for Python Software Foundation as a part of Google
Summer of Code under the mentorship of Clark Evans.
The LibYAML module was written by Kirill Simonov <xi@resolvent.net>.
It is currently maintained by the YAML community.
LibYAML is released under the MIT license.
See the file LICENSE for more details.

46
ReadMe.md Normal file
View File

@ -0,0 +1,46 @@
## LibYAML - A C library for parsing and emitting YAML.
To build and install the library, run:
$ ./configure
$ make
# make install
Required packages:
- gcc
- libtool
- make
If you checked the source code from the Git repository, run
$ ./bootstrap
$ ./configure
$ make
# make install
Required packages:
- autoconf
- libtool
- make
For more information, check the [LibYAML
homepage](https://github.com/yaml/libyaml).
Discuss LibYAML with the maintainers in IRC #libyaml irc.freenode.net.
You may also use the [YAML-Core mailing
list](http://lists.sourceforge.net/lists/listinfo/yaml-core).
Submit bug reports and feature requests to the [LibYAML bug
tracker](https://github.com/yaml/libyaml/issues/new).
This project was developed for Python Software Foundation as a part of Google
Summer of Code under the mentorship of Clark Evans.
The LibYAML module was written by Kirill Simonov <xi@resolvent.net>.
It is currently maintained by the YAML community.
LibYAML is released under the MIT license.
See the file LICENSE for more details.

View File

@ -1,13 +1,13 @@
From: Ingy döt Net <ingy@ingy.net>
From: Tina Müller <post@tinita.de>
To: yaml-core@lists.sourceforge.net
Subject: [ANN] LibYAML-0.2.2: A new release
Subject: [ANN] LibYAML-0.2.5: A new release
=========================
Announcing LibYAML-0.2.2
Announcing LibYAML-0.2.5
=========================
A new release of LibYAML is now available:
https://github.com/yaml/libyaml/tree/0.2.2
https://github.com/yaml/libyaml/tree/0.2.5
The LibYAML project is now maintained by the YAML community. Planning happens
on the #yaml-dev and #libyaml IRC channels on irc.freenode.net.
@ -16,19 +16,30 @@ on the #yaml-dev and #libyaml IRC channels on irc.freenode.net.
Changes
=======
* https://github.com/yaml/libyaml/pull/95 -- build: do not install config.h
* https://github.com/yaml/libyaml/pull/97 -- appveyor.yml: fix Release build
* https://github.com/yaml/libyaml/pull/103 -- Remove unused code in yaml_document_delete
* https://github.com/yaml/libyaml/pull/104 -- Allow colons in plain scalars inside flow collections
* https://github.com/yaml/libyaml/pull/109 -- Fix comparison in tests/run-emitter.c
* https://github.com/yaml/libyaml/pull/117 -- Fix typo error
* https://github.com/yaml/libyaml/pull/119 -- The closing single quote needs to be indented...
* https://github.com/yaml/libyaml/pull/121 -- fix token name typos in comments
* https://github.com/yaml/libyaml/pull/122 -- Revert removing of open_ended after top level plain scalar
* https://github.com/yaml/libyaml/pull/125 -- Cherry-picks from PR 27
* https://github.com/yaml/libyaml/pull/135 -- Windows/C89 compatibility
* https://github.com/yaml/libyaml/pull/136 -- allow override of Windows static lib name
https://github.com/yaml/libyaml/pull/187
Add -h and --flow (on|off|keep) to run-*-test-suite
https://github.com/yaml/libyaml/pull/182
Remove unnecessary include and malloc
https://github.com/yaml/libyaml/pull/177
Add specific files back to .gitignore
https://github.com/yaml/libyaml/pull/181
Output error position in run-parser-test-suite.c
https://github.com/yaml/libyaml/pull/105
Allow question marks in plain scalars in flow collections
https://github.com/yaml/libyaml/pull/186
Emitter: Don't output trailing space for empty scalar nodes
https://github.com/yaml/libyaml/pull/185
Emitter: Output space after an alias mapping key
https://github.com/yaml/libyaml/pull/191
A couple patches to improve test suite support
Resources
@ -36,7 +47,7 @@ Resources
LibYAML IRC Channel: #libyaml on irc.freenode.net
LibYAML homepage: https://github.com/yaml/libyaml
Source download: https://github.com/yaml/libyaml/archive/dist-0.2.2.zip
Source download: https://github.com/yaml/libyaml/archive/dist-0.2.3.zip
GitHub repository: https://github.com/yaml/libyaml
Bug tracking: https://github.com/yaml/libyaml/issues
@ -60,7 +71,6 @@ Maintainers
The following people are responsible for maintaining LibYAML:
* Ingy döt Net
* Tina Mueller
and many thanks to all who have contribributed!
See: https://github.com/yaml/libyaml/pulls
@ -69,7 +79,7 @@ See: https://github.com/yaml/libyaml/pulls
Copyright
=========
Copyright (c) 2017-2019 Ingy döt Net <ingy@ingy.net>
Copyright (c) 2017-2020 Ingy döt Net <ingy@ingy.net>
Copyright (c) 2006-2016 Kirill Simonov <xi@resolvent.net>
The LibYAML module was written by Kirill Simonov.

View File

@ -3,7 +3,7 @@
# Define the package version numbers and the bug reporting link.
m4_define([YAML_MAJOR], 0)
m4_define([YAML_MINOR], 2)
m4_define([YAML_PATCH], 2)
m4_define([YAML_PATCH], 5)
m4_define([YAML_BUGS], [https://github.com/yaml/libyaml/issues/new])
# Define the libtool version numbers; check the Autobook, Section 11.4.
@ -19,7 +19,7 @@ m4_define([YAML_BUGS], [https://github.com/yaml/libyaml/issues/new])
# YAML_AGE = 0
m4_define([YAML_RELEASE], 0)
m4_define([YAML_CURRENT], 2)
m4_define([YAML_REVISION], 6)
m4_define([YAML_REVISION], 9)
m4_define([YAML_AGE], 0)
# Initialize autoconf & automake.

View File

@ -1,4 +1,4 @@
unqouted: string
unquoted: string
literal-block: |
This entire block of text will be the value of the 'literal-block' key,
with line breaks being preserved.

View File

@ -28,7 +28,7 @@ extern "C" {
#if defined(__MINGW32__)
# define YAML_DECLARE(type) type
#elif defined(WIN32)
#elif defined(_WIN32)
# if defined(YAML_DECLARE_STATIC)
# define YAML_DECLARE(type) type
# elif defined(YAML_DECLARE_EXPORT)
@ -552,7 +552,7 @@ yaml_document_end_event_initialize(yaml_event_t *event, int implicit);
*/
YAML_DECLARE(int)
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor);
/**
* Create a SCALAR event.
@ -578,8 +578,8 @@ yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag,
yaml_char_t *value, int length,
const yaml_char_t *anchor, const yaml_char_t *tag,
const yaml_char_t *value, int length,
int plain_implicit, int quoted_implicit,
yaml_scalar_style_t style);
@ -601,7 +601,7 @@ yaml_scalar_event_initialize(yaml_event_t *event,
YAML_DECLARE(int)
yaml_sequence_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_sequence_style_t style);
/**
@ -633,7 +633,7 @@ yaml_sequence_end_event_initialize(yaml_event_t *event);
YAML_DECLARE(int)
yaml_mapping_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_mapping_style_t style);
/**
@ -896,7 +896,7 @@ yaml_document_get_root_node(yaml_document_t *document);
YAML_DECLARE(int)
yaml_document_add_scalar(yaml_document_t *document,
yaml_char_t *tag, yaml_char_t *value, int length,
const yaml_char_t *tag, const yaml_char_t *value, int length,
yaml_scalar_style_t style);
/**
@ -913,7 +913,7 @@ yaml_document_add_scalar(yaml_document_t *document,
YAML_DECLARE(int)
yaml_document_add_sequence(yaml_document_t *document,
yaml_char_t *tag, yaml_sequence_style_t style);
const yaml_char_t *tag, yaml_sequence_style_t style);
/**
* Create a MAPPING node and attach it to the document.
@ -929,7 +929,7 @@ yaml_document_add_sequence(yaml_document_t *document,
YAML_DECLARE(int)
yaml_document_add_mapping(yaml_document_t *document,
yaml_char_t *tag, yaml_mapping_style_t style);
const yaml_char_t *tag, yaml_mapping_style_t style);
/**
* Add an item to a SEQUENCE node.
@ -937,7 +937,7 @@ yaml_document_add_mapping(yaml_document_t *document,
* @param[in,out] document A document object.
* @param[in] sequence The sequence node id.
* @param[in] item The item node id.
*
*
* @returns @c 1 if the function succeeded, @c 0 on error.
*/
@ -952,7 +952,7 @@ yaml_document_append_sequence_item(yaml_document_t *document,
* @param[in] mapping The mapping node id.
* @param[in] key The key node id.
* @param[in] value The value node id.
*
*
* @returns @c 1 if the function succeeded, @c 0 on error.
*/
@ -1020,6 +1020,7 @@ typedef enum yaml_parser_state_e {
YAML_PARSE_DOCUMENT_CONTENT_STATE,
/** Expect DOCUMENT-END. */
YAML_PARSE_DOCUMENT_END_STATE,
/** Expect a block node. */
YAML_PARSE_BLOCK_NODE_STATE,
/** Expect a block node or indentless sequence. */
@ -1030,6 +1031,7 @@ typedef enum yaml_parser_state_e {
YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
/** Expect an entry of a block sequence. */
YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
/** Expect an entry of an indentless sequence. */
YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
/** Expect the first key of a block mapping. */
@ -1040,6 +1042,7 @@ typedef enum yaml_parser_state_e {
YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
/** Expect the first entry of a flow sequence. */
YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
/** Expect an entry of a flow sequence. */
YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
/** Expect a key of an ordered mapping. */
@ -1051,6 +1054,7 @@ typedef enum yaml_parser_state_e {
/** Expect the first key of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
/** Expect a key of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_KEY_STATE,
/** Expect a value of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
@ -1091,7 +1095,7 @@ typedef struct yaml_parser_s {
yaml_error_type_t error;
/** Error description. */
const char *problem;
/** The byte about which the problem occured. */
/** The byte about which the problem occurred. */
size_t problem_offset;
/** The problematic value (@c -1 is none). */
int problem_value;
@ -1205,7 +1209,7 @@ typedef struct yaml_parser_s {
/** The number of tokens fetched from the queue. */
size_t tokens_parsed;
/* Does the tokens queue contain a token ready for dequeueing. */
/** Does the tokens queue contain a token ready for dequeueing. */
int token_available;
/** The indentation levels stack. */
@ -1331,7 +1335,7 @@ yaml_parser_delete(yaml_parser_t *parser);
* Set a string input.
*
* Note that the @a input pointer must be valid while the @a parser object
* exists. The application is responsible for destroing @a input after
* exists. The application is responsible for destroying @a input after
* destroying the @a parser.
*
* @param[in,out] parser A parser object.
@ -1446,12 +1450,26 @@ yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
* @param[in,out] parser A parser object.
* @param[out] document An empty document object.
*
* @return @c 1 if the function succeeded, @c 0 on error.
* @returns @c 1 if the function succeeded, @c 0 on error.
*/
YAML_DECLARE(int)
yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
/**
* Set the maximum depth of nesting.
*
* Default: 1000
*
* Each nesting level increases the stack and the number of previous
* starting events that the parser has to check.
*
* @param[in] max The maximum number of allowed nested events
*/
YAML_DECLARE(void)
yaml_set_max_nest_level(int max);
/** @} */
/**
@ -1489,6 +1507,7 @@ typedef enum yaml_emitter_state_e {
YAML_EMIT_DOCUMENT_CONTENT_STATE,
/** Expect DOCUMENT-END. */
YAML_EMIT_DOCUMENT_END_STATE,
/** Expect the first item of a flow sequence. */
YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
/** Expect an item of a flow sequence. */
@ -1499,6 +1518,7 @@ typedef enum yaml_emitter_state_e {
YAML_EMIT_FLOW_MAPPING_KEY_STATE,
/** Expect a value for a simple key of a flow mapping. */
YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
/** Expect a value of a flow mapping. */
YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
/** Expect the first item of a block sequence. */
@ -1509,6 +1529,7 @@ typedef enum yaml_emitter_state_e {
YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
/** Expect the key of a block mapping. */
YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
/** Expect a value for a simple key of a block mapping. */
YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
/** Expect a value of a block mapping. */
@ -1560,7 +1581,7 @@ typedef struct yaml_emitter_s {
/** Write handler. */
yaml_write_handler_t *write_handler;
/** A pointer for passing to the white handler. */
/** A pointer for passing to the write handler. */
void *write_handler_data;
/** Standard (string or file) output data. */
@ -1727,7 +1748,7 @@ typedef struct yaml_emitter_s {
size_t length;
/** Does the scalar contain line breaks? */
int multiline;
/** Can the scalar be expessed in the flow plain style? */
/** Can the scalar be expressed in the flow plain style? */
int flow_plain_allowed;
/** Can the scalar be expressed in the block plain style? */
int block_plain_allowed;
@ -1858,7 +1879,7 @@ YAML_DECLARE(void)
yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
/**
* Set the intendation increment.
* Set the indentation increment.
*
* @param[in,out] emitter An emitter object.
* @param[in] indent The indentation increment (1 < . < 10).
@ -1943,7 +1964,7 @@ yaml_emitter_close(yaml_emitter_t *emitter);
/**
* Emit a YAML document.
*
* The documen object may be generated using the yaml_parser_load() function
* The document object may be generated using the yaml_parser_load() function
* or the yaml_document_initialize() function. The emitter takes the
* responsibility for the document object and destroys its content after
* it is emitted. The document object is destroyed even if the function fails.

77
pkg/ReadMe.md Normal file
View File

@ -0,0 +1,77 @@
# How to Make a `libyaml` Release
## Versioning
Update libyaml version in:
* announcement.msg
* Changes
* CMakeLists.txt
* `YAML_VERSION_MAJOR`, `YAML_VERSION_MINOR`, `YAML_VERSION_PATCH`
* .appveyor.yml
* configure.ac
* `YAML_MAJOR`, `YAML_MINOR`, `YAML_PATCH`, `YAML_RELEASE`, `YAML_CURRENT`, `YAML_REVISION`
Commit and push everything to `release/0.x.y`.
## Test and Create Release Archives
### GitHub Actions Automation
The github workflow:
.github/workflows/dist.yaml
will do this automatically for you.
#### .github/workflows/dist.yaml
This workflow will create release archives (`tar.gz` and `zip`).
### Manually
Make sure you have a clean git repository (no changed files).
The following process will clone your current git directory.
This will need the docker image `yamlio/libyaml-dev`.
You can either pull it, or create it yourself:
make docker-build
### Create dist archives
Run:
make docker-dist
It will run `make dist` in the container to create a tarball written to
`pkg/docker/output`.
It will also create a zipfile.
## Update master
git merge release/0.x.y
git tag -a 0.x.y
# <Editor opens>
# Paste the corresponding entry from the Changes file
# Look at an earlier release for how it should look like:
# git show 0.2.3
git push origin master 0.x.y
## Create a GitHub release
Go to "Releases" and click on "Draft a new release".
Fill in the tag you just created in the previous step.
Fill in the release title: v0.x.y
Paste the changelog into the description field.
Upload the tar.gz and .zip file.
You can "Save draft" and publish later, or directly click on "Publish release".
## Update pyyaml.org
See <https://github.com/yaml/pyyaml.org/blob/master/ReadMe.md>.

3
pkg/docker/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
output/*
!Makefile
!output/ReadMe

32
pkg/docker/Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y \
automake \
bison \
build-essential \
cmake \
curl \
doxygen \
flex \
git \
less \
libtool \
python \
vim \
zip \
&& true
# http://www.doxygen.nl/manual/install.html
RUN curl https://sourceforge.net/projects/doxygen/files/rel-1.8.14/doxygen-1.8.14.src.tar.gz/download \
-L -o /doxygen-1.8.14.src.tar.gz \
&& cd / \
&& tar -xvf doxygen-1.8.14.src.tar.gz \
&& cd doxygen-1.8.14 \
&& mkdir build \
&& cd build \
&& cmake -G "Unix Makefiles" .. \
&& make \
&& make install \
&& true

23
pkg/docker/Makefile Normal file
View File

@ -0,0 +1,23 @@
DOCKER_IMAGE ?= yamlio/libyaml-dev
build:
docker build -t $(DOCKER_IMAGE) .
run: build
docker run -it --rm $(DOCKER_IMAGE) bash
prepare-git:
rm -rf output/libyaml.git
git clone ../../.git output/libyaml.git
libyaml-dist: libyaml-dist-ci
libyaml-dist-ci: prepare-git
docker run --rm -u $$(id -u) \
-v"$$PWD/output:/output" \
-v"$$PWD/scripts:/scripts" \
$(DOCKER_IMAGE) /scripts/libyaml-dist.sh
clean:
rm -rf output/libyaml.git
rm -rf output/yaml-*.*

1
pkg/docker/output/ReadMe Normal file
View File

@ -0,0 +1 @@
Output directory for build files created by docker

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -ex
cp -r /output/libyaml.git /tmp/
cd /tmp/libyaml.git
./bootstrap
./configure
make dist
# get the tarball filename
tarballs=(yaml-*.tar.gz)
tarball=${tarballs[0]:?}
dirname=${tarball/.tar.gz/}
# Copy to output dir
cp "$tarball" /output
# Create zip archive
cd /tmp
cp "/output/$tarball" .
tar xvf "$tarball"
zip -r "/output/$dirname.zip" "$dirname"

View File

@ -623,10 +623,10 @@ yaml_token_delete(yaml_token_t *token)
*/
static int
yaml_check_utf8(yaml_char_t *start, size_t length)
yaml_check_utf8(const yaml_char_t *start, size_t length)
{
yaml_char_t *end = start+length;
yaml_char_t *pointer = start;
const yaml_char_t *end = start+length;
const yaml_char_t *pointer = start;
while (pointer < end) {
unsigned char octet;
@ -794,7 +794,7 @@ yaml_document_end_event_initialize(yaml_event_t *event, int implicit)
*/
YAML_DECLARE(int)
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor)
{
yaml_mark_t mark = { 0, 0, 0 };
yaml_char_t *anchor_copy = NULL;
@ -819,8 +819,8 @@ yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag,
yaml_char_t *value, int length,
const yaml_char_t *anchor, const yaml_char_t *tag,
const yaml_char_t *value, int length,
int plain_implicit, int quoted_implicit,
yaml_scalar_style_t style)
{
@ -873,7 +873,7 @@ error:
YAML_DECLARE(int)
yaml_sequence_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_sequence_style_t style)
{
yaml_mark_t mark = { 0, 0, 0 };
@ -928,7 +928,7 @@ yaml_sequence_end_event_initialize(yaml_event_t *event)
YAML_DECLARE(int)
yaml_mapping_start_event_initialize(yaml_event_t *event,
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_mapping_style_t style)
{
yaml_mark_t mark = { 0, 0, 0 };
@ -1193,7 +1193,7 @@ yaml_document_get_root_node(yaml_document_t *document)
YAML_DECLARE(int)
yaml_document_add_scalar(yaml_document_t *document,
yaml_char_t *tag, yaml_char_t *value, int length,
const yaml_char_t *tag, const yaml_char_t *value, int length,
yaml_scalar_style_t style)
{
struct {
@ -1243,7 +1243,7 @@ error:
YAML_DECLARE(int)
yaml_document_add_sequence(yaml_document_t *document,
yaml_char_t *tag, yaml_sequence_style_t style)
const yaml_char_t *tag, yaml_sequence_style_t style)
{
struct {
yaml_error_type_t error;
@ -1288,7 +1288,7 @@ error:
YAML_DECLARE(int)
yaml_document_add_mapping(yaml_document_t *document,
yaml_char_t *tag, yaml_mapping_style_t style)
const yaml_char_t *tag, yaml_mapping_style_t style)
{
struct {
yaml_error_type_t error;

View File

@ -495,6 +495,7 @@ static int
yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
yaml_event_t *event)
{
emitter->open_ended = 0;
if (event->type == YAML_STREAM_START_EVENT)
{
if (!emitter->encoding) {
@ -597,13 +598,20 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
if (!yaml_emitter_write_indent(emitter))
return 0;
}
emitter->open_ended = 0;
if (event->data.document_start.version_directive) {
implicit = 0;
if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0))
return 0;
if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
return 0;
if (event->data.document_start.version_directive->minor == 1) {
if (!yaml_emitter_write_indicator(emitter, "1.1", 1, 0, 0))
return 0;
}
else {
if (!yaml_emitter_write_indicator(emitter, "1.2", 1, 0, 0))
return 0;
}
if (!yaml_emitter_write_indent(emitter))
return 0;
}
@ -644,12 +652,25 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
emitter->state = YAML_EMIT_DOCUMENT_CONTENT_STATE;
emitter->open_ended = 0;
return 1;
}
else if (event->type == YAML_STREAM_END_EVENT)
{
/**
* This can happen if a block scalar with trailing empty lines
* is at the end of the stream
*/
if (emitter->open_ended == 2)
{
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
return 0;
emitter->open_ended = 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
}
if (!yaml_emitter_flush(emitter))
return 0;
@ -691,9 +712,12 @@ yaml_emitter_emit_document_end(yaml_emitter_t *emitter,
if (!event->data.document_end.implicit) {
if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
return 0;
emitter->open_ended = 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
}
else if (!emitter->open_ended)
emitter->open_ended = 1;
if (!yaml_emitter_flush(emitter))
return 0;
@ -999,6 +1023,8 @@ yaml_emitter_emit_alias(yaml_emitter_t *emitter, SHIM(yaml_event_t *event))
{
if (!yaml_emitter_process_anchor(emitter))
return 0;
if (emitter->simple_key_context)
if (!PUT(emitter, ' ')) return 0;
emitter->state = POP(emitter, emitter->states);
return 1;
@ -1227,7 +1253,7 @@ yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event)
}
/*
* Write an achor.
* Write an anchor.
*/
static int
@ -1326,7 +1352,10 @@ static int
yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter,
yaml_version_directive_t version_directive)
{
if (version_directive.major != 1 || version_directive.minor != 1) {
if (version_directive.major != 1 || (
version_directive.minor != 1
&& version_directive.minor != 2
)) {
return yaml_emitter_set_emitter_error(emitter,
"incompatible %YAML directive");
}
@ -1796,7 +1825,6 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,
emitter->whitespace = is_whitespace;
emitter->indention = (emitter->indention && is_indention);
emitter->open_ended = 0;
return 1;
}
@ -1897,7 +1925,17 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
STRING_ASSIGN(string, value, length);
if (!emitter->whitespace) {
/**
* Avoid trailing spaces for empty values in block mode.
* In flow mode, we still want the space to prevent ambiguous things
* like {a:}.
* Currently, the emitter forbids any plain empty scalar in flow mode
* (e.g. it outputs {a: ''} instead), so emitter->flow_level will
* never be true here.
* But if the emitter is ever changed to allow emitting empty values,
* the check for flow_level is already here.
*/
if (!emitter->whitespace && (length || emitter->flow_level)) {
if (!PUT(emitter, ' ')) return 0;
}
@ -1939,10 +1977,6 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
emitter->whitespace = 0;
emitter->indention = 0;
if (emitter->root_context)
{
emitter->open_ended = 1;
}
return 1;
}
@ -2203,7 +2237,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
else if (string.start == string.pointer)
{
chomp_hint = "+";
emitter->open_ended = 1;
emitter->open_ended = 2;
}
else
{
@ -2213,7 +2247,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
if (IS_BREAK(string))
{
chomp_hint = "+";
emitter->open_ended = 1;
emitter->open_ended = 2;
}
}
}

View File

@ -37,27 +37,47 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
static void
yaml_parser_delete_aliases(yaml_parser_t *parser);
/*
* Document loading context.
*/
struct loader_ctx {
int *start;
int *end;
int *top;
};
/*
* Composer functions.
*/
static int
yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx);
static int
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event);
static int
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
static int
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
static int
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
static int
yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
/*
* Load the next document of the stream.
@ -162,59 +182,78 @@ yaml_parser_delete_aliases(yaml_parser_t *parser)
*/
static int
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event)
{
yaml_event_t event;
struct loader_ctx ctx = { NULL, NULL, NULL };
assert(first_event->type == YAML_DOCUMENT_START_EVENT);
assert(event->type == YAML_DOCUMENT_START_EVENT);
/* DOCUMENT-START is expected. */
parser->document->version_directive
= first_event->data.document_start.version_directive;
= event->data.document_start.version_directive;
parser->document->tag_directives.start
= first_event->data.document_start.tag_directives.start;
= event->data.document_start.tag_directives.start;
parser->document->tag_directives.end
= first_event->data.document_start.tag_directives.end;
= event->data.document_start.tag_directives.end;
parser->document->start_implicit
= first_event->data.document_start.implicit;
parser->document->start_mark = first_event->start_mark;
= event->data.document_start.implicit;
parser->document->start_mark = event->start_mark;
if (!yaml_parser_parse(parser, &event)) return 0;
if (!yaml_parser_load_node(parser, &event)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
assert(event.type == YAML_DOCUMENT_END_EVENT);
/* DOCUMENT-END is expected. */
parser->document->end_implicit = event.data.document_end.implicit;
parser->document->end_mark = event.end_mark;
if (!STACK_INIT(parser, ctx, int*)) return 0;
if (!yaml_parser_load_nodes(parser, &ctx)) {
STACK_DEL(parser, ctx);
return 0;
}
STACK_DEL(parser, ctx);
return 1;
}
/*
* Compose a node.
* Compose a node tree.
*/
static int
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
{
switch (first_event->type) {
case YAML_ALIAS_EVENT:
return yaml_parser_load_alias(parser, first_event);
case YAML_SCALAR_EVENT:
return yaml_parser_load_scalar(parser, first_event);
case YAML_SEQUENCE_START_EVENT:
return yaml_parser_load_sequence(parser, first_event);
case YAML_MAPPING_START_EVENT:
return yaml_parser_load_mapping(parser, first_event);
default:
assert(0); /* Could not happen. */
return 0;
}
yaml_event_t event;
return 0;
do {
if (!yaml_parser_parse(parser, &event)) return 0;
switch (event.type) {
case YAML_ALIAS_EVENT:
if (!yaml_parser_load_alias(parser, &event, ctx)) return 0;
break;
case YAML_SCALAR_EVENT:
if (!yaml_parser_load_scalar(parser, &event, ctx)) return 0;
break;
case YAML_SEQUENCE_START_EVENT:
if (!yaml_parser_load_sequence(parser, &event, ctx)) return 0;
break;
case YAML_SEQUENCE_END_EVENT:
if (!yaml_parser_load_sequence_end(parser, &event, ctx))
return 0;
break;
case YAML_MAPPING_START_EVENT:
if (!yaml_parser_load_mapping(parser, &event, ctx)) return 0;
break;
case YAML_MAPPING_END_EVENT:
if (!yaml_parser_load_mapping_end(parser, &event, ctx))
return 0;
break;
default:
assert(0); /* Could not happen. */
return 0;
case YAML_DOCUMENT_END_EVENT:
break;
}
} while (event.type != YAML_DOCUMENT_END_EVENT);
parser->document->end_implicit = event.data.document_end.implicit;
parser->document->end_mark = event.end_mark;
return 1;
}
/*
@ -252,27 +291,80 @@ yaml_parser_register_anchor(yaml_parser_t *parser,
return 1;
}
/*
* Compose node into its parent in the stree.
*/
static int
yaml_parser_load_node_add(yaml_parser_t *parser, struct loader_ctx *ctx,
int index)
{
struct yaml_node_s *parent;
int parent_index;
if (STACK_EMPTY(parser, *ctx)) {
/* This is the root node, there's no tree to add it to. */
return 1;
}
parent_index = *((*ctx).top - 1);
parent = &parser->document->nodes.start[parent_index-1];
switch (parent->type) {
case YAML_SEQUENCE_NODE:
if (!STACK_LIMIT(parser, parent->data.sequence.items, INT_MAX-1))
return 0;
if (!PUSH(parser, parent->data.sequence.items, index))
return 0;
break;
case YAML_MAPPING_NODE: {
yaml_node_pair_t pair;
if (!STACK_EMPTY(parser, parent->data.mapping.pairs)) {
yaml_node_pair_t *p = parent->data.mapping.pairs.top - 1;
if (p->key != 0 && p->value == 0) {
p->value = index;
break;
}
}
pair.key = index;
pair.value = 0;
if (!STACK_LIMIT(parser, parent->data.mapping.pairs, INT_MAX-1))
return 0;
if (!PUSH(parser, parent->data.mapping.pairs, pair))
return 0;
break;
}
default:
assert(0); /* Could not happen. */
return 0;
}
return 1;
}
/*
* Compose a node corresponding to an alias.
*/
static int
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
yaml_char_t *anchor = first_event->data.alias.anchor;
yaml_char_t *anchor = event->data.alias.anchor;
yaml_alias_data_t *alias_data;
for (alias_data = parser->aliases.start;
alias_data != parser->aliases.top; alias_data ++) {
if (strcmp((char *)alias_data->anchor, (char *)anchor) == 0) {
yaml_free(anchor);
return alias_data->index;
return yaml_parser_load_node_add(parser, ctx, alias_data->index);
}
}
yaml_free(anchor);
return yaml_parser_set_composer_error(parser, "found undefined alias",
first_event->start_mark);
event->start_mark);
}
/*
@ -280,11 +372,12 @@ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
*/
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
yaml_node_t node;
int index;
yaml_char_t *tag = first_event->data.scalar.tag;
yaml_char_t *tag = event->data.scalar.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -294,23 +387,23 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
if (!tag) goto error;
}
SCALAR_NODE_INIT(node, tag, first_event->data.scalar.value,
first_event->data.scalar.length, first_event->data.scalar.style,
first_event->start_mark, first_event->end_mark);
SCALAR_NODE_INIT(node, tag, event->data.scalar.value,
event->data.scalar.length, event->data.scalar.style,
event->start_mark, event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.scalar.anchor)) return 0;
event->data.scalar.anchor)) return 0;
return index;
return yaml_parser_load_node_add(parser, ctx, index);
error:
yaml_free(tag);
yaml_free(first_event->data.scalar.anchor);
yaml_free(first_event->data.scalar.value);
yaml_free(event->data.scalar.anchor);
yaml_free(event->data.scalar.value);
return 0;
}
@ -319,17 +412,17 @@ error:
*/
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
yaml_event_t event;
yaml_node_t node;
struct {
yaml_node_item_t *start;
yaml_node_item_t *end;
yaml_node_item_t *top;
} items = { NULL, NULL, NULL };
int index, item_index;
yaml_char_t *tag = first_event->data.sequence_start.tag;
int index;
yaml_char_t *tag = event->data.sequence_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -342,48 +435,54 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error;
SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
first_event->data.sequence_start.style,
first_event->start_mark, first_event->end_mark);
event->data.sequence_start.style,
event->start_mark, event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.sequence_start.anchor)) return 0;
event->data.sequence_start.anchor)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
while (event.type != YAML_SEQUENCE_END_EVENT) {
if (!STACK_LIMIT(parser,
parser->document->nodes.start[index-1].data.sequence.items,
INT_MAX-1)) return 0;
item_index = yaml_parser_load_node(parser, &event);
if (!item_index) return 0;
if (!PUSH(parser,
parser->document->nodes.start[index-1].data.sequence.items,
item_index)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
}
if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
if (!PUSH(parser, *ctx, index)) return 0;
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
return 1;
error:
yaml_free(tag);
yaml_free(first_event->data.sequence_start.anchor);
yaml_free(event->data.sequence_start.anchor);
return 0;
}
static int
yaml_parser_load_sequence_end(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
int index;
assert(((*ctx).top - (*ctx).start) > 0);
index = *((*ctx).top - 1);
assert(parser->document->nodes.start[index-1].type == YAML_SEQUENCE_NODE);
parser->document->nodes.start[index-1].end_mark = event->end_mark;
(void)POP(parser, *ctx);
return 1;
}
/*
* Compose a mapping node.
*/
static int
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
yaml_event_t event;
yaml_node_t node;
struct {
yaml_node_pair_t *start;
@ -391,8 +490,7 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
yaml_node_pair_t *top;
} pairs = { NULL, NULL, NULL };
int index;
yaml_node_pair_t pair;
yaml_char_t *tag = first_event->data.mapping_start.tag;
yaml_char_t *tag = event->data.mapping_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -405,40 +503,42 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error;
MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
first_event->data.mapping_start.style,
first_event->start_mark, first_event->end_mark);
event->data.mapping_start.style,
event->start_mark, event->end_mark);
if (!PUSH(parser, parser->document->nodes, node)) goto error;
index = parser->document->nodes.top - parser->document->nodes.start;
if (!yaml_parser_register_anchor(parser, index,
first_event->data.mapping_start.anchor)) return 0;
event->data.mapping_start.anchor)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
if (!yaml_parser_load_node_add(parser, ctx, index)) return 0;
while (event.type != YAML_MAPPING_END_EVENT) {
if (!STACK_LIMIT(parser,
parser->document->nodes.start[index-1].data.mapping.pairs,
INT_MAX-1)) return 0;
pair.key = yaml_parser_load_node(parser, &event);
if (!pair.key) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
pair.value = yaml_parser_load_node(parser, &event);
if (!pair.value) return 0;
if (!PUSH(parser,
parser->document->nodes.start[index-1].data.mapping.pairs,
pair)) return 0;
if (!yaml_parser_parse(parser, &event)) return 0;
}
if (!STACK_LIMIT(parser, *ctx, INT_MAX-1)) return 0;
if (!PUSH(parser, *ctx, index)) return 0;
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
return 1;
error:
yaml_free(tag);
yaml_free(first_event->data.mapping_start.anchor);
yaml_free(event->data.mapping_start.anchor);
return 0;
}
static int
yaml_parser_load_mapping_end(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
{
int index;
assert(((*ctx).top - (*ctx).start) > 0);
index = *((*ctx).top - 1);
assert(parser->document->nodes.start[index-1].type == YAML_MAPPING_NODE);
parser->document->nodes.start[index-1].end_mark = event->end_mark;
(void)POP(parser, *ctx);
return 1;
}

View File

@ -64,6 +64,8 @@
* Public API declarations.
*/
int MAX_NESTING_LEVEL = 1000;
YAML_DECLARE(int)
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
@ -80,6 +82,10 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
const char *context, yaml_mark_t context_mark,
const char *problem, yaml_mark_t problem_mark);
static int
yaml_maximum_level_reached(yaml_parser_t *parser,
yaml_mark_t context_mark, yaml_mark_t problem_mark);
/*
* State functions.
*/
@ -162,6 +168,12 @@ static int
yaml_parser_append_tag_directive(yaml_parser_t *parser,
yaml_tag_directive_t value, int allow_duplicates, yaml_mark_t mark);
YAML_DECLARE(void)
yaml_set_max_nest_level(int max)
{
MAX_NESTING_LEVEL = max;
}
/*
* Get the next event.
*/
@ -217,6 +229,14 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
return 0;
}
static int
yaml_maximum_level_reached(yaml_parser_t *parser,
yaml_mark_t context_mark, yaml_mark_t problem_mark)
{
yaml_parser_set_parser_error_context(parser,
"while parsing", context_mark, "Maximum nesting level reached, set with yaml_set_max_nest_level())", problem_mark);
return 0;
}
/*
* State dispatcher.
@ -657,6 +677,10 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
return 1;
}
else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
@ -664,6 +688,10 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
return 1;
}
else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
@ -671,6 +699,10 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
return 1;
}
else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
@ -678,6 +710,10 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
return 1;
}
else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) {
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
goto error;
}
end_mark = token->end_mark;
parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
@ -1022,6 +1058,11 @@ yaml_parser_parse_flow_sequence_entry_mapping_key(yaml_parser_t *parser,
return 0;
return yaml_parser_parse_node(parser, event, 0, 0);
}
else if (token->type == YAML_FLOW_SEQUENCE_END_TOKEN) {
yaml_mark_t mark = token->start_mark;
parser->state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE;
return yaml_parser_process_empty_scalar(parser, event, mark);
}
else {
yaml_mark_t mark = token->end_mark;
SKIP_TOKEN(parser);
@ -1261,7 +1302,10 @@ yaml_parser_process_directives(yaml_parser_t *parser,
goto error;
}
if (token->data.version_directive.major != 1
|| token->data.version_directive.minor != 1) {
|| (
token->data.version_directive.minor != 1
&& token->data.version_directive.minor != 2
)) {
yaml_parser_set_parser_error(parser,
"found incompatible YAML document", token->start_mark);
goto error;

View File

@ -273,7 +273,7 @@
* The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation
* increase that precedes a block collection (cf. the INDENT token in Python).
* The token BLOCK-END denote indentation decrease that ends a block collection
* (cf. the DEDENT token in Python). However YAML has some syntax pecularities
* (cf. the DEDENT token in Python). However YAML has some syntax peculiarities
* that makes detections of these tokens more complex.
*
* The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators
@ -348,6 +348,7 @@
* SCALAR("another value",plain)
* KEY
* SCALAR("a mapping",plain)
* VALUE
* BLOCK-MAPPING-START
* KEY
* SCALAR("key 1",plain)
@ -711,7 +712,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive,
yaml_mark_t start_mark, yaml_char_t **handle);
static int
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri);
static int
@ -2292,7 +2293,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
/* Scan a prefix. */
if (!yaml_parser_scan_tag_uri(parser, 1, NULL, start_mark, &prefix_value))
if (!yaml_parser_scan_tag_uri(parser, 1, 1, NULL, start_mark, &prefix_value))
goto error;
/* Expect a whitespace or line break. */
@ -2410,7 +2411,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
/* Consume the tag value. */
if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 1, 0, NULL, start_mark, &suffix))
goto error;
/* Check for '>' and eat it. */
@ -2438,14 +2439,14 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
{
/* Scan the suffix now. */
if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 0, 0, NULL, start_mark, &suffix))
goto error;
}
else
{
/* It wasn't a handle after all. Scan the rest of the tag. */
if (!yaml_parser_scan_tag_uri(parser, 0, handle, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 0, 0, handle, start_mark, &suffix))
goto error;
/* Set the handle to '!'. */
@ -2474,9 +2475,11 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
if (!CACHE(parser, 1)) goto error;
if (!IS_BLANKZ(parser->buffer)) {
yaml_parser_set_scanner_error(parser, "while scanning a tag",
start_mark, "did not find expected whitespace or line break");
goto error;
if (!parser->flow_level || !CHECK(parser->buffer, ',') ) {
yaml_parser_set_scanner_error(parser, "while scanning a tag",
start_mark, "did not find expected whitespace or line break");
goto error;
}
}
end_mark = parser->mark;
@ -2565,7 +2568,7 @@ error:
*/
static int
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri)
{
size_t length = head ? strlen((char *)head) : 0;
@ -2601,8 +2604,11 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
* The set of characters that may appear in URI is as follows:
*
* '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&',
* '=', '+', '$', ',', '.', '!', '~', '*', '\'', '(', ')', '[', ']',
* '%'.
* '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%'.
*
* If we are inside a verbatim tag <...> (parameter uri_char is true)
* then also the following flow indicators are allowed:
* ',', '[', ']'
*/
while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';')
@ -2610,12 +2616,15 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
|| CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@')
|| CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=')
|| CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$')
|| CHECK(parser->buffer, ',') || CHECK(parser->buffer, '.')
|| CHECK(parser->buffer, '.') || CHECK(parser->buffer, '%')
|| CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~')
|| CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'')
|| CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')')
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
|| CHECK(parser->buffer, '%'))
|| (uri_char && (
CHECK(parser->buffer, ',')
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
)
))
{
/* Check if it is a URI-escape sequence. */
@ -3278,7 +3287,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token,
/* Check if we are at the end of the scalar. */
/* Fix for crash unitialized value crash
/* Fix for crash uninitialized value crash
* Credit for the bug and input is to OSS Fuzz
* Credit for the fix to Alex Gaynor
*/
@ -3456,7 +3465,7 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))
|| (parser->flow_level &&
(CHECK(parser->buffer, ',')
|| CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[')
|| CHECK(parser->buffer, '[')
|| CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{')
|| CHECK(parser->buffer, '}'))))
break;
@ -3518,12 +3527,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
{
if (IS_BLANK(parser->buffer))
{
/* Check for tab character that abuse indentation. */
/* Check for tab characters that abuse indentation. */
if (leading_blanks && (int)parser->mark.column < indent
&& IS_TAB(parser->buffer)) {
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
start_mark, "found a tab character that violate indentation");
start_mark, "found a tab character that violates indentation");
goto error;
}

63
tests/ReadMe.md Normal file
View File

@ -0,0 +1,63 @@
# Testing the Parser and Emitter
There are several programs to test the parser and emitter.
## Parser
echo 'foo: bar' | ./tests/run-parser-test-suite
This will output the parsing events in yaml-test-suite format:
+STR
+DOC
+MAP
=VAL :foo
=VAL :bar
-MAP
-DOC
-STR
For flow style events, you have to enable it with the `--flow` option:
echo '{ foo: bar }' | ./tests/run-parser-test-suite --flow keep
...
+MAP {}
...
In the future, this will be the default.
You can also explicitly disable this style with `--flow off`, or output
flow style always, with `--flow on`.
## Emitter
run-emitter-test-suite takes yaml-test-suite event format and emits YAML.
./tests/run-parser-test-suite ... | ./tests/run-emitter-test-suite
## Options
* `--directive (1.1|1.2)`
Prints a version directive before every document.
* `--flow on`
Will emit the whole document in flow style.
* `--flow off`
Will emit the whole document in block style.
* `--flow keep`
Will emit block/flow style like in the original document.
Example:
```
% echo 'foo: [bar, {x: y}]' |
./tests/run-parser-test-suite --flow keep |
./tests/run-emitter-test-suite --flow keep
foo: [bar, {x: y}]
```

View File

@ -635,10 +635,10 @@ main(int argc, char *argv[])
/* Display the style information. */
if (input_event.data.sequence_start.style)
if (input_event.data.mapping_start.style)
{
yaml_sequence_style_t style
= (yaml_sequence_style_t) input_event.data.mapping_start.style;
yaml_mapping_style_t style
= input_event.data.mapping_start.style;
/* Add 'style': <style>. */

View File

@ -3,45 +3,89 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "../src/yaml_private.h"
int get_line(FILE * input, char *line);
char *get_anchor(char sigil, char *line, char *anchor);
char *get_tag(char *line, char *tag);
void get_value(char *line, char *value, int *style);
int usage(int ret);
int main(int argc, char *argv[])
{
FILE *input;
yaml_emitter_t emitter;
yaml_event_t event;
yaml_version_directive_t *version_directive = NULL;
int canonical = 0;
int unicode = 0;
char line[1024];
int foundfile = 0;
int i = 0;
int minor = 0;
int flow = -1; /** default no flow style collections */
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--help", 6) == 0)
return usage(0);
if (strncmp(argv[i], "-h", 2) == 0)
return usage(0);
if (strncmp(argv[i], "--flow", 6) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "keep", 4) == 0)
flow = 0;
else if (strncmp(argv[i], "on", 2) == 0)
flow = 1;
else if (strncmp(argv[i], "off", 3) == 0)
flow = -1;
else
return usage(1);
}
else if (strncmp(argv[i], "--directive", 11) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "1.1", 3) == 0)
minor = 1;
else if (strncmp(argv[i], "1.2", 3) == 0)
minor = 2;
else
return usage(1);
}
else if (!foundfile) {
input = fopen(argv[i], "rb");
foundfile = 1;
}
if (argc == 1)
input = stdin;
else if (argc == 2)
input = fopen(argv[1], "rb");
else {
fprintf(stderr, "Usage: libyaml-emitter [<input-file>]\n");
return 1;
}
if (minor) {
version_directive = YAML_MALLOC_STATIC(yaml_version_directive_t);
version_directive->major = 1;
version_directive->minor = minor;
}
if (!foundfile)
input = stdin;
assert(input);
if (!yaml_emitter_initialize(&emitter)) {
fprintf(stderr, "Could not initalize the emitter object\n");
fprintf(stderr, "Could not initialize the emitter object\n");
return 1;
}
yaml_emitter_set_output_file(&emitter, stdout);
yaml_emitter_set_canonical(&emitter, canonical);
yaml_emitter_set_unicode(&emitter, unicode);
while (get_line(input, line)) {
int ok;
char anchor[256];
char tag[256];
int implicit;
int style;
if (strncmp(line, "+STR", 4) == 0) {
ok = yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
@ -50,25 +94,35 @@ int main(int argc, char *argv[])
ok = yaml_stream_end_event_initialize(&event);
}
else if (strncmp(line, "+DOC", 4) == 0) {
implicit = strncmp(line, "+DOC ---", 8) != 0;
ok = yaml_document_start_event_initialize(&event, NULL, NULL, NULL, implicit);
implicit = strncmp(line+4, " ---", 4) != 0;
ok = yaml_document_start_event_initialize(&event, version_directive, NULL, NULL, implicit);
}
else if (strncmp(line, "-DOC", 4) == 0) {
implicit = strncmp(line, "-DOC ...", 8) != 0;
implicit = strncmp(line+4, " ...", 4) != 0;
ok = yaml_document_end_event_initialize(&event, implicit);
}
else if (strncmp(line, "+MAP", 4) == 0) {
style = YAML_BLOCK_MAPPING_STYLE;
if (flow == 1)
style = YAML_FLOW_MAPPING_STYLE;
else if (flow == 0 && strncmp(line+5, "{}", 2) == 0)
style = YAML_FLOW_MAPPING_STYLE;
ok = yaml_mapping_start_event_initialize(&event, (yaml_char_t *)
get_anchor('&', line, anchor), (yaml_char_t *)
get_tag(line, tag), 0, YAML_BLOCK_MAPPING_STYLE);
get_tag(line, tag), 0, style);
}
else if (strncmp(line, "-MAP", 4) == 0) {
ok = yaml_mapping_end_event_initialize(&event);
}
else if (strncmp(line, "+SEQ", 4) == 0) {
style = YAML_BLOCK_SEQUENCE_STYLE;
if (flow == 1)
style = YAML_FLOW_MAPPING_STYLE;
else if (flow == 0 && strncmp(line+5, "[]", 2) == 0)
style = YAML_FLOW_SEQUENCE_STYLE;
ok = yaml_sequence_start_event_initialize(&event, (yaml_char_t *)
get_anchor('&', line, anchor), (yaml_char_t *)
get_tag(line, tag), 0, YAML_BLOCK_SEQUENCE_STYLE);
get_tag(line, tag), 0, style);
}
else if (strncmp(line, "-SEQ", 4) == 0) {
ok = yaml_sequence_end_event_initialize(&event);
@ -229,3 +283,8 @@ void get_value(char *line, char *value, int *style)
}
value[i] = '\0';
}
int usage(int ret) {
fprintf(stderr, "Usage: run-emitter-test-suite [--directive (1.1|1.2)] [--flow (on|off|keep)] [<input-file>]\n");
return ret;
}

View File

@ -4,20 +4,51 @@
#include <assert.h>
void print_escaped(yaml_char_t * str, size_t length);
int usage(int ret);
int main(int argc, char *argv[])
{
FILE *input;
yaml_parser_t parser;
yaml_event_t event;
int flow = -1; /** default no flow style collections */
int i = 0;
int foundfile = 0;
int max_level;
char *output;
if (argc == 1)
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--max-level", 11) == 0) {
i++;
max_level = strtol(argv[i], &output, 10);
yaml_set_max_nest_level(max_level);
}
else if (strncmp(argv[i], "--flow", 6) == 0) {
if (i+1 == argc)
return usage(1);
i++;
if (strncmp(argv[i], "keep", 4) == 0)
flow = 0;
else if (strncmp(argv[i], "on", 2) == 0)
flow = 1;
else if (strncmp(argv[i], "off", 3) == 0)
flow = -1;
else
return usage(1);
}
else if (strncmp(argv[i], "--help", 6) == 0)
return usage(0);
else if (strncmp(argv[i], "-h", 2) == 0)
return usage(0);
else if (!foundfile) {
input = fopen(argv[i], "rb");
foundfile = 1;
}
else
return usage(1);
}
if (!foundfile) {
input = stdin;
else if (argc == 2)
input = fopen(argv[1], "rb");
else {
fprintf(stderr, "Usage: libyaml-parser [<input-file>]\n");
return 1;
}
assert(input);
@ -30,7 +61,15 @@ int main(int argc, char *argv[])
while (1) {
yaml_event_type_t type;
if (!yaml_parser_parse(&parser, &event)) {
fprintf(stderr, "Parse error: %s\n", parser.problem);
if ( parser.problem_mark.line || parser.problem_mark.column ) {
fprintf(stderr, "Parse error: %s\nLine: %lu Column: %lu\n",
parser.problem,
(unsigned long)parser.problem_mark.line + 1,
(unsigned long)parser.problem_mark.column + 1);
}
else {
fprintf(stderr, "Parse error: %s\n", parser.problem);
}
return 1;
}
type = event.type;
@ -55,6 +94,10 @@ int main(int argc, char *argv[])
}
else if (type == YAML_MAPPING_START_EVENT) {
printf("+MAP");
if (flow == 0 && event.data.mapping_start.style == YAML_FLOW_MAPPING_STYLE)
printf(" {}");
else if (flow == 1)
printf(" {}");
if (event.data.mapping_start.anchor)
printf(" &%s", event.data.mapping_start.anchor);
if (event.data.mapping_start.tag)
@ -65,6 +108,10 @@ int main(int argc, char *argv[])
printf("-MAP\n");
else if (type == YAML_SEQUENCE_START_EVENT) {
printf("+SEQ");
if (flow == 0 && event.data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE)
printf(" []");
else if (flow == 1)
printf(" []");
if (event.data.sequence_start.anchor)
printf(" &%s", event.data.sequence_start.anchor);
if (event.data.sequence_start.tag)
@ -142,3 +189,8 @@ void print_escaped(yaml_char_t * str, size_t length)
printf("%c", c);
}
}
int usage(int ret) {
fprintf(stderr, "Usage: libyaml-parser [--flow (on|off|keep)] [<input-file>]\n");
return ret;
}

View File

@ -12,13 +12,31 @@ int
main(int argc, char *argv[])
{
int number;
int start = 0;
int i = 0;
char *filename;
char *output;
int max_level;
int show_error = 0;
if (argc < 2) {
printf("Usage: %s file1.yaml ...\n", argv[0]);
return 0;
}
for (i = 1; i < argc; i++) {
if (strncmp(argv[i], "--max-level", 11) == 0) {
i++;
max_level = strtol(argv[i], &output, 10);
yaml_set_max_nest_level(max_level);
start = i+1;
}
else if (strncmp(argv[i], "--show-error", 12) == 0) {
show_error = 1;
start = i+1;
}
}
for (number = 1; number < argc; number ++)
for (number = start; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
@ -27,10 +45,11 @@ main(int argc, char *argv[])
int count = 0;
int error = 0;
printf("[%d] Parsing '%s': ", number, argv[number]);
filename = argv[number];
printf("[%d] Parsing '%s': ", number, filename);
fflush(stdout);
file = fopen(argv[number], "rb");
file = fopen(filename, "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
@ -41,6 +60,12 @@ main(int argc, char *argv[])
{
if (!yaml_parser_parse(&parser, &event)) {
error = 1;
if (show_error) {
fprintf(stderr, "Parse error: %s\nLine: %lu Column: %lu\n",
parser.problem,
(unsigned long)parser.problem_mark.line + 1,
(unsigned long)parser.problem_mark.column + 1);
}
break;
}

View File

@ -103,7 +103,7 @@ test_case utf8_sequences[] = {
test_case boms[] = {
/* {"title", "test!", lenth}, */
/* {"title", "test!", length}, */
{"no bom (utf-8)", "Hi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13},
{"bom (utf-8)", "\xef\xbb\xbfHi is \xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82!", 13},