Skip to content

Commit

Permalink
Merge pull request #43 from newsdev/nested-objects
Browse files Browse the repository at this point in the history
add nested object blocks to docs and spec
  • Loading branch information
samjacoby authored Nov 12, 2021
2 parents 33e5dfc + c7ad091 commit 71191c6
Show file tree
Hide file tree
Showing 5 changed files with 1,471 additions and 15 deletions.
15 changes: 8 additions & 7 deletions archieml.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,19 @@ function load(input, options) {
var parsedScopeKey = keyBits[keyBits.length - 1];
}

// Content of nested scopes within a freeform should be stored under "value."
if (stackScope && stackScope.flags.indexOf('+') > -1 && flags.indexOf('.') > -1) {
if (scopeType === '[') parsedScopeKey = 'value';
else if (scopeType === '{') scope = scope.value = {};
}

var stackScopeItem = {
array: null,
arrayType: null,
arrayFirstKey: null,
flags: flags,
scope: scope
};

// Content of nested scopes within a freeform should be stored under "value."
var isNestedFreeform = stackScope && stackScope.flags.indexOf('+') > -1 && flags.indexOf('.') > -1;

if (scopeType == '[') {
if (isNestedFreeform) parsedScopeKey = 'value'
stackScopeItem.array = keyScope[parsedScopeKey] = [];
if (flags.indexOf('+') > -1) stackScopeItem.arrayType = 'freeform';
if (nesting) {
Expand All @@ -207,6 +206,8 @@ function load(input, options) {

} else if (scopeType == '{') {
if (nesting) {
if (isNestedFreeform) scope = scope.value = {};
else scope = keyScope[parsedScopeKey] = keyScope = {};
stack.push(stackScopeItem);
} else {
scope = keyScope[parsedScopeKey] = (typeof keyScope[parsedScopeKey] === 'object') ? keyScope[parsedScopeKey] : {};
Expand Down Expand Up @@ -323,4 +324,4 @@ if (typeof define === 'function' && define.amd) {
return archieml;
});
}
}.call(this))
}.call(this))
50 changes: 46 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ <h3>Nested key structure</h3>
red: #f00
green: #0f0
blue: #00f
{}

{numbers}
one: 1
Expand All @@ -316,18 +317,59 @@ <h3>Nested key structure</h3>
key: value
</aml>

<p>You can end an object with a line beginning with {}, or by beginning a new object. ArchieML is parsed one line at a time, so ending "tags" like {} are never required.</p>

<p>Dot notation can be used in object namespaces as well:</p>
<p>Dot notation can be used in object blocks as well:</p>

<aml>
{colors.reds}
crimson: #dc143c
darkred: #8b0000
{}

{colors.blues}
cornflowerblue: #6495ed
darkblue: #00008b
{}
</aml>

<p>You can close an object by beginning a line with <code>{}</code>. ArchieML is parsed one line at a time, so you can also close an object by opening a new one.</p>

<aml>
{colors}
red: #f00
green: #0f0
blue: #00f

{numbers}
one: 1
ten: 10
one-hundred: 100
{}

key: value
</aml>

<h3>Nested object blocks</h3>

<p>Object blocks with names prepened with a period nest inside of open objects instead of ending them. Beginning a line with <code>{}</code> closes a nested object and returns to the parent.</p>

<aml>
{colors}
red: #f00
green: #0f0
blue: #00f

{.numbers}
one: 1
ten: 10
one-hundred: 100
{}

nestedKey: nestedValue

{months}
january: 0
february: 1

</aml>

<h3>Arrays of objects</h3>
Expand Down Expand Up @@ -387,7 +429,7 @@ <h3 id="nested-arrays">Nested arrays</h3>
key: value
</aml>

<p>Unlike top-level arrays, nested arrays must be "closed" with empty brackets in order to move up to the parent level.</p>
<p>Much like nested object blocks, nested arrays must be "closed" with empty brackets in order to move up to the parent level.</p>

<aml>
[days]
Expand Down
Loading

0 comments on commit 71191c6

Please sign in to comment.