newsdev / archieml-js

JavaScript parser for the Archie Markup Language (ArchieML)
http://archieml.org
Other
205 stars 19 forks source link

Multi-line values are created when they shouldn't be #4

Closed minikomi closed 9 years ago

minikomi commented 9 years ago

I'm not sure what the expected result is but this seems a little odd:

key:value
multi-line-value
[singleword]
another multi line value
:end

Output:

{
  "key": "valueanother multi line value",
  "yeah": []
}

multi-line-value has disappeared, and there's also no newlines in the output.

When there is a multi-word value within the square brackets, it is treated as a comment and we get:

key:value
multi-line-value
[double word]
another multi line value
:end

{
  "key": "value\nmulti-line-value\n\nanother multi line value"
}

Which seems more consistent with the other rules.

minikomi commented 9 years ago

Another strange edge case:

key:value
multi-line-value
[singleword]
newkey:yeah
[]
another multi line value
:end

Result:

{
  "key": "value",
  "singleword": [
    {
      "newkey": "yeah"
    }
  ],
  "newkey": "undefinedanother multi line value"
}
minikomi commented 9 years ago

Also seems to be related:

{scope}
key:value
{}
value2
:end

result:

{
  "scope": {
    "key": "value"
  },
  "key": "undefinedvalue2"
}
abstrctn commented 9 years ago

Hey @minikomi - thanks for all of the examples, these were all bugs in the way archieml-js was handling multi-line values. We can continue the discussion here if there are any questions / concerns about the behavior in any specific circumstances, but the way we intended it to work was:

Start any value with either a key: value, or with an asterisk in the case of a simple array * value). The value as defined on that line is always included as the value. Sequential lines are added to the value only if those lines 1) do not contain any lines that would be interpreted as commands (i.e., {}), and are followed with an :end line.

All of the examples above broke because the javascript parser was trying to add the lines immediately preceding :end to the last key that was defined, even though there was a command line in the middle of the value that should have prevented it from being interpreted as a multi-line value.

I'm uploading a patch now that will cause key in most of your examples to wind up as a single-line value, value.