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

Expose lexer item types #5358

Merged
merged 2 commits into from Mar 14, 2019

Conversation

Projects
None yet
3 participants
@juliusv
Copy link
Member

juliusv commented Mar 14, 2019

We have generally agreed to expose AST types / values that are necessary
to make sense of the AST outside of the promql package. Currently the
UnaryExpr, BinaryExpr, and AggregateExpr AST nodes store the lexer
item type to indicate the operator type, but since the individual item
types aren't exposed, an external user of the package cannot determine
the operator type. So this PR exposes them.

Although not all item types are required to make sense of the AST (some
are really only used in the lexer), I decided to expose them all here to
be somewhat more consistent. Another option would be to not use lexer
item types at all in AST nodes.

The concrete motivation is my work on the PromQL->Flux transpiler, but
this ought to be useful for other cases as well.

Signed-off-by: Julius Volz julius.volz@gmail.com

Expose lexer item types
We have generally agreed to expose AST types / values that are necessary
to make sense of the AST outside of the promql package. Currently the
`UnaryExpr`, `BinaryExpr`, and `AggregateExpr` AST nodes store the lexer
item type to indicate the operator type, but since the individual item
types aren't exposed, an external user of the package cannot determine
the operator type. So this PR exposes them.

Although not all item types are required to make sense of the AST (some
are really only used in the lexer), I decided to expose them all here to
be somewhat more consistent. Another option would be to not use lexer
item types at all in AST nodes.

The concrete motivation is my work on the PromQL->Flux transpiler, but
this ought to be useful for other cases as well.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Mar 14, 2019

👍

You've test failures.

Fix item type names in tests
Signed-off-by: Julius Volz <julius.volz@gmail.com>
@juliusv

This comment has been minimized.

Copy link
Member Author

juliusv commented Mar 14, 2019

Doh. Fixed.

@juliusv juliusv merged commit 8155cc4 into master Mar 14, 2019

3 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: test Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@juliusv juliusv deleted the expose-ast-item-types branch Mar 14, 2019

@mxinden

This comment has been minimized.

Copy link
Member

mxinden commented Mar 15, 2019

Thanks @juliusv. I am looking into a language server implementation for PromQL right now. This should help.

@juliusv

This comment has been minimized.

Copy link
Member Author

juliusv commented Mar 15, 2019

@mxinden Oohhh, looking forward to that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.