123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 'use strict';
- var Base = require('base');
- var define = require('define-property');
- var Compiler = require('./lib/compiler');
- var Parser = require('./lib/parser');
- var utils = require('./lib/utils');
- var regexCache = {};
- var cache = {};
- function Snapdragon(options) {
- Base.call(this, null, options);
- this.options = utils.extend({source: 'string'}, this.options);
- this.compiler = new Compiler(this.options);
- this.parser = new Parser(this.options);
- Object.defineProperty(this, 'compilers', {
- get: function() {
- return this.compiler.compilers;
- }
- });
- Object.defineProperty(this, 'parsers', {
- get: function() {
- return this.parser.parsers;
- }
- });
- Object.defineProperty(this, 'regex', {
- get: function() {
- return this.parser.regex;
- }
- });
- }
- Base.extend(Snapdragon);
- Snapdragon.prototype.capture = function() {
- return this.parser.capture.apply(this.parser, arguments);
- };
- Snapdragon.prototype.use = function(fn) {
- fn.call(this, this);
- return this;
- };
- Snapdragon.prototype.parse = function(str, options) {
- this.options = utils.extend({}, this.options, options);
- var parsed = this.parser.parse(str, this.options);
-
- define(parsed, 'parser', this.parser);
- return parsed;
- };
- Snapdragon.prototype.compile = function(ast, options) {
- this.options = utils.extend({}, this.options, options);
- var compiled = this.compiler.compile(ast, this.options);
-
- define(compiled, 'compiler', this.compiler);
- return compiled;
- };
- module.exports = Snapdragon;
- module.exports.Compiler = Compiler;
- module.exports.Parser = Parser;
|