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

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

Open
ghost opened this issue Feb 2, 2015 · 0 comments
Open

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

ghost opened this issue Feb 2, 2015 · 0 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Feb 2, 2015

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.

@fge fge added the bug label Feb 2, 2015
@fge fge self-assigned this Feb 2, 2015
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