How to use the parsimmon/build/parsimmon.browser.string function in parsimmon

To help you get started, we’ve selected a few parsimmon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caolan / magery / parsers.js View on Github external
).chain(function (name) {
    return p.alt(
        p.string("/}}").desc("self-closed tag '/}}'"),
        p.string("}}").then(defineInner.skip(p.string('{{/define}}')))
    ).map(function (contents) {
        return {
            name: name,
            contents: contents
        };
    });
});
github caolan / magery / parsers.js View on Github external
}
        throw e;
    }
    return result.value;
};

var basicString = p.regex(/(?!{{)[\s\S]+?(?={{)/)
    .desc('non-template chars');

var variableName = p.regex(/\s*(?!\d)(\.|(?:(?:[^"\.\s\,=}/]\.?)+))/, 1)
    .desc('variable name')
    .map(function (x) {
        return {type: 'property', value: x};
     });

var trueLiteral = p.string('true').skip(p.optWhitespace)
    .result({type: 'boolean', value: true});

var falseLiteral = p.string('false').skip(p.optWhitespace)
    .result({type: 'boolean', value: false});

var booleanLiteral = p.alt(trueLiteral, falseLiteral).desc('boolean');

var numberLiteral = p.regex(/-?(0|[1-9]\d*)([.]\d+)?(e[+-]?\d+)?/i)
    .skip(p.optWhitespace)
    .desc('numeral')
    .map(function (x) {
        return {type: 'number', value: Number(x)};
    });

var stringLiteral = p.regex(/"((?:\\.|.)*?)"/, 1)
    .skip(p.optWhitespace)
github caolan / magery / parsers.js View on Github external
).chain(function (name) {
    return p.alt(
        p.string("/}}").desc("self-closed tag '/}}'"),
        p.string("}}").then(defineInner.skip(p.string('{{/define}}')))
    ).map(function (contents) {
        return {
            name: name,
            contents: contents
        };
    });
});
github caolan / magery / parsers.js View on Github external
else {
            args.push(x);
        }
    }
    return {
        args: args,
        kwargs: kwargs
    };
});

var defineInner = p.regex(/(?!{{[\/#]define[\s}])[\s\S]+?(?={{[\/#]define[\s}])/)
        .desc('template definition block');

var defineTag = p.seqMap(
    p.optWhitespace,
    p.string("{{#define").desc("{{#define..."),
    p.whitespace,
    variableName.desc('definition name'),
    function (before, define, _, name) {
        return name.value;
    }
).chain(function (name) {
    return p.alt(
        p.string("/}}").desc("self-closed tag '/}}'"),
        p.string("}}").then(defineInner.skip(p.string('{{/define}}')))
    ).map(function (contents) {
        return {
            name: name,
            contents: contents
        };
    });
});
github caolan / magery / parsers.js View on Github external
return result.value;
};

var basicString = p.regex(/(?!{{)[\s\S]+?(?={{)/)
    .desc('non-template chars');

var variableName = p.regex(/\s*(?!\d)(\.|(?:(?:[^"\.\s\,=}/]\.?)+))/, 1)
    .desc('variable name')
    .map(function (x) {
        return {type: 'property', value: x};
     });

var trueLiteral = p.string('true').skip(p.optWhitespace)
    .result({type: 'boolean', value: true});

var falseLiteral = p.string('false').skip(p.optWhitespace)
    .result({type: 'boolean', value: false});

var booleanLiteral = p.alt(trueLiteral, falseLiteral).desc('boolean');

var numberLiteral = p.regex(/-?(0|[1-9]\d*)([.]\d+)?(e[+-]?\d+)?/i)
    .skip(p.optWhitespace)
    .desc('numeral')
    .map(function (x) {
        return {type: 'number', value: Number(x)};
    });

var stringLiteral = p.regex(/"((?:\\.|.)*?)"/, 1)
    .skip(p.optWhitespace)
    .desc('quoted string')
    .map(interpretEscapes)
    .map(function (x) {