From 13ae16997d4bbca14e255d5989d1c44a76eac72c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 15:23:48 -0700 Subject: montage v.0.10 integration Signed-off-by: Valerio Virgillito --- node_modules/montage/core/selector/parser.js | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 node_modules/montage/core/selector/parser.js (limited to 'node_modules/montage/core/selector/parser.js') diff --git a/node_modules/montage/core/selector/parser.js b/node_modules/montage/core/selector/parser.js new file mode 100644 index 00000000..b674218c --- /dev/null +++ b/node_modules/montage/core/selector/parser.js @@ -0,0 +1,62 @@ + +var Montage = require("montage").Montage; + +var Parser = exports.Parser = Montage.create(Montage, { + + newWithLanguage: { + value: function (language, callback) { + var self = Montage.create(this); + self.tokens = []; + self.state = language.parsePrevious(function (syntax) { + callback && callback(syntax); + return language.parseEof(); + }); + return self; + } + }, + + state: { + value: null, + writable: true + }, + + emit: { + value: function (token) { + try { + this.tokens.push(token); + this.state = this.state(token); + return this; + } catch (exception) { + if (exception instanceof SyntaxError) { + throw new SyntaxError(exception.message + ' at ' + this.format()); + } else { + throw exception; + } + } + } + }, + + state: { + value: null, + writable: true + }, + + syntax: { + value: null, + writable: true, + serializable: true + }, + + format: { + value: function () { + return this.tokens.reduce(function (hither, token) { + if (token.type === 'literal') { + return hither + '(' + JSON.stringify(token.value) + ')'; + } else { + return hither + '.' + token.type; + } + }, 'Selector'); + } + } + +}); -- cgit v1.2.3