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

lexer ambiguity problem #114

Open
mmoskal opened this issue Jan 30, 2025 · 0 comments
Open

lexer ambiguity problem #114

mmoskal opened this issue Jan 30, 2025 · 0 comments
Assignees

Comments

@mmoskal
Copy link
Collaborator

mmoskal commented Jan 30, 2025

The lexer is required to produce a single lexeme, and so the following testcase fails for 'foo'bb (since the lexer fixates on 'foo' despite STRING being viable as well).

#[test]
fn test_lexer_amb() {
    lark_str_test_many(
        r#"start: "'foo'" /a+/ | STRING /b+/
           STRING: /'[^']*'/
        "#,
        &["'foo'a", "'foo'aaa", "'bar'b", "'bar'bbb", "'foo'bb"],
        &["'bar'a", "'bar'c"],
    );
}

This causes the following JSON test to also fail; it passes with the required line (add to test_raw_parser.rs)

#[test]
fn test_ff_json4() {
    let schema = json!({
        "anyOf":[{
            "type": "object",
            "properties": {
                "foo": { "type": "number" }
            },
            // "required": ["foo"], -> with required it passes
            "additionalProperties": { "type": "string" },
        }, {
            "type": "object",
            "properties": {
                "bar": { "type": "number" }
            },
            "additionalProperties": false,
        }]
    });

    json_fwd_test(schema.clone(), json!({ "foo": 123, "baz": "hello" }));
    json_fwd_test(schema.clone(), json!({ "bar": 123 }));
}

So this is problem with the grammar engine but if affects JSON.

fyi @hudson-ai

@mmoskal mmoskal self-assigned this Jan 30, 2025
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