diff --git a/lib/tags.js b/lib/tags.js index 7759e81..d515bdd 100644 --- a/lib/tags.js +++ b/lib/tags.js @@ -1,4 +1,4 @@ -var Access, Anchor, AnonFunction, Block, Content, DoWhile, Else, For, Func, Group, If, Invoke, Member, NamedFunction, Parameters, ScriptBlock, Tag, Value, While, +var Access, Anchor, Block, Content, DoWhile, Else, For, Func, Group, If, Invoke, Member, Parameters, ScriptBlock, Tag, Value, While, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; @@ -203,45 +203,6 @@ DoWhile = (function(_super) { })(Tag); -AnonFunction = (function(_super) { - - __extends(AnonFunction, _super); - - AnonFunction.prototype.name = 'AnonFunction'; - - function AnonFunction(args, block) { - this.args = args; - this.block = block; - } - - AnonFunction.prototype.parts = function() { - return ['function', this.args, this.block]; - }; - - return AnonFunction; - -})(Tag); - -NamedFunction = (function(_super) { - - __extends(NamedFunction, _super); - - NamedFunction.prototype.name = 'NamedFunction'; - - function NamedFunction(identifier, args, block) { - this.identifier = identifier; - this.args = args; - this.block = block; - } - - NamedFunction.prototype.parts = function() { - return ['function ', this.identifier, this.args, this.block]; - }; - - return NamedFunction; - -})(Tag); - Func = (function(_super) { __extends(Func, _super); @@ -365,8 +326,6 @@ module.exports = { For: For, While: While, DoWhile: DoWhile, - AnonFunction: AnonFunction, - NamedFunction: NamedFunction, Func: Func, Parameters: Parameters, Value: Value, diff --git a/lib/tokenizer.js b/lib/tokenizer.js index c7c8230..4b67043 100644 --- a/lib/tokenizer.js +++ b/lib/tokenizer.js @@ -1,4 +1,4 @@ -var ACCESS, ANCHOR, Access, Anchor, BLOCK, Block, Content, DO, DO_WHILE, DoWhile, ELSE, Else, FOR, FUNC, Failure, For, Func, GROUP, Group, IDENTIFIER, IF, INVOKE, If, Invoke, MEMBER, Member, NoMatch, PARAMETERS, Parameters, ScriptBlock, Success, TRAILING_SPACES, Tokenizer, Value, WHILE, WHITESPACE, While, failure, success, _ref, _ref2; +var ACCESS, ANCHOR, Access, Anchor, BLOCK, Block, COMMENT, Content, DO, DO_WHILE, DoWhile, ELSE, Else, FOR, FUNC, Failure, For, Func, GROUP, Group, IDENTIFIER, IF, INVOKE, If, Invoke, MEMBER, Member, NoMatch, PARAMETERS, Parameters, ScriptBlock, Success, TRAILING_SPACES, Tokenizer, Value, WHILE, WHITESPACE, While, failure, success, _ref, _ref2; _ref = require('./tags'), Anchor = _ref.Anchor, Content = _ref.Content, Group = _ref.Group, Block = _ref.Block, ScriptBlock = _ref.ScriptBlock, If = _ref.If, Else = _ref.Else, For = _ref.For, While = _ref.While, DoWhile = _ref.DoWhile, Func = _ref.Func, Parameters = _ref.Parameters, Value = _ref.Value, Member = _ref.Member, Access = _ref.Access, Invoke = _ref.Invoke; @@ -38,6 +38,8 @@ ACCESS = /^\s*\[/; INVOKE = /^\s*\(/; +COMMENT = /^\*/; + module.exports = Tokenizer = (function() { function Tokenizer() {} @@ -92,7 +94,7 @@ module.exports = Tokenizer = (function() { if (chunk[0] !== '@') return NoMatch; start = 1; chunk = chunk.slice(start); - result = this.Parameters(chunk) || this.Escape(chunk) || this.If(chunk) || this.For(chunk) || this.While(chunk) || this.DoWhile(chunk) || this.Func(chunk) || this.Group(chunk) || this.ScriptBlock(chunk) || this.Value(chunk); + result = this.Comment(chunk) || this.Parameters(chunk) || this.Escape(chunk) || this.If(chunk) || this.For(chunk) || this.While(chunk) || this.DoWhile(chunk) || this.Func(chunk) || this.Group(chunk) || this.ScriptBlock(chunk) || this.Value(chunk); if (result != null ? result.success : void 0) { offset = start + result.offset; value = new Anchor(result.get()); @@ -103,6 +105,21 @@ module.exports = Tokenizer = (function() { return result; }; + Tokenizer.prototype.Comment = function(chunk) { + var error, match, offset, start, value; + if (!(match = COMMENT.exec(chunk))) return NoMatch; + start = match[0].length; + match = chunk.slice(start).match(/\*\@\s*/); + if (!(match != null)) { + offset = start; + error = 'malformed comment'; + return failure(offset, error); + } + offset = start + match.index + match[0].length; + value = new Content(''); + return success(offset, value); + }; + Tokenizer.prototype.Parameters = function(chunk) { var end, error, match, offset, parameters, start, value; if (!(match = PARAMETERS.exec(chunk))) return NoMatch; @@ -392,7 +409,7 @@ module.exports = Tokenizer = (function() { error = 'malformed array access'; return failure(offset, error); } - results = this.replace(chunk.slice(start + 1, (end - 1)), 'function', this.Function.bind(this)); + results = this.replace(chunk.slice(start + 1, (end - 1)), 'function', this.Func.bind(this)); offset = start + end; value = new Access(results); return success(offset, value); diff --git a/src/tags.coffee b/src/tags.coffee index e0d2aab..489582b 100644 --- a/src/tags.coffee +++ b/src/tags.coffee @@ -95,8 +95,6 @@ module.exports = { For While DoWhile - AnonFunction - NamedFunction Func Parameters Value diff --git a/src/tokenizer.coffee b/src/tokenizer.coffee index ef8f990..2f8bb4b 100644 --- a/src/tokenizer.coffee +++ b/src/tokenizer.coffee @@ -42,6 +42,7 @@ IDENTIFIER = /^[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*/ MEMBER = /^\s*\./ ACCESS = /^\s*\[/ INVOKE = /^\s*\(/ +COMMENT = /^\*/ module.exports = class Tokenizer @@ -91,6 +92,7 @@ module.exports = class Tokenizer chunk = chunk[start..] result = + @Comment(chunk) or @Parameters(chunk) or @Escape(chunk) or @If(chunk) or @@ -111,6 +113,22 @@ module.exports = class Tokenizer return result + Comment: (chunk) -> + return NoMatch unless match = COMMENT.exec chunk + + start = match[0].length + match = chunk[start..].match /\*\@\s*/ + + if not match? + offset = start + error = 'malformed comment' + return failure offset, error + + offset = start + match.index + match[0].length + value = new Content('') + return success offset, value + + Parameters: (chunk) -> return NoMatch unless match = PARAMETERS.exec chunk diff --git a/test/hello.txt b/test/hello.txt index f4f9fd1..1926744 100644 --- a/test/hello.txt +++ b/test/hello.txt @@ -1,3 +1,7 @@ hello world! +@* + * Comment Block! + *@ + @render('compose/header')