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

NotAllInputParsedException : Redundant input, expecting EOF but found #1079

Closed
ixops opened this issue Jan 10, 2020 · 2 comments
Closed

NotAllInputParsedException : Redundant input, expecting EOF but found #1079

ixops opened this issue Jan 10, 2020 · 2 comments

Comments

@ixops
Copy link

ixops commented Jan 10, 2020

I'm trying to create a wildcard token which captures everything that isn't part of my grammar. To illustrate, lets say I want to match Foo, Bar, and Baz specifically, and any text that isn't one of those, I want it to be captured with a wildcard token.

So given "Foo Bar Baz, This is a cow. ", the Lexer would return [] where wildcard would hold "This is a cow."

So given "Bar Baz Foo, This is a fish. ", the Lexer would return [] where wildcard would hold "This is a fish."

I've got a set of tokens that seem to match everything correctly, including (I think) the wildcard. They look like this...

matchFoo = createToken({ name: 'matchWildcard', pattern: 'Foo'});
matchBar = createToken({ name: 'matchBar', pattern: 'Bar' });
matchBaz = createToken({ name: 'matchBaz', pattern: 'Baz' });
matchWildcard = createToken({ name: 'matchWildcard', pattern: /[a-zA-Z',. ]+/ });

The issue I'm having is with the parsing rule. I'm trying a rule that looks like this...

$.RULE('notation', () => {
    $.AT_LEAST_ONE(() => {
        $.OR([
          { ALT: () => $.CONSUME(matchFoo) },
          { ALT: () => $.CONSUME(matchBar) }, 
          { ALT: () => $.CONSUME(matchBaz) },
          { ALT: () => $.CONSUME(matchWildcard) }
        ]);
    })
});

I "think" this should require at least one token but also consume all tokens, regardless of the order in which they appear. The problem is I'm getting the following error...

 Error {
   name: 'NotAllInputParsedException',
   message: 'Redundant input, expecting EOF but found: , This is a fish.',
   token: [Object],
   resyncedTokens: [],
   context: [Object] } 

I searched the docs, chat channel, and issue history, but haven't been able to unpack why I'm getting the error or how to fix it. I'm sure I'm failing to grasp something here.

@bd82
Copy link
Member

bd82 commented Jan 10, 2020

Hello @ixops

A possibly related topic may be fuzzy matching:

Anyhow I think your code snippet should be working as you expect it to.
I suggest you inspect the tokenVector produced by the Lexer before it is passed to the parser and ensure it contains exactly four tokens as you expect.

You can also put a breakpoints just inside and after:

  • $.AT_LEAST_ONE

and inspect $.LA(1)/this.LA(1) every iteration that enters and after exiting from the loop, perhaps this will provide some hints to the problem...

If these options fail to produce clues, please create a simple gist/repo I can checkout and reproduce the problem with and I will debug it myself.

Please note that Chevrotain performs Lexical Matching in Before Parsing in a separate phase. Which make your Token Names (match prefix) a bit misleading as no regExp matching is done inside the parser, that already happened during lexing...

Cheers.
😄

@bd82
Copy link
Member

bd82 commented Feb 14, 2020

please re-open this if you can provide an easily re-producible example.

@bd82 bd82 closed this as completed Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants