Skip to content
Merged
Changes from all commits
Commits
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
41 changes: 38 additions & 3 deletions src/interpreter/ast/helpers/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::interpreter::{
ast::{
ExistenceCheck, LogicalOperator, MathOperator, Operator, OrderByDirection,
SelectStatementColumn, SelectStatementTable, SelectableStack, SelectableStackElement,
helpers::token::token_to_value, parser::Parser,
ExistenceCheck, FunctionName, FunctionSignature, LogicalOperator, MathOperator, Operator,
OrderByDirection, SelectStatementColumn, SelectStatementTable, SelectableStack,
SelectableStackElement, helpers::token::token_to_value, parser::Parser,
},
tokenizer::token::TokenTypes,
};
Expand Down Expand Up @@ -116,6 +116,12 @@ pub fn get_selectables(
current_name += token.value;
}
continue;
} else if token.token_type == TokenTypes::As {
parser.advance()?;
if parser.current_token()?.token_type == TokenTypes::Identifier {
current_alias = Some(parser.current_token()?.value.to_string());
}
continue;
} else if token.token_type == TokenTypes::LeftParen {
operators.push(ExtendedSelectableStackElement::LeftParen);
current_name += token.value;
Expand Down Expand Up @@ -252,6 +258,35 @@ pub fn get_selectables(
current_name = column.column_name.clone();
SelectableStackElement::Column(column)
}
TokenTypes::Count => {
// TODO: GENERALIZE THIS FOR ALL FUNCTIONS
let mut function_name = token.value.to_string();
let has_parentheses = if let Ok(peek_token) = parser.peek_token() {
peek_token.token_type == TokenTypes::LeftParen
} else {
false
};

if has_parentheses {
parser.advance()?;
function_name += parser.current_token()?.value;

parser.advance()?;
while parser.current_token()?.token_type != TokenTypes::RightParen {
function_name += parser.current_token()?.value;
parser.advance()?;
}

function_name += parser.current_token()?.value;
}

current_name = function_name;
SelectableStackElement::Function(FunctionSignature {
name: FunctionName::CountFunction,
input_count: 0,
has_parentheses,
})
}
_ => return Err(parser.format_error()), // TODO: better error handling
};
output.push(element);
Expand Down
Loading