Use yamerl_constr:new({file, ...}), like yamerl_constr:file/{1, 2}

This commit is contained in:
Jean-Sébastien Pédron 2012-12-12 11:46:05 +01:00
parent 7d38065b3c
commit 511f7928e6
2 changed files with 5 additions and 4 deletions

View File

@ -86,7 +86,7 @@ If parsing or construction fails, throw an exception.
##### Parse a valid stream ##### Parse a valid stream
```erlang ```erlang
Stream_St1 = yamerl_constr:new("<stdin>"), Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"He">>), {continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"He">>),
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>), {continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
yamerl_constr:last_chunk(Stream_St3, <<"o!">>). yamerl_constr:last_chunk(Stream_St3, <<"o!">>).
@ -104,7 +104,7 @@ Returns:
##### Parse an invalid stream ##### Parse an invalid stream
```erlang ```erlang
Stream_St1 = yamerl_constr:new("<stdin>"), Stream_St1 = yamerl_constr:new({file, "<stdin>"}),
{continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"'He">>), {continue, Stream_St2} = yamerl_constr:next_chunk(Stream_St1, <<"'He">>),
{continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>), {continue, Stream_St3} = yamerl_constr:next_chunk(Stream_St2, <<"ll">>),
yamerl_constr:last_chunk(Stream_St3, <<"o!">>) % Unfinished single-quoted scalar. yamerl_constr:last_chunk(Stream_St3, <<"o!">>) % Unfinished single-quoted scalar.

View File

@ -18,8 +18,9 @@ Documents = yamerl_constr:file("input.yaml").
* To parse a stream: * To parse a stream:
```erlang ```erlang
% Create a new construction state. The only required argument is an % Create a new construction state. The only required argument is an
% arbitrary term describing the source of the data. % arbitrary term describing the source of the data. Here, we use the
Constr_State = yamerl_constr:new("<stdin>"), % same term structure as yamerl_constr:file/{1, 2}.
Constr_State = yamerl_constr:new({file, "<stdin>"}),
% Feed the parser with binary chunks. The developer is responsible for % Feed the parser with binary chunks. The developer is responsible for
% reading the chunk from the underlying source. % reading the chunk from the underlying source.