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

Return indices into the input collection instead of slices #68

Closed
robrix opened this issue Feb 21, 2015 · 0 comments · Fixed by #70
Closed

Return indices into the input collection instead of slices #68

robrix opened this issue Feb 21, 2015 · 0 comments · Fixed by #70
Milestone

Comments

@robrix
Copy link
Owner

robrix commented Feb 21, 2015

Combinators are all of type Input -> (Output, Input)?. This is sufficient to reject parses, parse forwards, and even to implement zero-width negative lookahead or more esoteric things (e.g. it’s trivial, although of dubious value, to implement parsers which swap out the input string for parsers following them), but it doesn’t allow lookbehind.

We should instead return an index into the input collection; then we can loosen #67’s recursive Sliceable constraint to arbitrary CollectionTypes. That would give us:

struct Parser<Input: CollectionType, Tree> {
    typealias Function = (Input, Input.Index) -> (Tree, Input.Index)
}

If we have a use case for swapping the parsed collection, we could add the collection to the return value as well:

struct Parser<Input: CollectionType, Tree> {
    typealias Function = (Input, Input.Index) -> (Tree, Input, Input.Index)
}

(We could also parameterize by a second collection type, such that each combinator could initiate parsing into not simply a different collection but a different kind of collection, but again, this is of dubious value.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant