grappa icon indicating copy to clipboard operation
grappa copied to clipboard

anyOf(Characters.ALL) matches at end of input

Open akirschbaum opened this issue 10 years ago • 0 comments

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);
        }

    }

}

akirschbaum avatar May 30 '15 16:05 akirschbaum