Skip to content

Unexpected end of input when using uppercase letter #2

@mbatchkarov

Description

@mbatchkarov

Hi,

I noticed a weird corner case when using uppercase letters in a regex. The following example parses fine:

final String grammar =
        "/nlp/\n" +
                "sent <- goo* name goo*\n" +
                "name <- 'Miro' \n" +
                "goo <- [0-9] / [a-z]/ ' '\n"; // adding  "/ [A-Z]" here breaks it

String txt = "hello Miro how are you";
try (GramExp peg = new GramExp(grammar)) {
    System.out.println(peg.parse(txt));
}

whereas the next two examples fail. I am only adding support for uppercase letters:

final String grammar =
        "/nlp/\n" +
                "sent <- goo* name goo*\n" +
                "name <- 'Miro' \n" +
                "goo <- [0-9] / [A-Z]/ ' '\n"; // adding  "/ [A-Z]" here breaks it

String txt = "HELLO MIRO HOW ARE YOU";
try (GramExp peg = new GramExp(grammar)) {
    System.out.println(peg.parse(txt));
}

and

final String grammar =
        "/nlp/\n" +
                "sent <- goo* name goo*\n" +
                "name <- 'Miro' \n" +
                "goo <- [0-9] / [a-zA-Z]/ ' '\n"; // adding  "/ [A-Z]" here breaks it

String txt = "hello Miro How are you";
try (GramExp peg = new GramExp(grammar)) {
    System.out.println(peg.parse(txt));
}

The error is:
Exception in thread "main" uk.ac.susx.tag.gramexp.GrammarException: Unexpected end of input, expected goo or name (line 1, pos 23)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions