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

anyOf(Characters.ALL) matches at end of input #30

Open
akirschbaum opened this issue May 30, 2015 · 0 comments
Open

anyOf(Characters.ALL) matches at end of input #30

akirschbaum opened this issue May 30, 2015 · 0 comments

Comments

@akirschbaum
Copy link

anyOf(Characters.ALL) does match even if no more input is available. It should not match because no input character is available and thus no input character could have been consumed.

The behavior of ANY is correct: it does not match if no more input is available.

$ gradle
:compileJava
:processResources UP-TO-DATE
:classes
:run
Parser1: false
Parser2: true

BUILD SUCCESSFUL

Total time: 6.269 secs
$ cat build.gradle
defaultTasks 'run'

apply plugin: 'application'
apply plugin: 'java'

sourceCompatibility = 1.8
mainClassName = 'app.Main'

dependencies {
    compile 'com.github.fge:grappa:2.0.0'
}

repositories {
    mavenCentral()
}
$ cat src/main/java/app/Main.java
package app;

import com.github.fge.grappa.Grappa;
import com.github.fge.grappa.buffers.CharSequenceInputBuffer;
import com.github.fge.grappa.parsers.BaseParser;
import com.github.fge.grappa.rules.Rule;
import com.github.fge.grappa.run.ListeningParseRunner;
import com.github.fge.grappa.support.Characters;

public class Main {

    public static void main(final String[] args) {
        final Parser parser = Grappa.createParser(Parser.class);
        final CharSequenceInputBuffer buffer = new CharSequenceInputBuffer("");
        System.out.println("Parser1: "+new ListeningParseRunner<>(parser.rule1()).run(buffer).isSuccess());
        System.out.println("Parser2: "+new ListeningParseRunner<>(parser.rule2()).run(buffer).isSuccess());
    }

    public static class Parser extends BaseParser<Object> {

        public Rule rule1() {
            return ANY;
        }

        public Rule rule2() {
            return anyOf(Characters.ALL);
        }

    }

}
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

1 participant