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

Odd behaviors with lexemes at end of greedy grammars #17

Closed
hudson-ai opened this issue Jun 28, 2024 · 2 comments
Closed

Odd behaviors with lexemes at end of greedy grammars #17

hudson-ai opened this issue Jun 28, 2024 · 2 comments
Assignees

Comments

@hudson-ai
Copy link
Owner

g = greedy_grammar(body=lexeme("\d+"))

(
    g.match("123") is not None,
    g.match("123 ") is not None,
    g.match("123  ") is not None,
    (g+"x").match("123x") is not None
)
>> (False, False, False, True)

Only matches when not at end of grammar (I suppose an EOS would work?)

g = greedy_grammar(body=lexeme("\d+"), skip_regex='\s')

(
    g.match("123") is not None,
    g.match("123 ") is not None,
    g.match("123  ") is not None,
    (g+"x").match("123x") is not None
)
>> (False, True, False, True)

Requires single trailing whitespace to match

g = greedy_grammar(body=lexeme("\d+"), skip_regex='\s*')

(
    g.match("123") is not None,
    g.match("123 ") is not None,
    g.match("123  ") is not None,
    (g+"x").match("123x") is not None
)
>> (False, False, True, True)

Requires two trailing whitespace to match

@mmoskal
Copy link
Collaborator

mmoskal commented Jul 1, 2024

@hudson-ai there is still an issue with the captures not being generated - I guess we can have either the parser generate partial captures (here "1", "12", "123") or you feeding EOS before you get the captures

@hudson-ai
Copy link
Owner Author

Thanks! I think that the current capture approach is fine... May need to expose something for partial captures in the future (not sure if there is actually a valid use-case for this..?), but for now I can try and manually inject an EOS

mmoskal added a commit to mmoskal/llguidance that referenced this issue Jul 6, 2024
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

2 participants