YAML: use factor's c-string in more places
parent
2a409cdec6
commit
7701e1dace
|
@ -51,6 +51,10 @@ yaml_get_version ( int *major, int *minor, int *patch ) ;
|
||||||
! */
|
! */
|
||||||
|
|
||||||
! /** The character type (UTF-8 octet). */
|
! /** The character type (UTF-8 octet). */
|
||||||
|
! libYAML returns it's data as null-terminated UTF-8 string.
|
||||||
|
! It copies it's input and we can use null-terminated string
|
||||||
|
! if we give a negative length. So we can use factor's c-string
|
||||||
|
! for input and output.
|
||||||
TYPEDEF: uchar yaml_char_t
|
TYPEDEF: uchar yaml_char_t
|
||||||
|
|
||||||
! /** The version directive data. */
|
! /** The version directive data. */
|
||||||
|
@ -61,8 +65,8 @@ STRUCT: yaml_version_directive_t
|
||||||
|
|
||||||
! /** The tag directive data. */
|
! /** The tag directive data. */
|
||||||
STRUCT: yaml_tag_directive_t
|
STRUCT: yaml_tag_directive_t
|
||||||
{ handle yaml_char_t* }
|
{ handle c-string }
|
||||||
{ prefix yaml_char_t* }
|
{ prefix c-string }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** The stream encoding. */
|
! /** The stream encoding. */
|
||||||
|
@ -185,22 +189,22 @@ STRUCT: stream_start_token_data
|
||||||
;
|
;
|
||||||
! /** The alias (for @c YAML_ALIAS_TOKEN). */
|
! /** The alias (for @c YAML_ALIAS_TOKEN). */
|
||||||
STRUCT: alias_token_data
|
STRUCT: alias_token_data
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
;
|
;
|
||||||
! /** The anchor (for @c YAML_ANCHOR_TOKEN). */
|
! /** The anchor (for @c YAML_ANCHOR_TOKEN). */
|
||||||
STRUCT: anchor_token_data
|
STRUCT: anchor_token_data
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** The tag (for @c YAML_TAG_TOKEN). */
|
! /** The tag (for @c YAML_TAG_TOKEN). */
|
||||||
STRUCT: tag_token_data
|
STRUCT: tag_token_data
|
||||||
{ handle yaml_char_t* }
|
{ handle c-string }
|
||||||
{ suffix yaml_char_t* }
|
{ suffix c-string }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** The scalar value (for @c YAML_SCALAR_TOKEN). */
|
! /** The scalar value (for @c YAML_SCALAR_TOKEN). */
|
||||||
STRUCT: scalar_token_data
|
STRUCT: scalar_token_data
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
{ length size_t }
|
{ length size_t }
|
||||||
{ style yaml_scalar_style_t }
|
{ style yaml_scalar_style_t }
|
||||||
;
|
;
|
||||||
|
@ -293,14 +297,14 @@ STRUCT: document_end_event_data
|
||||||
|
|
||||||
! /** The alias parameters (for @c YAML_ALIAS_EVENT). */
|
! /** The alias parameters (for @c YAML_ALIAS_EVENT). */
|
||||||
STRUCT: alias_event_data
|
STRUCT: alias_event_data
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
|
! /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
|
||||||
STRUCT: scalar_event_data
|
STRUCT: scalar_event_data
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
{ tag yaml_char_t* }
|
{ tag c-string }
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
{ length size_t }
|
{ length size_t }
|
||||||
{ plain_implicit int }
|
{ plain_implicit int }
|
||||||
{ quoted_implicit int }
|
{ quoted_implicit int }
|
||||||
|
@ -309,16 +313,16 @@ STRUCT: scalar_event_data
|
||||||
|
|
||||||
! /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
|
! /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
|
||||||
STRUCT: sequence_start_event_data
|
STRUCT: sequence_start_event_data
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
{ tag yaml_char_t* }
|
{ tag c-string }
|
||||||
{ implicit int }
|
{ implicit int }
|
||||||
{ style yaml_sequence_style_t }
|
{ style yaml_sequence_style_t }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
|
! /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
|
||||||
STRUCT: mapping_start_event_data
|
STRUCT: mapping_start_event_data
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
{ tag yaml_char_t* }
|
{ tag c-string }
|
||||||
{ implicit int }
|
{ implicit int }
|
||||||
{ style yaml_mapping_style_t }
|
{ style yaml_mapping_style_t }
|
||||||
;
|
;
|
||||||
|
@ -418,7 +422,7 @@ yaml_document_end_event_initialize ( yaml_event_t *event, int implicit ) ;
|
||||||
! */
|
! */
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_alias_event_initialize ( yaml_event_t *event, yaml_char_t *anchor ) ;
|
yaml_alias_event_initialize ( yaml_event_t *event, c-string anchor ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
! * Create a SCALAR event.
|
! * Create a SCALAR event.
|
||||||
|
@ -444,8 +448,8 @@ yaml_alias_event_initialize ( yaml_event_t *event, yaml_char_t *anchor ) ;
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_scalar_event_initialize ( yaml_event_t *event,
|
yaml_scalar_event_initialize ( yaml_event_t *event,
|
||||||
yaml_char_t *anchor, yaml_char_t *tag,
|
c-string anchor, c-string tag,
|
||||||
yaml_char_t *value, int length,
|
c-string value, int length,
|
||||||
int plain_implicit, int quoted_implicit,
|
int plain_implicit, int quoted_implicit,
|
||||||
yaml_scalar_style_t style ) ;
|
yaml_scalar_style_t style ) ;
|
||||||
|
|
||||||
|
@ -467,7 +471,7 @@ yaml_scalar_event_initialize ( yaml_event_t *event,
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_sequence_start_event_initialize ( yaml_event_t *event,
|
yaml_sequence_start_event_initialize ( yaml_event_t *event,
|
||||||
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
c-string anchor, c-string tag, int implicit,
|
||||||
yaml_sequence_style_t style ) ;
|
yaml_sequence_style_t style ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
|
@ -499,7 +503,7 @@ yaml_sequence_end_event_initialize ( yaml_event_t *event ) ;
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_mapping_start_event_initialize ( yaml_event_t *event,
|
yaml_mapping_start_event_initialize ( yaml_event_t *event,
|
||||||
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
c-string anchor, c-string tag, int implicit,
|
||||||
yaml_mapping_style_t style ) ;
|
yaml_mapping_style_t style ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
|
@ -579,7 +583,7 @@ STRUCT: yaml_node_pair_t
|
||||||
! /** The node structure. */
|
! /** The node structure. */
|
||||||
! /** The scalar parameters (for @c YAML_SCALAR_NODE). */
|
! /** The scalar parameters (for @c YAML_SCALAR_NODE). */
|
||||||
STRUCT: scalar_node_data
|
STRUCT: scalar_node_data
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
{ length size_t }
|
{ length size_t }
|
||||||
{ style yaml_scalar_style_t }
|
{ style yaml_scalar_style_t }
|
||||||
;
|
;
|
||||||
|
@ -617,7 +621,7 @@ STRUCT: yaml_node_t
|
||||||
|
|
||||||
{ type yaml_node_type_t }
|
{ type yaml_node_type_t }
|
||||||
|
|
||||||
{ tag yaml_char_t* }
|
{ tag c-string }
|
||||||
|
|
||||||
{ data node_data }
|
{ data node_data }
|
||||||
|
|
||||||
|
@ -741,7 +745,7 @@ yaml_document_get_root_node ( yaml_document_t *document ) ;
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_document_add_scalar ( yaml_document_t *document,
|
yaml_document_add_scalar ( yaml_document_t *document,
|
||||||
yaml_char_t *tag, yaml_char_t *value, int length,
|
c-string tag, c-string value, int length,
|
||||||
yaml_scalar_style_t style ) ;
|
yaml_scalar_style_t style ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
|
@ -758,7 +762,7 @@ yaml_document_add_scalar ( yaml_document_t *document,
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_document_add_sequence ( yaml_document_t *document,
|
yaml_document_add_sequence ( yaml_document_t *document,
|
||||||
yaml_char_t *tag, yaml_sequence_style_t style ) ;
|
c-string tag, yaml_sequence_style_t style ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
! * Create a MAPPING node and attach it to the document.
|
! * Create a MAPPING node and attach it to the document.
|
||||||
|
@ -774,7 +778,7 @@ yaml_document_add_sequence ( yaml_document_t *document,
|
||||||
|
|
||||||
FUNCTION: int
|
FUNCTION: int
|
||||||
yaml_document_add_mapping ( yaml_document_t *document,
|
yaml_document_add_mapping ( yaml_document_t *document,
|
||||||
yaml_char_t *tag, yaml_mapping_style_t style ) ;
|
c-string tag, yaml_mapping_style_t style ) ;
|
||||||
|
|
||||||
! /**
|
! /**
|
||||||
! * Add an item to a SEQUENCE node.
|
! * Add an item to a SEQUENCE node.
|
||||||
|
@ -882,7 +886,7 @@ ENUM: yaml_parser_state_t
|
||||||
! */
|
! */
|
||||||
|
|
||||||
STRUCT: yaml_alias_data_t
|
STRUCT: yaml_alias_data_t
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
{ index int }
|
{ index int }
|
||||||
{ mark yaml_mark_t }
|
{ mark yaml_mark_t }
|
||||||
;
|
;
|
||||||
|
@ -1298,22 +1302,22 @@ ENUM: yaml_emitter_state_t
|
||||||
|
|
||||||
! /** Anchor analysis. */
|
! /** Anchor analysis. */
|
||||||
STRUCT: yaml_emitter_anchor_data
|
STRUCT: yaml_emitter_anchor_data
|
||||||
{ anchor yaml_char_t* }
|
{ anchor c-string }
|
||||||
{ anchor_length size_t }
|
{ anchor_length size_t }
|
||||||
{ alias int }
|
{ alias int }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** Tag analysis. */
|
! /** Tag analysis. */
|
||||||
STRUCT: yaml_emitter_tag_data
|
STRUCT: yaml_emitter_tag_data
|
||||||
{ handle yaml_char_t* }
|
{ handle c-string }
|
||||||
{ handle_length size_t }
|
{ handle_length size_t }
|
||||||
{ suffix yaml_char_t* }
|
{ suffix c-string }
|
||||||
{ suffix_length size_t }
|
{ suffix_length size_t }
|
||||||
;
|
;
|
||||||
|
|
||||||
! /** Scalar analysis. */
|
! /** Scalar analysis. */
|
||||||
STRUCT: yaml_emitter_scalar_data
|
STRUCT: yaml_emitter_scalar_data
|
||||||
{ value yaml_char_t* }
|
{ value c-string }
|
||||||
{ length size_t }
|
{ length size_t }
|
||||||
{ multiline int }
|
{ multiline int }
|
||||||
{ flow_plain_allowed int }
|
{ flow_plain_allowed int }
|
||||||
|
|
|
@ -11,8 +11,7 @@ IN: yaml
|
||||||
: yaml-assert-ok ( n -- ) 0 = [ "yaml error" throw ] when ;
|
: yaml-assert-ok ( n -- ) 0 = [ "yaml error" throw ] when ;
|
||||||
|
|
||||||
: event>scalar ( event -- obj )
|
: event>scalar ( event -- obj )
|
||||||
data>> scalar>> [ value>> ] [ length>> ] bi
|
data>> scalar>> value>> ;
|
||||||
memory>byte-array utf8 decode ;
|
|
||||||
|
|
||||||
: ?scalar-value ( event -- scalar/f f/type )
|
: ?scalar-value ( event -- scalar/f f/type )
|
||||||
dup type>> YAML_SCALAR_EVENT =
|
dup type>> YAML_SCALAR_EVENT =
|
||||||
|
@ -134,27 +133,14 @@ SYMBOL: yaml-write-buffer
|
||||||
GENERIC: emit-value ( emitter event obj -- )
|
GENERIC: emit-value ( emitter event obj -- )
|
||||||
|
|
||||||
M:: string emit-value ( emitter event string -- )
|
M:: string emit-value ( emitter event string -- )
|
||||||
[
|
event f YAML_STR_TAG string -1 0 0 0
|
||||||
string utf8 encode
|
yaml_scalar_event_initialize yaml-assert-ok
|
||||||
[ malloc-byte-array &free ] [ length ] bi :> ( value length )
|
emitter event yaml_emitter_emit yaml-assert-ok ;
|
||||||
|
|
||||||
YAML_STR_TAG utf8 malloc-string &free :> tag
|
|
||||||
|
|
||||||
event f tag value length 0 0 0
|
|
||||||
yaml_scalar_event_initialize yaml-assert-ok
|
|
||||||
|
|
||||||
emitter event yaml_emitter_emit yaml-assert-ok
|
|
||||||
] with-destructors ;
|
|
||||||
|
|
||||||
:: emit-sequence-start ( emitter event -- )
|
:: emit-sequence-start ( emitter event -- )
|
||||||
[
|
event f YAML_SEQ_TAG 0 0
|
||||||
YAML_SEQ_TAG utf8 malloc-string &free :> tag
|
yaml_sequence_start_event_initialize yaml-assert-ok
|
||||||
|
emitter event yaml_emitter_emit yaml-assert-ok ;
|
||||||
event f tag 0 0
|
|
||||||
yaml_sequence_start_event_initialize yaml-assert-ok
|
|
||||||
|
|
||||||
emitter event yaml_emitter_emit yaml-assert-ok
|
|
||||||
] with-destructors ;
|
|
||||||
: emit-sequence-end ( emitter event -- )
|
: emit-sequence-end ( emitter event -- )
|
||||||
dup yaml_sequence_end_event_initialize yaml-assert-ok
|
dup yaml_sequence_end_event_initialize yaml-assert-ok
|
||||||
yaml_emitter_emit yaml-assert-ok ;
|
yaml_emitter_emit yaml-assert-ok ;
|
||||||
|
@ -168,14 +154,9 @@ M: sequence emit-value ( emitter event seq -- )
|
||||||
[ drop emit-sequence-end ] 3tri ;
|
[ drop emit-sequence-end ] 3tri ;
|
||||||
|
|
||||||
:: emit-assoc-start ( emitter event -- )
|
:: emit-assoc-start ( emitter event -- )
|
||||||
[
|
event f YAML_MAP_TAG 0 0
|
||||||
YAML_MAP_TAG utf8 malloc-string &free :> tag
|
yaml_mapping_start_event_initialize yaml-assert-ok
|
||||||
|
emitter event yaml_emitter_emit yaml-assert-ok ;
|
||||||
event f tag 0 0
|
|
||||||
yaml_mapping_start_event_initialize yaml-assert-ok
|
|
||||||
|
|
||||||
emitter event yaml_emitter_emit yaml-assert-ok
|
|
||||||
] with-destructors ;
|
|
||||||
: emit-assoc-end ( emitter event -- )
|
: emit-assoc-end ( emitter event -- )
|
||||||
dup yaml_mapping_end_event_initialize yaml-assert-ok
|
dup yaml_mapping_end_event_initialize yaml-assert-ok
|
||||||
yaml_emitter_emit yaml-assert-ok ;
|
yaml_emitter_emit yaml-assert-ok ;
|
||||||
|
|
Loading…
Reference in New Issue