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

feat: PromQL Rust Lexer #12

Merged
merged 23 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5140940
feat(lex): skeleton
yuanbohan Dec 14, 2022
5b1603a
refactor(lexer): use enum instead of trait object
yuanbohan Dec 14, 2022
645456d
lex: keyword_or_identifier
yuanbohan Dec 14, 2022
7d5c90f
fix(ctx): pos, start, peek logic
yuanbohan Dec 15, 2022
88d5496
refactor: fn -> Fn
yuanbohan Dec 15, 2022
baa0544
refactor: move shift into Lexer
yuanbohan Dec 15, 2022
ec160b2
lexer: accept_string
yuanbohan Dec 15, 2022
45d25a7
lexer: duration, lable_selector
yuanbohan Dec 15, 2022
eea02f0
example: make example work with lexer
yuanbohan Dec 15, 2022
fff544b
test: common test done
yuanbohan Dec 15, 2022
6f10b40
test(lex): more test cases
yuanbohan Dec 15, 2022
27d72ed
test(lex): unbalanced parentheses
yuanbohan Dec 16, 2022
4d414ba
test(lexer): subquery
yuanbohan Dec 16, 2022
aa48e86
test(lexer): more cases
yuanbohan Dec 16, 2022
a40422d
test: token and production fn
yuanbohan Dec 16, 2022
07348ac
misc(lex): modification based on review comments
yuanbohan Dec 19, 2022
0a6cbe0
misc(lex): revision based on review comment
yuanbohan Dec 19, 2022
29073c0
misc(lex): use const instead of lazy_static
yuanbohan Dec 19, 2022
4dd987c
perf(token): use hashmap instead of match on &str
yuanbohan Dec 19, 2022
9d50c4d
fix(lex): potential panic try to dec depth when depth is less than 1
yuanbohan Dec 20, 2022
92f8c7a
misc(lex): use usize instead of u8 for paren_depth
yuanbohan Dec 20, 2022
1113030
feat(lex): to check if backup is at the beginning of input
yuanbohan Dec 20, 2022
3ee5940
comment(lex): typo
yuanbohan Dec 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
.vscode

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
9 changes: 5 additions & 4 deletions examples/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use promql_parser::parser;

fn main() {
let promql = "node_cpu_seconds_total{cpu=0,mode=idle}";
let promql = r#"prometheus_http_requests_total{code="200", job="prometheus"}"#;

let ast = parser::parse(promql).unwrap();

println!("AST: {:?}", ast);
match parser::parse(promql) {
Ok(ast) => println!("AST: {:?}", ast),
Err(info) => println!("Err: {:?}", info),
}
}
3 changes: 1 addition & 2 deletions src/label/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::parser::Token;
use crate::parser::{T_EQL, T_EQL_REGEX, T_NEQ, T_NEQ_REGEX};
use crate::parser::token::{Token, T_EQL, T_EQL_REGEX, T_NEQ, T_NEQ_REGEX};
use regex::Regex;

#[derive(Debug)]
Expand Down
Loading