tifParser: Tab Indented Format Parser
This is a simple parser for Tab Indented Format (TIF, the spec of this format is currently in progress).
It transforms a text file into nested objects.
While it is too general to produce anything by itself, it is actually the first stage of more complicated and specific parsers.
- License: MIT
- Current status: alpha / unstable
- Platform: Node.js only
Full BDD spec generated by Mocha:
TOC
Single line
when empty, should return a root node without child.
to ;
with a single word, should return a root node with one child, no comment and the word as content.
to ;
with a many words, should return a root node with one child, no comment and all words as content.
to ;
with a comment, should return a root node with one child, no content and all words as comment.
to ;
with content and comment, should return a root node with one child, having content and comment.
to ;
should trim whitespace in both content and comment.
to ;
should thow error if the line is indented.
try tifParser ; ;catch error to ;
Custom comment mark
with a comment, should return a root node with one child, no content and all words as comment.
to ;
with a comment, should return a root node with one child, no content and all words as comment.
to ;
with content and comment, should return a root node with one child, having content and comment.
to ;
with content and comment, should return a root node with one child, having content and comment.
to ;
Escape sequences
\n should be replaced by a newline.
to ;
\r should be replaced by a carriage return.
to ;
\t should be replaced by a tab.
to ;
> should be replaced by a >.
to ;
\ should be replaced by a single backslash.
to ;
# should escape the comment.
to ;
\# should NOT escape the comment.
to ;
\# should escape the comment.
to ;
\\# should NOT escape the comment.
to ;
should be able to process a mixing of escape sequences.
to ;
Sample file
1 comparison.
var parsed = tifParser ; var expected = depth: 0 children: depth: 1 line: 2 content: undefined comment: "Starting comment" children: depth: 1 content: "Big One" line: 4 comment: undefined children: depth: 2 line: 5 content: "medium1" comment: undefined children: depth: 2 line: 6 content: "medium2" comment: undefined children: depth: 3 line: 7 content: undefined comment: "Comment #1" children: depth: 3 line: 8 content: "little1" comment: undefined children: depth: 3 line: 9 content: undefined comment: "Comment #2" children: depth: 3 line: 10 content: "little2" comment: undefined children: depth: 2 line: 11 content: "medium3" comment: "with a comment" children: depth: 3 line: 12 content: undefined comment: "Comment #3" children: depth: 2 line: 13 content: "medium4 with many words" comment: undefined children: depth: 2 line: 14 content: "medium5 with many words" comment: "and a comment" children: depth: 1 line: 18 content: "Big2" comment: undefined children: depth: 2 line: 22 content: "not a #comment here" comment: undefined children: depth: 1 line: 20 content: undefined comment: "The next node is not a child of this comment" children: depth: 1 line: 25 content: "Big3" comment: undefined children: depth: 2 line: 26 content: "This is\na multi-line\nblock of\ntext" comment: undefined children: depth: 2 line: 31 content: "This is\n another one\n\tand this # is not a comment\n> This is still the same block of text" comment: undefined children: depth: 2 line: 36 content: "A regular text-node" comment: undefined children: depth: 2 line: 38 content: "One line" comment: undefined children: depth: 1 line: 39 content: "This does not belong to the previous block" comment: undefined children: ; to ;to ;