Skip to content

Commit fa5ecf0

Browse files
committed
fix group field parsing as a part of group by
1 parent ef31f43 commit fa5ecf0

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/lexer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub enum Lexem {
2323
And,
2424
Or,
2525
Not,
26-
Group,
2726
Order,
2827
By,
2928
DescendingOrder,
@@ -212,7 +211,6 @@ impl Lexer {
212211
"or" => Some(Lexem::Or),
213212
"and" => Some(Lexem::And),
214213
"not" if self.after_where => Some(Lexem::Not),
215-
"group" => Some(Lexem::Group),
216214
"order" => Some(Lexem::Order),
217215
"by" => Some(Lexem::By),
218216
"asc" => self.next_lexem(),
@@ -1072,7 +1070,7 @@ mod tests {
10721070
lexer.next_lexem(),
10731071
Some(Lexem::RawString(String::from("/test")))
10741072
);
1075-
assert_eq!(lexer.next_lexem(), Some(Lexem::Group));
1073+
assert_eq!(lexer.next_lexem(), Some(Lexem::RawString("group".to_owned())));
10761074
assert_eq!(lexer.next_lexem(), Some(Lexem::By));
10771075
assert_eq!(
10781076
lexer.next_lexem(),

src/parser.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ impl Parser {
125125
fields.push(Expr::field(Field::Modified));
126126
fields.push(Expr::field(Field::Path));
127127
} else {
128+
if s.to_lowercase() == "group" {
129+
if let Some(Lexem::By) = self.next_lexem() {
130+
self.drop_lexem();
131+
self.drop_lexem();
132+
break;
133+
} else {
134+
self.drop_lexem();
135+
}
136+
}
137+
128138
self.drop_lexem();
129139

130140
if Self::is_root_option_keyword(s) {
@@ -204,7 +214,10 @@ impl Parser {
204214
self.drop_lexem();
205215
match self.parse_root_options() {
206216
Some(options) => root_options = options,
207-
None => break
217+
None => {
218+
roots.push(Root::new(path, RootOptions::new()));
219+
break
220+
}
208221
}
209222
}
210223
_ => {}
@@ -779,25 +792,29 @@ impl Parser {
779792
fn parse_group_by(&mut self) -> Result<Vec<Expr>, String> {
780793
let mut group_by_fields: Vec<Expr> = vec![];
781794

782-
if let Some(Lexem::Group) = self.next_lexem() {
783-
if let Some(Lexem::By) = self.next_lexem() {
784-
loop {
785-
match self.next_lexem() {
786-
Some(Lexem::Comma) => {}
787-
Some(Lexem::RawString(_)) => {
788-
self.drop_lexem();
789-
let group_field = self.parse_expr().unwrap().unwrap();
790-
group_by_fields.push(group_field);
791-
}
792-
_ => {
793-
self.drop_lexem();
794-
break;
795+
if let Some(Lexem::RawString(s)) = self.next_lexem() {
796+
if s.to_lowercase() == "group" {
797+
if let Some(Lexem::By) = self.next_lexem() {
798+
loop {
799+
match self.next_lexem() {
800+
Some(Lexem::Comma) => {}
801+
Some(Lexem::RawString(_)) => {
802+
self.drop_lexem();
803+
let group_field = self.parse_expr().unwrap().unwrap();
804+
group_by_fields.push(group_field);
805+
}
806+
_ => {
807+
self.drop_lexem();
808+
break;
809+
}
795810
}
796811
}
812+
} else {
813+
self.drop_lexem();
797814
}
798815
} else {
799816
self.drop_lexem();
800-
}
817+
}
801818
} else {
802819
self.drop_lexem();
803820
}

0 commit comments

Comments
 (0)