grappa icon indicating copy to clipboard operation
grappa copied to clipboard

Label for rule is not applied by method, but works with annotation

Open ghost opened this issue 11 years ago • 0 comments

When attaching a label to a Rule via method .label("some label") it is not correctly applied to the rule. Attaching a label via annotation @Label works fine.

Example:

import org.parboiled.Parboiled;
import org.parboiled.Rule;
import org.parboiled.annotations.Label;
import org.parboiled.parserunners.TracingParseRunner;
import org.parboiled.support.ParsingResult;

import com.github.parboiled1.grappa.parsers.EventBusParser;

public class LabelTest {

    public static void main(String[] args) {
        LabelParser parser = Parboiled.createParser(LabelParser.class);
        for (Rule r : new Rule[] { parser.rule1(), parser.rule2() }) {
            TracingParseRunner<String> runner = new TracingParseRunner<>(r);
            ParsingResult<String> result = runner.run(new StringBuffer("a"));
        }
    }

    public static class LabelParser extends EventBusParser<String> {

        @Label("Label-1")
        Rule rule1() {
            return optional("a");
        }

        Rule rule2() {
            return optional("a").label("Label-2");
        }

    }

}

Output:

Starting new parsing run
Label-1/'a', matched, cursor at 1:2 after "a"
Label-1, matched, cursor at 1:2 after "a"
Starting new parsing run
rule2/'a', matched, cursor at 1:2 after "a"
rule2, matched, cursor at 1:2 after "a"

The label "Label-1" of the first rule is applied correctly, the second label "Label-2" is not applied. The second rule is still labeled as "rule2" in the output. This also happens in the tracer / debugger, so it is not a problem during output, but when attaching the label.

ghost avatar Feb 02 '15 13:02 ghost