Commits

kates committed 6568401

parse empty comment line

Comments (0)

Files changed (2)

lib/grammar.pegjs

 	= doc*
 
 doc
-	= "/**" "\n" body:body? "*/" "\n"* functionBody { return {comment: body};}
+	= whitespace* "/**" whitespace* body:body? whitespace* "*/" whitespace* functionBody { return {comment: body};}
 
 body
-	= line:line* { return {tags: line};}
+	= lines:line* { var tags = []; for (var i=0; i<lines.length; i++){ if (lines[i] != '') { tags.push(lines[i]);}} return {tags: tags};}
 
 line
-	= " "* "*" " "+ "@" tag:ident " " value:ident "\n"+ { return {tag: tag, value: value};}
+	= " "* "*" whitespace+ comment:comment? { return comment;}
 
+ignoreLine
+	= " "* "*" whitespace+
+
+comment
+	= "@" tag:ident " "+ value:ident whitespace+ { return {tag: tag, value: value};}
 
 functionBody
-	= "function" " "+ ident "(" ")" "{" "}" "\n"*
+	= "function" " "+ ident "(" ")" "{" "}" whitespace*
+
+whitespace
+	= " "
+	/ "\n"
 
 ident
 	= chars:[0-9a-zA-Z]* { return chars.join('');}

test/parser-test.js

 var buster = require("buster");
 var parser = require("../lib/parser").parser;
+var fs = require('fs');
+
 
 buster.testCase("Parser", {
-	"comment block": function() {
-		var code = "/**\n * @name Klass\n\n * @param num\n * @param num2\n*/\nfunction Klass(){}";
+	"comment block 1": function() {
+		var code = "/**\n * @name Klass\n * @param num\n * @param num2\n*/\nfunction Klass(){}";
 		var ast = parser.parse(code);
 
 		assert.equals(ast[0]['comment']['tags'].length, 3);
-		assert.equals(ast[0]['comment']['tags'][0]['tag'], 'name')
-		assert.equals(ast[0]['comment']['tags'][1]['tag'], 'param')
+		assert.equals(ast[0]['comment']['tags'][0]['tag'], 'name');
+		assert.equals(ast[0]['comment']['tags'][1]['tag'], 'param');
+	},
+	"comment block 2": function() {
+		var code = "/**\n * @name Klass\n *\n * @param num\n * @param num2\n*/\nfunction Klass(){}";
+		var ast = parser.parse(code);
+		console.log(ast[0]['comment']);
+		assert.equals(ast[0]['comment']['tags'].length, 3);
+		assert.equals(ast[0]['comment']['tags'][0]['tag'], 'name');
+		assert.equals(ast[0]['comment']['tags'][1]['tag'], 'param');
 	}
 });