Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Add Drop operation to Fields #369

Merged
merged 2 commits into from
Feb 21, 2019
Merged

Add Drop operation to Fields #369

merged 2 commits into from
Feb 21, 2019

Conversation

dennwc
Copy link
Member

@dennwc dennwc commented Feb 21, 2019

As requested in bblfsh/cpp-driver#26, add an option to drop a field. It will work the same way as Optional: "x", Op: Any(), except that it won't create a variable for Optional.

Signed-off-by: Denys Smirnov denys@sourced.tech

uast/transformer/ops.go Outdated Show resolved Hide resolved
uast/transformer/ops.go Outdated Show resolved Hide resolved
@dennwc
Copy link
Member Author

dennwc commented Feb 21, 2019

OK, I see that the comment is confusing. Any ideas on how to make it more clear?

uast/transformer/ops.go Outdated Show resolved Hide resolved
Signed-off-by: Denys Smirnov <denys@sourced.tech>
@dennwc
Copy link
Member Author

dennwc commented Feb 21, 2019

Ready for another review round.

// To handle nil fields, see Opt operation.
Optional string
Op Op // operation used to check/construct the field value
// Drop the field if it exists. Op should be set and it will be called to check the
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add:

  • Optional is implied (even if its implicitly told by "if it exists").

// To handle nil fields, see Opt operation.
Optional string
Op Op // operation used to check/construct the field value
// Drop the field if it exists. Op should be set and it will be called to check the
// value before dropping it. If the check fails, the whole transform will be canceled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "the whole transform will be cancelled like if you used Any()" which is also didactic.

// Drop the field if it exists. Op should be set and it will be called to check the
// value before dropping it. If the check fails, the whole transform will be canceled.
//
// Please note that you should avoid dropping fields with Any unless there is no
Copy link
Contributor

Choose a reason for hiding this comment

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

"you should avoid dropping fields with Any (explicit or implicit) unless there is no..."

Copy link
Member Author

Choose a reason for hiding this comment

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

See the comment thread above: #369 (comment)

I remove the implicit Any.

@juanjux
Copy link
Contributor

juanjux commented Feb 21, 2019

More nitpicking trying to look at it from the perspective or a new, clueless and confused DSL user (because I've been there haha).

Signed-off-by: Denys Smirnov <denys@sourced.tech>
@juanjux
Copy link
Contributor

juanjux commented Feb 21, 2019

Perfection has been reached 👌

@dennwc dennwc merged commit 5a1a268 into bblfsh:master Feb 21, 2019
@dennwc dennwc deleted the fields_drop branch February 21, 2019 18:53
@bzz
Copy link
Contributor

bzz commented Feb 27, 2019

Regarding the discussion in #369 (comment) - would you be so kind to help me understand the expected behavior of - {Name: "specifiers", Drop: true, Op: Arr()}, is that suppose to match&drop only empty array?

Because from what I can tell - right now this results in check: unused field(s) on node ImportDeclaration: specifiers 😕

@juanjux
Copy link
Contributor

juanjux commented Feb 27, 2019

Could it be the case that there is a specifiers field that is not an empty array (so the Drop wouldn't match) and it's not being handled?

@bzz
Copy link
Contributor

bzz commented Feb 27, 2019

It could, but I wanted to verify the expectations here: {Name: "specifiers", Drop: true, Op: Arr()} is supposed to match&drop specifiers only in case it's an empty array - would that be correct?

@juanjux
Copy link
Contributor

juanjux commented Feb 28, 2019

I think it is but less wait for the DSL guru @dennwc to confirm this.

@dennwc
Copy link
Member Author

dennwc commented Feb 28, 2019

Yes, it's correct. If it's not an empty array the whole operation will be reverted.

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

Successfully merging this pull request may close these issues.

4 participants