Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
codex
committed
Dec 19, 2011
1 parent
f4cde20
commit d929f02
Showing
6 changed files
with
70 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
README | ||
tater parses out annotated codeblocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
tokenize = require('parsimony').tokenize | ||
getLeadspace = require('parsimony').getLeadspace | ||
|
||
annotate = (dsl, annotationDelim, next) -> | ||
|
||
annotationDelim ?= "#>>" | ||
parsingDelim = new RegExp( annotationDelim + '(.+)\n' ) | ||
|
||
tokenize dsl, parsingDelim, (tokens) -> | ||
|
||
tokens.shift() # remove first token | ||
|
||
# the first and then every other token is an annotation | ||
# immediately following a token is a codeblock | ||
|
||
blocks = [] | ||
|
||
for annotation, index in tokens by 2 | ||
|
||
# the next token is code | ||
code = tokens[index + 1] | ||
|
||
blocks.push | ||
# block: | ||
annotation: annotation.trim() | ||
code: code.trim() | ||
leadspace: getLeadspace code | ||
|
||
next blocks | ||
|
||
module.exports = annotate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#>> Setup | ||
|
||
should = require 'should' | ||
annotate = require '../annotate' | ||
|
||
#>> Given some DSL code | ||
|
||
code = | ||
''' | ||
>> Given some dsl code | ||
foo = "foo" | ||
''' | ||
|
||
#>> when it is tokenized | ||
|
||
annotate code, '>>', (blocks) -> | ||
|
||
#>> Then | ||
|
||
blocks[0].annotation.should.equal "Given some dsl code" | ||
blocks[0].code.should.equal 'foo = "foo"' | ||
blocks[0].leadspace.should.equal " " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
annotate = require './services/annotate' | ||
|
||
tater = | ||
|
||
parse: (dsl, delim, next) -> annotate dsl, delim, next | ||
|
||
|
||
module.exports = tater |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters