Compare commits

..

No commits in common. "master" and "0.2.2" have entirely different histories.

33 changed files with 274 additions and 1347 deletions

View File

@ -1,28 +0,0 @@
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*

View File

@ -1,54 +0,0 @@
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,32 +14,21 @@
.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
config.status
configure
example-deconstructor*
example-reformatter*
run*
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,8 +23,6 @@ MAKE_TARGETS := \
all \
all-am \
all-recursive \
docker-build \
docker-dist \
install \
test \
test-all \

View File

@ -18,7 +18,6 @@ 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 5)
set (YAML_VERSION_PATCH 2)
set (YAML_VERSION_STRING "${YAML_VERSION_MAJOR}.${YAML_VERSION_MINOR}.${YAML_VERSION_PATCH}")
option(BUILD_SHARED_LIBS "Build libyaml as a shared library" OFF)
set(YAML_STATIC_LIB_NAME "yaml" CACHE STRING "Base name of static library output")
option(YAML_STATIC_LIB_NAME "base name of static library output" yaml)
#
# Output directories for a build tree

372
Changes
View File

@ -1,372 +0,0 @@
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-2020 Ingy döt Net
Copyright (c) 2017-2019 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,11 +3,7 @@
SUBDIRS = include src . tests
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
EXTRA_DIST = README LICENSE CMakeLists.txt doc/doxygen.cfg
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = yaml-0.1.pc
@ -29,23 +25,12 @@ bootstrap: maintainer-clean
test: all
make -C tests check-TESTS
test-suite: tests/run-test-suite all
test-suite: tests/run-test-suite
make -C $< test
test-all: test test-suite
tests/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
-git branch --track run-test-suite origin/run-test-suite
-git worktree prune
git worktree add $@ run-test-suite

32
README Normal file
View File

@ -0,0 +1,32 @@
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.

View File

@ -1,46 +0,0 @@
## 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: Tina Müller <post@tinita.de>
From: Ingy döt Net <ingy@ingy.net>
To: yaml-core@lists.sourceforge.net
Subject: [ANN] LibYAML-0.2.5: A new release
Subject: [ANN] LibYAML-0.2.2: A new release
=========================
Announcing LibYAML-0.2.5
Announcing LibYAML-0.2.2
=========================
A new release of LibYAML is now available:
https://github.com/yaml/libyaml/tree/0.2.5
https://github.com/yaml/libyaml/tree/0.2.2
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,30 +16,19 @@ 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
@ -47,7 +36,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.3.zip
Source download: https://github.com/yaml/libyaml/archive/dist-0.2.2.zip
GitHub repository: https://github.com/yaml/libyaml
Bug tracking: https://github.com/yaml/libyaml/issues
@ -71,6 +60,7 @@ 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
@ -79,7 +69,7 @@ See: https://github.com/yaml/libyaml/pulls
Copyright
=========
Copyright (c) 2017-2020 Ingy döt Net <ingy@ingy.net>
Copyright (c) 2017-2019 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

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

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], 5)
m4_define([YAML_PATCH], 2)
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], 9)
m4_define([YAML_REVISION], 6)
m4_define([YAML_AGE], 0)
# Initialize autoconf & automake.

View File

