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

Starting work on negation, wip #106

Merged
merged 1 commit into from Sep 7, 2020
Merged

Conversation

ceymard
Copy link
Contributor

@ceymard ceymard commented Sep 5, 2020

Here is a naive interpretation on how the negation could function.

If you want to do it entirely yourself, go ahead, but I'm willing to see this through as I really would like to see it come to fruition and this helps me hone my go funk.

I'm looking for some feedback on that preliminary implementation.

Am I missing something glaring ? Is the clone stuff potentially a performance killer ? Should Parse() be a little more involved ?

@ceymard
Copy link
Contributor Author

ceymard commented Sep 5, 2020

I could change all that to have !( ';' | ',' | SomeToken) by parsing it by hand (not going for parseDisjunction) and having a Parse() that actually peeks and verifies the list passes the check. That would ensure that we forbid anything like !( @'what' ) which would make no sense since for binding we'd rather have @!'lit' or @!(';', ',')

@alecthomas
Copy link
Owner

alecthomas commented Sep 5, 2020

Don't worry about the speed of clone, despite what I wrote before :)... I'm going to do an optimisation pass once I'm happy with everything else.

I could change all that to have !( ';' | ',' | SomeToken) by parsing it by hand (not going for parseDisjunction) and having a Parse() that actually peeks and verifies the list passes the check.

It would be simpler to just call parseDisjunction() then walk it to type check it. But I think just supporting ![@]<literal> or ![@]<reference> to start with is a good approach, then we could expand it later if desired.

Copy link
Owner

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start!

You'll also need to update the visitors.

grammar.go Outdated Show resolved Hide resolved
nodes.go Outdated Show resolved Hide resolved
@alecthomas
Copy link
Owner

BTW, if you want to join my channel in the Gophers Slack, there's a little group of us working on Participle :)

@alecthomas
Copy link
Owner

Thanks for this by the way, looking good!

@ceymard
Copy link
Contributor Author

ceymard commented Sep 6, 2020

Alright.

So I added some tests, which show so far that the negation has the potential to be pretty flexible.

It seems just parsing a term (with groups, sequences and whatnot) without restrictions has some satisfying results, even when I want to negate sequences (which is probably useful). Are there potential restrictions to address ?

However, I'm ignoring lookahead by not calling Stop() in negation.Parse. I did that because of course, when negating a sequence, I need the lookahead to be at least as big as the potential sequence, but it works if we just ignore that (so that Stop won't Accept my arm if partially matched, thus failing to parse afterwards). Am I missing something ? Is the lookahead size important to prevent the parser from going haywire or something ?

Also, I'm a bit puzzled by the depth in the stringer(). What is its objective ?

@ceymard
Copy link
Contributor Author

ceymard commented Sep 6, 2020

I reverted my tentative changes in stringer(), but the thing is if I define !('tok' 'tok2'), then stringer just won't display 'tok2' since the sequence stops at depth 0 which is attained immediately (so right after the first item).

A '...' would be nice, or even better have everything on display. I'm just not sure how depth is supposed to work.

@ceymard
Copy link
Contributor Author

ceymard commented Sep 6, 2020

BTW, if you want to join my channel in the Gophers Slack, there's a little group of us working on Participle :)

How do I join ? No matter how I try to login, I just can't enter. :(

@alecthomas
Copy link
Owner

BTW, if you want to join my channel in the Gophers Slack, there's a little group of us working on Participle :)

How do I join ? No matter how I try to login, I just can't enter. :(

Try this link I think? https://invite.slack.golangbridge.org/

I'm in Australia, so I'll be back online in about 9-10 hours.

@alecthomas
Copy link
Owner

It seems just parsing a term (with groups, sequences and whatnot) without restrictions has some satisfying results, even when I want to negate sequences (which is probably useful). Are there potential restrictions to address ?

No I think the approach is sound.

However, I'm ignoring lookahead by not calling Stop() in negation.Parse. I did that because of course, when negating a sequence, I need the lookahead to be at least as big as the potential sequence, but it works if we just ignore that (so that Stop won't Accept my arm if partially matched, thus failing to parse afterwards).

Sounds reasonable.

Also, I'm a bit puzzled by the depth in the stringer(). What is its objective ?

It's not the recursion depth. The idea is that it displays to the user the next set of options available to them, which is why in the case of "foo" "bar" only "foo" would be displayed.

Copy link
Owner

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pretty close. I'm happy to merge once my comments are addressed. Thanks!

grammar.go Outdated Show resolved Hide resolved
nodes.go Outdated Show resolved Hide resolved
nodes.go Outdated Show resolved Hide resolved
parser_test.go Outdated Show resolved Hide resolved
parser_test.go Show resolved Hide resolved
stringer.go Outdated Show resolved Hide resolved
stringer.go Outdated Show resolved Hide resolved
stringer.go Outdated Show resolved Hide resolved
@@ -282,6 +284,18 @@ func (g *generatorContext) parseGroup(slexer *structLexer) (node, error) {
return &group{expr: disj}, nil
}

// A token negation
//
// Accepts both the form !"some-literal" and !SomeNamedToken
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment accurate now?

@alecthomas
Copy link
Owner

Awesome, thanks!

If you want to git rebase -i master && git push -f, we can use this PR. Up to you.

@ceymard
Copy link
Contributor Author

ceymard commented Sep 7, 2020

Done !

@alecthomas alecthomas merged commit 0c84294 into alecthomas:master Sep 7, 2020
@alecthomas
Copy link
Owner

Thanks again :)

@ceymard ceymard deleted the anything-but branch September 7, 2020 12:43
@ceymard
Copy link
Contributor Author

ceymard commented Sep 7, 2020

fixes #104 for reference.

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

Successfully merging this pull request may close these issues.

None yet

2 participants