Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const Parsimmon = require('parsimmon');
const tagsParser = require('./tags-parser')
const string = Parsimmon.string;
const regex = Parsimmon.regex;
const succeed = Parsimmon.succeed;
const alt = Parsimmon.alt;
const seq = Parsimmon.seq;
const seqMap = Parsimmon.seqMap;
const lazy = Parsimmon.lazy;
const eof = Parsimmon.eof;
const ignore = regex(/\s*/m);
function lexeme(p) {
return p.skip(ignore);
}
// Base context-free grammar
const colon = lexeme(string(':'));
const flag = lexeme(string('#+'));
const startOfLine = lexeme(regex(/\n*/));
const identifier = lexeme(regex(/[a-z]+/i));
const singleLineText = lexeme(regex(/[^\n]+/));
const multiline = lexeme(regex(/[^\*]*/));
// Complex context-free grammar
const blockOption = seq(
startOfLine, flag, identifier, colon, singleLineText
module.exports = function(ps) {
return P.string("#")
.then(NotNewlines)
.skip(Newline.or(P.eof));
};
function: function (r) { return P.seqObj(r.fnKeyword, r.lparen, ['args', r.arg.sepBy(r.comma).desc('args')], r.rparen, r.lbrace, r.return, ['obj', r.letters], ['keyPath', r.field.sepBy(r._)], r.semi.or(r._), r.rbrace, P.eof); },
lambda: function (r) { return P.seqObj(r.lparen.or(r._), ['args', r.arg.sepBy(r.comma).desc('args')], r.rparen.or(r._), r.arrow, r.lbrace.or(r._), r.return.or(r._), ['obj', r.letters], ['keyPath', r.field.sepBy(r._)], r.semi.or(r._), r.rbrace.or(r._), P.eof); },
lambda: r => P.seqObj(
r.lparen.or(r._),
['args', r.arg.sepBy(r.comma).desc('args')],
r.rparen.or(r._),
r.arrow,
r.lbrace.or(r._),
r.return.or(r._),
['obj', r.letters],
['keyPath', r.field.sepBy(r._)],
r.semi.or(r._),
r.rbrace.or(r._),
P.eof,
),
function: r => P.seqObj(
r.fnKeyword,
r.lparen,
['args', r.arg.sepBy(r.comma).desc('args')],
r.rparen,
r.lbrace,
r.return,
['obj', r.letters],
['keyPath', r.field.sepBy(r._)],
r.semi.or(r._),
r.rbrace,
P.eof,
),
lambda: r => P.seqObj(
lambda: function (r) { return P.seqObj(r.lparen.or(r._), ['args', r.arg.sepBy(r.comma).desc('args')], r.rparen.or(r._), r.arrow, r.lbrace.or(r._), r.return.or(r._), ['obj', r.letters], ['keyPath', r.field.sepBy(r._)], r.semi.or(r._), r.rbrace.or(r._), P.eof); },
accessor: function (r) { return r.function.or(r.lambda); }
return P.alt(
P.seqMap(
P.string("{%")
.then(P.whitespace)
.then(P.string("name=" + blockType.name))
.then(JSONParser.value.trim(P.optWhitespace))
.skip(P.string("%}")),
innerBlockParser.trim(r.newline),
P.string("{% end %}"),
(attributes, block) => {
return Object.assign({}, block, {
attributes: Object.assign(attributes, block.attributes)
});
}
),
innerBlockParser.lookahead(P.alt(r.newline, P.eof))
).map(({ name, attributes }) => createBlock(name, attributes));
};
};