prometheus/promql/parser
Harkishen Singh 44fcf876ca
Adds support for prettifying PromQL expression (#10544)
* Implement Pretty() function for AST nodes.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit adds .Pretty() for all nodes of PromQL AST.
Each .Pretty() prettifies the node it belongs to, and under
no circustance, the parent or child node is touch/prettified.

Read more in the "Approach" part in `prettier.go`

* Refactor functions between printer.go & prettier.go

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit removes redundancy between printer.go and prettier.go
by taking out the common code into separate private functions.

* Add more unit tests for Prettier.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* Add support for spliting function calls with 1 arg & unary expressions.

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit does 2 things:
1. It adds support to split function calls that have 1 arg and exceeds the max_characters_per_line
to multiple lines.
2. Splits Unary expressions that exceed the max_characters_per_line. This is done by formatting the child node
and then removing the prefix indent, which is already applied before the unary operator.
2022-07-07 18:13:36 +05:30
..
ast.go Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
functions.go Adds day_of_year function to PromQL 2022-05-20 14:08:34 +02:00
generated_parser.y Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
generated_parser.y.go Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
lex.go Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
lex_test.go Run gofumpt on all files (#10392) 2022-03-03 17:21:05 +01:00
parse.go refactor (promql): move from github.com/pkg/errors to 'errors' and 'fmt' (#10817) 2022-06-08 10:47:52 +02:00
parse_test.go refactor (promql): move from github.com/pkg/errors to 'errors' and 'fmt' (#10817) 2022-06-08 10:47:52 +02:00
prettier.go Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
prettier_rules.md Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
prettier_test.go Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
printer.go Adds support for prettifying PromQL expression (#10544) 2022-07-07 18:13:36 +05:30
printer_test.go Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00
value.go promql: use explicit type declare instead of string. (#7716) 2020-08-02 09:57:38 +01:00