@ -1,4 +1,4 @@
unquoted: string
unqouted: 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, const yaml_char_t *anchor);
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
/**
* Create a SCALAR event.
@ -578,8 +578,8 @@ yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor);
YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
const yaml_char_t *anchor, const yaml_char_t *tag,
const yaml_char_t *value, int length,
yaml_char_t *anchor, yaml_char_t *tag,
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,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_char_t *anchor, 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,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_char_t *anchor, 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,
const yaml_char_t *tag, const yaml_char_t *value, int length,
yaml_char_t *tag, 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,
const yaml_char_t *tag, yaml_sequence_style_t style);
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,
const yaml_char_t *tag, yaml_mapping_style_t style);
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,7 +1020,6 @@ 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. */
@ -1031,7 +1030,6 @@ 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. */
@ -1042,7 +1040,6 @@ 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. */
@ -1054,7 +1051,6 @@ 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,
@ -1095,7 +1091,7 @@ typedef struct yaml_parser_s {
yaml_error_type_t error;
/** Error description. */
const char *problem;
/** The byte about which the problem occurred. */
/** The byte about which the problem occured. */
size_t problem_offset;
/** The problematic value (@c -1 is none). */
int problem_value;
@ -1209,7 +1205,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. */
@ -1335,7 +1331,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 destroying @a input after
* exists. The application is responsible for destroing @a input after
* destroying the @a parser.
*
* @param[in,out] parser A parser object.
@ -1450,26 +1446,12 @@ 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.
*
* @returns @c 1 if the function succeeded, @c 0 on error.
* @return @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);
/** @} */
/**
@ -1507,7 +1489,6 @@ 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. */
@ -1518,7 +1499,6 @@ 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. */
@ -1529,7 +1509,6 @@ 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. */
@ -1581,7 +1560,7 @@ typedef struct yaml_emitter_s {
/** Write handler. */
yaml_write_handler_t *write_handler;
/** A pointer for passing to the write handler. */
/** A pointer for passing to the white handler. */
void *write_handler_data;
/** Standard (string or file) output data. */
@ -1748,7 +1727,7 @@ typedef struct yaml_emitter_s {
size_t length;
/** Does the scalar contain line breaks? */
int multiline;
/** Can the scalar be expressed in the flow plain style? */
/** Can the scalar be expessed in the flow plain style? */
int flow_plain_allowed;
/** Can the scalar be expressed in the block plain style? */
int block_plain_allowed;
@ -1879,7 +1858,7 @@ YAML_DECLARE(void)
yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
/**
* Set the indentation increment.
* Set the intendation increment.
*
* @param[in,out] emitter An emitter object.
* @param[in] indent The indentation increment (1 < . < 10).
@ -1964,7 +1943,7 @@ yaml_emitter_close(yaml_emitter_t *emitter);
/**
* Emit a YAML document.
*
* The document object may be generated using the yaml_parser_load() function
* The documen 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.

View File

@ -1,77 +0,0 @@
# 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>.

View File

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

View File

@ -1,32 +0,0 @@
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

View File

@ -1,23 +0,0 @@
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-*.*

View File

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

View File

@ -1,23 +0,0 @@
#!/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(const yaml_char_t *start, size_t length)
yaml_check_utf8(yaml_char_t *start, size_t length)
{
const yaml_char_t *end = start+length;
const yaml_char_t *pointer = start;
yaml_char_t *end = start+length;
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, const yaml_char_t *anchor)
yaml_alias_event_initialize(yaml_event_t *event, 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, const yaml_char_t *anchor)
YAML_DECLARE(int)
yaml_scalar_event_initialize(yaml_event_t *event,
const yaml_char_t *anchor, const yaml_char_t *tag,
const yaml_char_t *value, int length,
yaml_char_t *anchor, yaml_char_t *tag,
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,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_char_t *anchor, 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,
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
yaml_char_t *anchor, 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,
const yaml_char_t *tag, const yaml_char_t *value, int length,
yaml_char_t *tag, 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,
const yaml_char_t *tag, yaml_sequence_style_t style)
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,
const yaml_char_t *tag, yaml_mapping_style_t style)
yaml_char_t *tag, yaml_mapping_style_t style)
{
struct {
yaml_error_type_t error;

View File

@ -495,7 +495,6 @@ 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) {
@ -598,20 +597,13 @@ 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 (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_indicator(emitter, "1.1", 1, 0, 0))
return 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
}
@ -652,25 +644,12 @@ 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;
@ -712,12 +691,9 @@ 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;
@ -1023,8 +999,6 @@ 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;
@ -1253,7 +1227,7 @@ yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event)
}
/*
* Write an anchor.
* Write an achor.
*/
static int
@ -1352,10 +1326,7 @@ 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
&& version_directive.minor != 2
)) {
if (version_directive.major != 1 || version_directive.minor != 1) {
return yaml_emitter_set_emitter_error(emitter,
"incompatible %YAML directive");
}
@ -1825,6 +1796,7 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter,
emitter->whitespace = is_whitespace;
emitter->indention = (emitter->indention && is_indention);
emitter->open_ended = 0;
return 1;
}
@ -1925,17 +1897,7 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
STRING_ASSIGN(string, value, length);
/**
* 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 (!emitter->whitespace) {
if (!PUT(emitter, ' ')) return 0;
}
@ -1977,6 +1939,10 @@ 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;
}
@ -2237,7 +2203,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
else if (string.start == string.pointer)
{
chomp_hint = "+";
emitter->open_ended = 2;
emitter->open_ended = 1;
}
else
{
@ -2247,7 +2213,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter,
if (IS_BREAK(string))
{
chomp_hint = "+";
emitter->open_ended = 2;
emitter->open_ended = 1;
}
}
}

View File

@ -37,47 +37,27 @@ 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 *event);
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event);
static int
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx);
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event);
static int
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);
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event);
/*
* Load the next document of the stream.
@ -182,73 +162,30 @@ yaml_parser_delete_aliases(yaml_parser_t *parser)
*/
static int
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *event)
{
struct loader_ctx ctx = { NULL, NULL, NULL };
assert(event->type == YAML_DOCUMENT_START_EVENT);
/* DOCUMENT-START is expected. */
parser->document->version_directive
= event->data.document_start.version_directive;
parser->document->tag_directives.start
= event->data.document_start.tag_directives.start;
parser->document->tag_directives.end
= event->data.document_start.tag_directives.end;
parser->document->start_implicit
= event->data.document_start.implicit;
parser->document->start_mark = event->start_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 tree.
*/
static int
yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
yaml_parser_load_document(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_event_t event;
do {
if (!yaml_parser_parse(parser, &event)) return 0;
assert(first_event->type == YAML_DOCUMENT_START_EVENT);
/* DOCUMENT-START is expected. */
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->version_directive
= first_event->data.document_start.version_directive;
parser->document->tag_directives.start
= first_event->data.document_start.tag_directives.start;
parser->document->tag_directives.end
= first_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;
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;
@ -256,6 +193,30 @@ yaml_parser_load_nodes(yaml_parser_t *parser, struct loader_ctx *ctx)
return 1;
}
/*
* Compose a node.
*/
static int
yaml_parser_load_node(yaml_parser_t *parser, yaml_event_t *first_event)
{
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;
}
return 0;
}
/*
* Add an anchor.
*/
@ -291,80 +252,27 @@ 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 *event,
struct loader_ctx *ctx)
yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_char_t *anchor = event->data.alias.anchor;
yaml_char_t *anchor = first_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 yaml_parser_load_node_add(parser, ctx, alias_data->index);
return alias_data->index;
}
}
yaml_free(anchor);
return yaml_parser_set_composer_error(parser, "found undefined alias",
event->start_mark);
first_event->start_mark);
}
/*
@ -372,12 +280,11 @@ yaml_parser_load_alias(yaml_parser_t *parser, yaml_event_t *event,
*/
static int
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_node_t node;
int index;
yaml_char_t *tag = event->data.scalar.tag;
yaml_char_t *tag = first_event->data.scalar.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -387,23 +294,23 @@ yaml_parser_load_scalar(yaml_parser_t *parser, yaml_event_t *event,
if (!tag) goto error;
}
SCALAR_NODE_INIT(node, tag, event->data.scalar.value,
event->data.scalar.length, event->data.scalar.style,
event->start_mark, event->end_mark);
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);
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,
event->data.scalar.anchor)) return 0;
first_event->data.scalar.anchor)) return 0;
return yaml_parser_load_node_add(parser, ctx, index);
return index;
error:
yaml_free(tag);
yaml_free(event->data.scalar.anchor);
yaml_free(event->data.scalar.value);
yaml_free(first_event->data.scalar.anchor);
yaml_free(first_event->data.scalar.value);
return 0;
}
@ -412,17 +319,17 @@ error:
*/
static int
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
struct loader_ctx *ctx)
yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *first_event)
{
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;
yaml_char_t *tag = event->data.sequence_start.tag;
int index, item_index;
yaml_char_t *tag = first_event->data.sequence_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -435,54 +342,48 @@ yaml_parser_load_sequence(yaml_parser_t *parser, yaml_event_t *event,
if (!STACK_INIT(parser, items, yaml_node_item_t*)) goto error;
SEQUENCE_NODE_INIT(node, tag, items.start, items.end,
event->data.sequence_start.style,
event->start_mark, event->end_mark);
first_event->data.sequence_start.style,
first_event->start_mark, first_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,
event->data.sequence_start.anchor)) return 0;
first_event->data.sequence_start.anchor)) return 0;
if (!yaml_parser_load_node_add(parser, ctx, 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;
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;
}
return 1;
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
error:
yaml_free(tag);
yaml_free(event->data.sequence_start.anchor);
yaml_free(first_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 *event,
struct loader_ctx *ctx)
yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event)
{
yaml_event_t event;
yaml_node_t node;
struct {
yaml_node_pair_t *start;
@ -490,7 +391,8 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
yaml_node_pair_t *top;
} pairs = { NULL, NULL, NULL };
int index;
yaml_char_t *tag = event->data.mapping_start.tag;
yaml_node_pair_t pair;
yaml_char_t *tag = first_event->data.mapping_start.tag;
if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error;
@ -503,42 +405,40 @@ yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *event,
if (!STACK_INIT(parser, pairs, yaml_node_pair_t*)) goto error;
MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end,
event->data.mapping_start.style,
event->start_mark, event->end_mark);
first_event->data.mapping_start.style,
first_event->start_mark, first_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,
event->data.mapping_start.anchor)) return 0;
first_event->data.mapping_start.anchor)) return 0;
if (!yaml_parser_load_node_add(parser, ctx, 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;
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;
}
return 1;
parser->document->nodes.start[index-1].end_mark = event.end_mark;
return index;
error:
yaml_free(tag);
yaml_free(event->data.mapping_start.anchor);
yaml_free(first_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,8 +64,6 @@
* Public API declarations.
*/
int MAX_NESTING_LEVEL = 1000;
YAML_DECLARE(int)
yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
@ -82,10 +80,6 @@ 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.
*/
@ -168,12 +162,6 @@ 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.
*/
@ -229,14 +217,6 @@ 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.
@ -677,10 +657,6 @@ 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,
@ -688,10 +664,6 @@ 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,
@ -699,10 +671,6 @@ 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,
@ -710,10 +678,6 @@ 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,
@ -1058,11 +1022,6 @@ 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);
@ -1302,10 +1261,7 @@ 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 != 2
)) {
|| token->data.version_directive.minor != 1) {
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 peculiarities
* (cf. the DEDENT token in Python). However YAML has some syntax pecularities
* that makes detections of these tokens more complex.
*
* The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators
@ -348,7 +348,6 @@
* SCALAR("another value",plain)
* KEY
* SCALAR("a mapping",plain)
* VALUE
* BLOCK-MAPPING-START
* KEY
* SCALAR("key 1",plain)
@ -712,7 +711,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 uri_char, int directive,
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri);
static int
@ -2293,7 +2292,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser,
/* Scan a prefix. */
if (!yaml_parser_scan_tag_uri(parser, 1, 1, NULL, start_mark, &prefix_value))
if (!yaml_parser_scan_tag_uri(parser, 1, NULL, start_mark, &prefix_value))
goto error;
/* Expect a whitespace or line break. */
@ -2411,7 +2410,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
/* Consume the tag value. */
if (!yaml_parser_scan_tag_uri(parser, 1, 0, NULL, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 0, NULL, start_mark, &suffix))
goto error;
/* Check for '>' and eat it. */
@ -2439,14 +2438,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, 0, NULL, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 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, 0, handle, start_mark, &suffix))
if (!yaml_parser_scan_tag_uri(parser, 0, handle, start_mark, &suffix))
goto error;
/* Set the handle to '!'. */
@ -2475,11 +2474,9 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token)
if (!CACHE(parser, 1)) goto error;
if (!IS_BLANKZ(parser->buffer)) {
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;
}
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;
@ -2568,7 +2565,7 @@ error:
*/
static int
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive,
yaml_char_t *head, yaml_mark_t start_mark, yaml_char_t **uri)
{
size_t length = head ? strlen((char *)head) : 0;
@ -2604,11 +2601,8 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, 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, ';')
@ -2616,15 +2610,12 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, 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, ')')
|| (uri_char && (
CHECK(parser->buffer, ',')
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
)
))
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
|| CHECK(parser->buffer, '%'))
{
/* Check if it is a URI-escape sequence. */
@ -3287,7 +3278,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 uninitialized value crash
/* Fix for crash unitialized value crash
* Credit for the bug and input is to OSS Fuzz
* Credit for the fix to Alex Gaynor
*/
@ -3465,7 +3456,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;
@ -3527,12 +3518,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
{
if (IS_BLANK(parser->buffer))
{
/* Check for tab characters that abuse indentation. */
/* Check for tab character 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 violates indentation");
start_mark, "found a tab character that violate indentation");
goto error;
}

View File

@ -1,63 +0,0 @@
# 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.mapping_start.style)
if (input_event.data.sequence_start.style)
{
yaml_mapping_style_t style
= input_event.data.mapping_start.style;
yaml_sequence_style_t style
= (yaml_sequence_style_t) input_event.data.mapping_start.style;
/* Add 'style': <style>. */

View File

@ -3,89 +3,45 @@
#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 (minor) {
version_directive = YAML_MALLOC_STATIC(yaml_version_directive_t);
version_directive->major = 1;
version_directive->minor = minor;
}
if (!foundfile)
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;
}
assert(input);
if (!yaml_emitter_initialize(&emitter)) {
fprintf(stderr, "Could not initialize the emitter object\n");
fprintf(stderr, "Could not initalize 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);
@ -94,35 +50,25 @@ int main(int argc, char *argv[])
ok = yaml_stream_end_event_initialize(&event);
}
else if (strncmp(line, "+DOC", 4) == 0) {
implicit = strncmp(line+4, " ---", 4) != 0;
ok = yaml_document_start_event_initialize(&event, version_directive, NULL, NULL, implicit);
implicit = strncmp(line, "+DOC ---", 8) != 0;
ok = yaml_document_start_event_initialize(&event, NULL, NULL, NULL, implicit);
}
else if (strncmp(line, "-DOC", 4) == 0) {
implicit = strncmp(line+4, " ...", 4) != 0;
implicit = strncmp(line, "-DOC ...", 8) != 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, style);
get_tag(line, tag), 0, YAML_BLOCK_MAPPING_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, style);
get_tag(line, tag), 0, YAML_BLOCK_SEQUENCE_STYLE);
}
else if (strncmp(line, "-SEQ", 4) == 0) {
ok = yaml_sequence_end_event_initialize(&event);
@ -283,8 +229,3 @@ 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,51 +4,20 @@
#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;
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) {
if (argc == 1)
input = stdin;
else if (argc == 2)
input = fopen(argv[1], "rb");
else {
fprintf(stderr, "Usage: libyaml-parser [<input-file>]\n");
return 1;
}
assert(input);
@ -61,15 +30,7 @@ int main(int argc, char *argv[])
while (1) {
yaml_event_type_t type;
if (!yaml_parser_parse(&parser, &event)) {
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);
}
fprintf(stderr, "Parse error: %s\n", parser.problem);
return 1;
}
type = event.type;
@ -94,10 +55,6 @@ 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)
@ -108,10 +65,6 @@ 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)
@ -189,8 +142,3 @@ 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,31 +12,13 @@ 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 = start; number < argc; number ++)
for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
@ -45,11 +27,10 @@ main(int argc, char *argv[])
int count = 0;
int error = 0;
filename = argv[number];
printf("[%d] Parsing '%s': ", number, filename);
printf("[%d] Parsing '%s': ", number, argv[number]);
fflush(stdout);
file = fopen(filename, "rb");
file = fopen(argv[number], "rb");
assert(file);
assert(yaml_parser_initialize(&parser));
@ -60,12 +41,6 @@ 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!", length}, */
/* {"title", "test!", lenth}, */
{"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},