parser-combinator
Version:
Parser combinators
60 lines (50 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _index = require('../../parsec/index');
// resolve meanningles characters as an empty string
// also accept an empty string
function blank() {
return _index.C.charIn(' \t').optrep().thenReturns('');
}
//todo: escape characters
function rawTextUntilChar(charList) {
var allowVoid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (allowVoid) {
return _index.C.charNotIn(charList).optrep().map(function (chars) {
return chars.join('');
});
} else {
return _index.C.charNotIn(charList).rep().map(function (chars) {
return chars.join('');
});
}
}
function rawTextUntil(stop) {
return _index.F.not(stop).rep().map(function (chars) {
return chars.join('');
});
}
function eol() {
return _index.C.char('\n').or(_index.C.string('\r\n'));
}
//A blank line in the code(that is 2 consecutive \n) is a single end of line (lineFeed) in the rendition
function lineFeed() {
return eol().then(blank()).then(eol()).thenReturns({
linefeed: undefined
});
}
//accept 1 tab or 4 spaces. Space may be unbreakable
function fourSpacesBlock() {
return _index.C.char('\t').or(_index.C.charIn(' \xA0').occurrence(4));
}
exports.default = {
blank: blank,
rawTextUntilChar: rawTextUntilChar,
rawTextUntil: rawTextUntil,
eol: eol,
lineFeed: lineFeed,
fourSpacesBlock: fourSpacesBlock
};
//# sourceMappingURL=token.js.map