Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-building the parser can fail #277

Closed
jeromesimeon opened this issue Aug 7, 2020 · 1 comment
Closed

Re-building the parser can fail #277

jeromesimeon opened this issue Aug 7, 2020 · 1 comment
Assignees
Labels

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Aug 7, 2020

Describe the bug
Building the parser sometimes fail. We should be able to rebuild the parser (e.g., to handle changes to the grammar). It seems to indicate the internals of the parser generation keeps some state when it shouldn't.

To Reproduce
Steps to reproduce the behavior:

Tested internally by calling buildParser twice in the parsermanager:

    /**
     * Build the parser
     */
    testBuildParser() {
        if (!this.templateMark) {
            const tokenStream = templateToTokens(this.template);
            const template = tokensToUntypedTemplateMark(tokenStream, this.templateKind);
            this.templateMark = templateMarkTyping(template, this.modelManager, this.templateKind);
        }
        this.parser = this.parserVisitor.toParser(this,this.templateMark,this.parsingTable);
    }

    /**
     * Build the parser
     */
    buildParser() {
        this.testBuildParser();
        this.testBuildParser();
    }

This results in some errors in a few tests:

  2) #TemplateMarkTransformer [Parse Success]
       #latedeliveryandpenalty
         should parse sample:
     TypeError: Cannot read property 'map' of undefined
      at result (lib/toparserrules.js:73:38)
      at P.seqMap.apply.parsers.map.x (lib/combinators.js:257:57)
      at Array.map (<anonymous>)
      at /Users/jeromesimeon/git/markdown-transform/packages/markdown-template/lib/combinators.js:257:48
      at parameters.result (lib/ToParserVisitor.js:39:16)
      at P.seqMap.apply.parsers.map.x (lib/combinators.js:257:57)
      at Array.map (<anonymous>)
      at /Users/jeromesimeon/git/markdown-transform/packages/markdown-template/lib/combinators.js:257:48
      at Object.org.accordproject.cicero.contract.AccordParty (lib/parsingtable.js:105:47)
      at func (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:803:30)
      at Parsimmon._ (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:1283:16)
      at Parsimmon._ (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:1017:23)
      at Parsimmon._ (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:717:40)
      at Parsimmon._ (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:1017:23)
      at Parsimmon._ (/Users/jeromesimeon/git/markdown-transform/node_modules/parsimmon/src/parsimmon.js:1017:23)

Additional context
This will affect editors (e.g., VSCode extension or Template Studio) or users relying on the API and expecting consistent behaviour when rebuilding the parser for a template.

@jeromesimeon
Copy link
Member Author

Fixed in #278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant