compound-ex4
Version:
Compound-ex4 - MVC framework for NodeJS (ExpressJs 4 version), fork compoundjs(https://github.com/1602/compound)
124 lines (102 loc) • 3.88 kB
text/coffeescript
events = require './events'
{MarkedYAMLError} = require './errors'
nodes = require './nodes'
class extends MarkedYAMLError
class
constructor: ->
= {}
check_node: ->
# Drop the STREAM-START event.
if events.StreamStartEvent
# Are there more documents available?
return not events.StreamEndEvent
###
Get the root node of the next document.
###
get_node: ->
return unless events.StreamEndEvent
get_single_node: ->
# Drop the STREAM-START event.
# Compose a document if the stream is not empty.
document = null
document = unless events.StreamEndEvent
# Ensure that the stream contains no more documents.
unless events.StreamEndEvent
event =
throw new exports.ComposerError 'expected a single document in the stream',
document.start_mark, 'but found another document', event.start_mark
# Drop the STREAM-END event.
return document
compose_document: ->
# Drop the DOCUMENT-START event.
# Compose the root node.
node =
# Drop the DOCUMENT-END node.
= {}
return node
compose_node: (parent, index) ->
if events.AliasEvent
event =
anchor = event.anchor
throw new exports.ComposerError null, null, \
"found undefined alias #{anchor}", event.start_mark \
if anchor not of
return [anchor]
event =
anchor = event.anchor
throw new exports.ComposerError \
"found duplicate anchor #{anchor}; first occurence", \
[anchor].start_mark, 'second occurrence', event.start_mark \
if anchor isnt null and anchor of
parent, index
if events.ScalarEvent
node = anchor
else if events.SequenceStartEvent
node = anchor
else if events.MappingStartEvent
node = anchor
return node
compose_scalar_node: (anchor) ->
event =
tag = event.tag
tag = nodes.ScalarNode, event.value, event.implicit \
if tag is null or tag is '!'
node = new nodes.ScalarNode tag, event.value, event.start_mark,
event.end_mark, event.style
[anchor] = node if anchor isnt null
return node
compose_sequence_node: (anchor) ->
start_event =
tag = start_event.tag
tag = nodes.SequenceNode, null, start_event.implicit \
if tag is null or tag is '!'
node = new nodes.SequenceNode tag, [], start_event.start_mark, null,
start_event.flow_style
[anchor] = node if anchor isnt null
index = 0
while not events.SequenceEndEvent
node.value.push node, index
index++
end_event =
node.end_mark = end_event.end_mark
return node
compose_mapping_node: (anchor) ->
start_event =
tag = start_event.tag
tag = nodes.MappingNode, null, start_event.implicit \
if tag is null or tag is '!'
node = new nodes.MappingNode tag, [], start_event.start_mark, null,
start_event.flow_style
[anchor] = node if anchor isnt null
while not events.MappingEndEvent
item_key = node
item_value = node, item_key
node.value.push [item_key, item_value]
end_event =
node.end_mark = end_event.end_mark
return node