Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Updating archieml-js to v0.1.2
Browse files Browse the repository at this point in the history
Merge commit '479318134c30733fdd24feb8d0d6099b9bbaab9a'
  • Loading branch information
noamross committed Mar 17, 2015
2 parents 1447b46 + 4793181 commit a442008
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
12 changes: 11 additions & 1 deletion inst/archieml-js/README.md
Expand Up @@ -4,7 +4,7 @@ Parse Archie Markup Language (ArchieML) documents into JavaScript objects.

Read about the ArchieML specification at [archieml.org](http://archieml.org).

The current version is `v0.1.0`.
The current version is `v0.1.2`.

## Installation

Expand Down Expand Up @@ -55,6 +55,16 @@ You can use a test document to start that's public to everyone. It will ask you

[`http://127.0.0.1:3000/1JjYD90DyoaBuRYNxa4_nqrHKkgZf1HrUj30i3rTWX1s`](http://127.0.0.1:3000/1JjYD90DyoaBuRYNxa4_nqrHKkgZf1HrUj30i3rTWX1s)

## Tests

There is a full test suite under the `test/` directory. Simply open up `test/index.html` in a web browser to run it.

```
rspec
```

## Changelog

* `0.1.2` - More consistent handling of newlines. Fixes issue #4, around detecting the scope of multi-line values.
* `0.1.1` - Fixes issue #1, removing comment backslashes.
* `0.1.0` - Initial release supporting the first version of the ArchieML spec, published [2015-03-06](http://archieml.org/spec/1.0/CR-20150306.html).
14 changes: 7 additions & 7 deletions inst/archieml-js/archieml.js
Expand Up @@ -10,10 +10,10 @@
// which match patterns for different types of commands in AML.
function load(input) {
var nextLine = new RegExp('.*((\r|\n)+)');
var startKey = new RegExp('^\\s*([A-Za-z0-9-_\.]+)[ \t\r]*:[ \t\r]*(.*)');
var commandKey = new RegExp('^\\s*:[ \t\r]*(endskip|ignore|skip|end)', 'i');
var arrayElement = new RegExp('^\\s*\\*[ \t\r]*(.*)');
var scopePattern = new RegExp('^\\s*(\\[|\\{)[ \t\r]*([A-Za-z0-9-_\.]*)[ \t\r]*(?:\\]|\\})[ \t\r]*.*?(\n|\r|$)');
var startKey = new RegExp('^\\s*([A-Za-z0-9-_\.]+)[ \t\r]*:[ \t\r]*(.*(?:\n|\r|$))');
var commandKey = new RegExp('^\\s*:[ \t\r]*(endskip|ignore|skip|end).*?(\n|\r|$)', 'i');
var arrayElement = new RegExp('^\\s*\\*[ \t\r]*(.*(?:\n|\r|$))');
var scopePattern = new RegExp('^\\s*(\\[|\\{)[ \t\r]*([A-Za-z0-9-_\.]*)[ \t\r]*(?:\\]|\\}).*?(\n|\r|$)');

var data = {},
scope = data,
Expand Down Expand Up @@ -129,8 +129,6 @@ function load(input) {
isSkipping = false;
break;
}

flushBuffer();
}

function parseScope(scopeType, scopeKey) {
Expand Down Expand Up @@ -160,6 +158,7 @@ function load(input) {

if (scopeType == '[') {
array = keyScope[keyBits[keyBits.length - 1]] = keyScope[keyBits[keyBits.length - 1]] || [];
if (typeof array == 'string') array = keyScope[keyBits[keyBits.length - 1]] = [];
// If we're reopening this array, set the arrayType
if (array.length > 0) arrayType = typeof array[0] === 'string' ? 'simple' : 'complex';

Expand All @@ -177,7 +176,7 @@ function load(input) {
// If we're appending to a multi-line string, escape special punctuation
// by using a backslash at the beginning of any line.
// Note we do not do this processing for the first line of any value.
value = value.replace(new RegExp('^(\\s*)\\\\'), "$1");
value = value.replace(new RegExp('^(\\s*)\\\\', 'gm'), "$1");
}

return value;
Expand Down Expand Up @@ -225,6 +224,7 @@ function load(input) {
array = null;
arrayType = null;
arrayFirstKey = null;
bufferKey = null;
}

flushBuffer();
Expand Down
2 changes: 1 addition & 1 deletion inst/archieml-js/package.json
@@ -1,6 +1,6 @@
{
"name": "archieml",
"version": "0.1.0",
"version": "0.1.2",
"description": "JavaScript parser for the Archie Markup Language (ArchieML)",
"homepage": "http://archieml.org",
"keywords": [
Expand Down
27 changes: 25 additions & 2 deletions inst/archieml-js/test/archieml.js
Expand Up @@ -22,8 +22,8 @@
equal(Object.keys(load('k&ey:value')).length, 0, 'symbols are not allowed in keys');
equal(load('scope.key:value').scope.key, 'value', 'keys can be nested using dot-notation');
equal(load('scope.key:value\nscope.otherkey:value').scope.key, 'value', "earlier keys within scopes aren't deleted when using dot-notation");
deepEqual(load('scope.level:value\nscope.level.level:value').scope.level.level, 'value', 'the value of key that used to be a parent object should be replaced with a string if necessary');
equal(load('scope.level.level:value\nscope.level:value').scope.level, 'value', 'the value of key that used to be a string object should be replaced with an object if necessary');
deepEqual(load('scope.level:value\nscope.level.level:value').scope.level.level, 'value', 'the value of key that used to be a string object should be replaced with an object if necessary');
equal(load('scope.level.level:value\nscope.level:value').scope.level, 'value', 'the value of key that used to be a parent object should be replaced with a string if necessary');
});

test('valid values', function() {
Expand Down Expand Up @@ -94,9 +94,16 @@
equal(load('key:value\n\\[comment]\n:end').key, 'value', 'allows escaping [comments] at the beginning of lines');
equal(load('key:value\n\\[[array]]\n:end').key, 'value\n[array]', 'allows escaping [[arrays]] at the beginning of lines');

equal(load('key:value\ntext\n[array]\nmore text\n:end').key, 'value', 'arrays within a multi-line value breaks up the value');
equal(load('key:value\ntext\n{scope}\nmore text\n:end').key, 'value', 'objects within a multi-line value breaks up the value');
equal(load('key:value\ntext\n* value\nmore text\n:end').key, 'value\ntext\n* value\nmore text', 'bullets within a multi-line value do not break up the value');
equal(load('key:value\ntext\n:skip\n:endskip\nmore text\n:end').key, 'value\ntext\nmore text', 'skips within a multi-line value do not break up the value');

equal(load('key:value\n\\\\:end\n:end').key, 'value\n\\:end', 'allows escaping initial backslash at the beginning of lines');
equal(load('key:value\n\\\\\\:end\n:end').key, 'value\n\\\\:end', 'escapes only one initial backslash');

equal(load('key:value\n\\:end\n\\:ignore\n\\:endskip\n\\:skip\n:end').key, 'value\n:end\n:ignore\n:endskip\n:skip', 'allows escaping multiple lines in a value');

equal(load('key:value\nLorem key2\\:value\n:end').key, 'value\nLorem key2\\:value', "doesn't escape colons after beginning of lines");
});

Expand Down Expand Up @@ -156,8 +163,16 @@
equal(load('[array]\n*Value1\n\\key:value\n:end').array[0], "Value1\nkey:value", 'allows escaping key lines with a leading backslash');
equal(load('[array]\n*Value1\nword key\\:value\n:end').array[0], "Value1\nword key\\:value", 'does not allow escaping of colons not at the beginning of lines');

equal(load('[array]\n* value\n[array]\nmore text\n:end').array[0], 'value', 'arrays within a multi-line value breaks up the value');
equal(load('[array]\n* value\n{scope}\nmore text\n:end').array[0], 'value', 'objects within a multi-line value breaks up the value');
equal(load('[array]\n* value\nkey: value\nmore text\n:end').array[0], 'value\nkey: value\nmore text', 'key/values within a multi-line value do not break up the value');
equal(load('[array]\n* value\n* value\nmore text\n:end').array[0], 'value', 'bullets within a multi-line value break up the value');
equal(load('[array]\n* value\n:skip\n:endskip\nmore text\n:end').array[0], 'value\nmore text', 'skips within a multi-line value do not break up the value');

equal(load('[array]\n*Value\n[]\n[array]\n*Value').array.length, 2, 'arrays that are reopened add to existing array');
deepEqual(load('[array]\n*Value\n[]\n[array]\nkey:value').array, ["Value"], 'simple arrays that are reopened remain simple');

equal(load('a.b:complex value\n[a.b]\n*simple value').a.b[0], 'simple value', 'simple ararys overwrite existing keys');
});

test('complex arrays', function() {
Expand All @@ -170,8 +185,16 @@
equal(load('[array]\nkey:value\nscope.key:value').array.length, 1, 'duplicate keys must match on dot-notation scope');
equal(load('[array]\nscope.key:value\nkey:value\notherscope.key:value').array.length, 1, 'duplicate keys must match on dot-notation scope');

equal(load('[array]\nkey:value\n[array]\nmore text\n:end').array[0].key, 'value', 'arrays within a multi-line value breaks up the value');
equal(load('[array]\nkey:value\n{scope}\nmore text\n:end').array[0].key, 'value', 'objects within a multi-line value breaks up the value');
equal(load('[array]\nkey:value\nother: value\nmore text\n:end').array[0].key, 'value', 'key/values within a multi-line value break up the value');
equal(load('[array]\nkey:value\n* value\nmore text\n:end').array[0].key, 'value\n* value\nmore text', 'bullets within a multi-line value do not break up the value');
equal(load('[array]\nkey:value\n:skip\n:endskip\nmore text\n:end').array[0].key, 'value\nmore text', 'skips within a multi-line value do not break up the value');

equal(load('[array]\nkey:value\n[]\n[array]\nkey:value').array.length, 2, 'arrays that are reopened add to existing array');
deepEqual(load('[array]\nkey:value\n[]\n[array]\n*Value').array, [{"key": "value"}], 'complex arrays that are reopened remain complex');

equal(load('a.b:complex value\n[a.b]\nkey:value').a.b[0].key, 'value', 'complex ararys overwrite existing keys');
});

test('inline comments', function() {
Expand Down

0 comments on commit a442008

Please sign in to comment.