How to use the @accordproject/concerto-core.ParseException function in @accordproject/concerto-core

To help you get started, we’ve selected a few @accordproject/concerto-core 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 accordproject / cicero / packages / cicero-core / src / templateinstance.js View on Github external
parse(input, currentTime, fileName) {
        let text = TemplateLoader.normalizeText(input);
        // Roundtrip the sample through the Commonmark parser
        text = this.getTemplate().getParserManager().roundtripMarkdown(text);

        // Set the current time and UTC Offset
        const now = Util.setCurrentTime(currentTime);
        const utcOffset = now.utcOffset();

        let parser = this.getTemplate().getParserManager().getParser();
        try {
            parser.feed(text);
        } catch(err) {
            const fileLocation = ErrorUtil.locationOfError(err);
            throw new ParseException(err.message, fileLocation, fileName, err.message, 'cicero-core');
        }
        if (parser.results.length !== 1) {
            const head = JSON.stringify(parser.results[0]);

            parser.results.forEach(function (element) {
                if (head !== JSON.stringify(element)) {
                    const err = `Ambiguous text. Got ${parser.results.length} ASTs for text: ${text}`;
                    throw new ParseException(err, null, fileName, err, 'cicero-core' );
                }
            }, this);
        }
        let ast = parser.results[0];
        Logger.debug('Result of parsing: ' + JSON.stringify(ast));

        if(!ast) {
            const err = 'Parsing clause text returned a null AST. This may mean the text is valid, but not complete.';
github accordproject / cicero / packages / cicero-core / src / templateinstance.js View on Github external
if (parser.results.length !== 1) {
            const head = JSON.stringify(parser.results[0]);

            parser.results.forEach(function (element) {
                if (head !== JSON.stringify(element)) {
                    const err = `Ambiguous text. Got ${parser.results.length} ASTs for text: ${text}`;
                    throw new ParseException(err, null, fileName, err, 'cicero-core' );
                }
            }, this);
        }
        let ast = parser.results[0];
        Logger.debug('Result of parsing: ' + JSON.stringify(ast));

        if(!ast) {
            const err = 'Parsing clause text returned a null AST. This may mean the text is valid, but not complete.';
            throw new ParseException(err, null, fileName, err, 'cicero-core' );
        }

        ast = TemplateInstance.convertDateTimes(ast, utcOffset);
        this.setData(ast);
    }
github accordproject / cicero / packages / cicero-core / src / templateinstance.js View on Github external
parser.results.forEach(function (element) {
                if (head !== JSON.stringify(element)) {
                    const err = `Ambiguous text. Got ${parser.results.length} ASTs for text: ${text}`;
                    throw new ParseException(err, null, fileName, err, 'cicero-core' );
                }
            }, this);
        }