Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 10 additions & 9 deletions docs/architecture/EAQL.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<QueryContent> ::= <DatabaseQuery>
| <TableQuery>

## Utilities
### Conditionals
<MultiIdentifier> ::= <Identifier> { <Comma> <Identifier> } [ <And> <Identifier> ]
<Condition> ::= <OrCondition>
<OrCondition> ::= <AndCondition> { <OrCondition> <AndCondition> }
<AndCondition> ::= <Expression> { <AndCondition> <Expression> }
<Expression> ::= <Identifier> <ComparisonOperator> <Literal>

## Database Queries
### Interaction
Expand All @@ -25,6 +32,7 @@
## Table Queries
<TableQuery> ::= <TableAccessorQuery>
| <TableDeleteQuery>
| <TableShowQuery>

### Accessing
<TableAccessorQuery> ::= <Get> ( <MultiIdentifier> | <WildcardKeyword> ) <From> <Identifier> [ <FilterClause> ] [ <PostProcessorClause> ]
Expand All @@ -34,15 +42,8 @@
<SortAction> ::= <Sort> <SortHelper> <SortType> [ <Order> ]

### Table Interaction
<TableDeleteQuery> ::= <DeleteKeyword> <Table> <Identifier>

## Utilities
### Conditionals
<MultiIdentifier> ::= <Identifier> { <Comma> <Identifier> } [ <And> <Identifier> ]
<Condition> ::= <OrCondition>
<OrCondition> ::= <AndCondition> { <OrCondition> <AndCondition> }
<AndCondition> ::= <Expression> { <AndCondition> <Expression> }
<Expression> ::= <Identifier> <ComparisonOperator> <Literal>
<TableDeleteQuery> ::= <DeleteKeyword> <Table> <Identifier> <Condition>
<TableShowQuery> ::= <ShowKeyword> <Table>

## Tokens
### Literal Tokens
Expand Down
8 changes: 6 additions & 2 deletions src/bin/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ fn main() {

match args[args.len() - 1].as_str() {
"transpile" => transpiler::repl_loop(),
"query_test" => validator::repl_loop(),
"validate" => validator::repl_loop(),
_ => utils::help::display_help(Some(
format!("Invalid Testing CLI Argument -> {}, see usage!", args[2]).as_str(),
format!(
"Invalid Testing CLI Argument -> {}, see usage!",
args[args.len() - 1]
)
.as_str(),
)),
}
}
105 changes: 52 additions & 53 deletions src/language/parser/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{

#[derive(Debug, PartialEq)]
pub struct ConditionNode {
_condition: ConditionChild,
_literal: String,
pub condition: ConditionChild,
pub literal: String,

_depth: u16,
}
Expand All @@ -25,26 +25,25 @@ pub enum ConditionChild {

#[derive(Debug, PartialEq)]
pub struct OperandNode {
_type: String,

_ls: ConditionChild,
_rs: ConditionChild,
pub op: String,
pub ls: ConditionChild,
pub rs: ConditionChild,

_depth: u16,
}

#[derive(Debug, PartialEq)]
pub struct ExpressionNode {
_identifier: Token,
_comparison_operator: Token,
_literal: Token,
pub identifier: Token,
pub comparison_operator: Token,
pub literal: Token,

_depth: u16,
}

#[derive(Debug, PartialEq)]
pub struct BoolNode {
_value: bool,
pub value: bool,

_depth: u16,
}
Expand All @@ -53,8 +52,8 @@ fn update_depths(node: &mut ConditionChild) -> () {
match node {
ConditionChild::Op(state) => {
state._depth += 1;
update_depths(&mut state._ls);
update_depths(&mut state._rs);
update_depths(&mut state.ls);
update_depths(&mut state.rs);
return;
}
ConditionChild::Bool(state) => state._depth += 1,
Expand All @@ -72,9 +71,9 @@ fn handle_open_paren(
closing_or: &mut bool,
) -> Result<ConditionChild, String> {
let mut ret: ConditionChild = ConditionChild::Op(Box::new(OperandNode {
_type: "OR".to_string(),
op: "OR".to_string(),
_depth: depth,
_ls: match recurse_down(
ls: match recurse_down(
tokens,
idx,
depth + 1,
Expand All @@ -87,7 +86,7 @@ fn handle_open_paren(
Ok(node) => node,
Err(msg) => return Err(msg),
},
_rs: match recurse_down(
rs: match recurse_down(
tokens,
idx,
depth + 1,
Expand All @@ -114,9 +113,9 @@ fn handle_open_paren(
}

return Ok(ConditionChild::Op(Box::new(OperandNode {
_type: "AND".to_string(),
_ls: ret,
_rs: match recurse_down(
op: "AND".to_string(),
ls: ret,
rs: match recurse_down(
tokens,
idx,
depth + 1,
Expand Down Expand Up @@ -144,9 +143,9 @@ fn handle_open_paren(
}

return Ok(ConditionChild::Op(Box::new(OperandNode {
_type: "OR".to_string(),
_ls: ret,
_rs: match recurse_down(
op: "OR".to_string(),
ls: ret,
rs: match recurse_down(
tokens,
idx,
depth + 1,
Expand Down Expand Up @@ -208,9 +207,9 @@ fn handle_and(
closing_or: &mut bool,
) -> Result<ConditionChild, String> {
Ok(ConditionChild::Op(Box::new(OperandNode {
_type: "AND".to_string(),
op: "AND".to_string(),
_depth: depth,
_ls: match recurse_down(
ls: match recurse_down(
tokens,
idx,
depth + 1,
Expand All @@ -223,7 +222,7 @@ fn handle_and(
Ok(node) => node,
Err(msg) => return Err(msg),
},
_rs: match recurse_down(
rs: match recurse_down(
tokens,
idx,
depth + 1,
Expand Down Expand Up @@ -269,23 +268,23 @@ fn handle_literal(
};

return Ok(ConditionChild::Op(Box::new(OperandNode {
_type: "AND".to_string(),
op: "AND".to_string(),
_depth: depth,
_ls: ls,
_rs: rs,
ls,
rs,
})));
}

fn handle_close(parent_node: &String, depth: u16) -> ConditionChild {
// AND default to true, OR defaults to false
if *parent_node == "AND" {
ConditionChild::Bool(Box::new(BoolNode {
_value: true,
value: true,
_depth: depth,
}))
} else {
ConditionChild::Bool(Box::new(BoolNode {
_value: false,
value: false,
_depth: depth,
}))
}
Expand Down Expand Up @@ -425,9 +424,9 @@ fn recurse_down(
*closing_or = false;

return Ok(ConditionChild::Op(Box::new(OperandNode {
_type: "OR".to_string(),
op: "OR".to_string(),
_depth: depth,
_ls: match recurse_down(
ls: match recurse_down(
tokens,
idx,
depth + 1,
Expand All @@ -440,7 +439,7 @@ fn recurse_down(
Ok(node) => node,
Err(msg) => return Err(msg),
},
_rs: match recurse_down(
rs: match recurse_down(
tokens,
idx,
depth + 1,
Expand Down Expand Up @@ -533,9 +532,9 @@ impl ConditionNode {
let start_idx: usize = *idx;

let ret: ConditionChild = ConditionChild::Op(Box::new(OperandNode {
_type: "OR".to_string(),
op: "OR".to_string(),
_depth: depth + 1,
_ls: match recurse_down(
ls: match recurse_down(
tokens,
idx,
depth + 2,
Expand All @@ -548,7 +547,7 @@ impl ConditionNode {
Ok(node) => node,
Err(msg) => return Err(msg),
},
_rs: match recurse_down(
rs: match recurse_down(
tokens,
idx,
depth + 2,
Expand All @@ -568,22 +567,22 @@ impl ConditionNode {
}

return Ok(ConditionNode {
_condition: ret,
condition: ret,
_depth: depth,
_literal: ConditionNode::reconstruct_literal(tokens, start_idx, *idx),
literal: ConditionNode::reconstruct_literal(tokens, start_idx, *idx),
});
}

/// Outputs current AST node transpiled with color
/// and it's raw query counterpart. Output are used by
/// the Transpiler REPL.
pub fn transpile_color(&self) -> String {
format!("{}", self._literal)
format!("{}", self.literal)
}

/// Outputs current AST node transpiled to raw SQL
pub fn transpile_raw(&self) -> String {
format!("{}", self._literal)
format!("{}", self.literal)
}
}

Expand Down Expand Up @@ -634,9 +633,9 @@ impl ExpressionNode {
}

return Ok(ExpressionNode {
_identifier: identifier,
_comparison_operator: comparison_operator,
_literal: literal,
identifier,
comparison_operator,
literal,

_depth: depth,
});
Expand All @@ -661,7 +660,7 @@ impl fmt::Display for ConditionNode {
"\n{}(Condition){}{}",
get_tab(self._depth),
get_tab(self._depth + 1),
self._condition
self.condition
)
}
}
Expand All @@ -672,16 +671,16 @@ impl fmt::Display for OperandNode {
f,
"\n{}(Operand::{}){}{}",
get_tab(self._depth),
self._type,
self._ls,
self._rs,
self.op,
self.ls,
self.rs,
)
}
}

impl fmt::Display for BoolNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\n{}(Bool::{})", get_tab(self._depth), self._value,)
write!(f, "\n{}(Bool::{})", get_tab(self._depth), self.value,)
}
}

Expand All @@ -695,11 +694,11 @@ impl fmt::Display for ExpressionNode {
{}value: {:?}",
get_tab(self._depth),
get_tab(self._depth + 1),
self._identifier.lexeme,
self.identifier.lexeme,
get_tab(self._depth + 1),
self._comparison_operator.token_type,
self.comparison_operator.token_type,
get_tab(self._depth + 1),
self._literal.literal
self.literal.literal
)
}
}
Expand All @@ -720,9 +719,9 @@ mod tests {
let mut idx: usize = 0;
let depth: u16 = 0;
let expected: ExpressionNode = ExpressionNode {
_identifier: Token::new(TokenType::Identifier, &"".to_string(), &"id".to_string()),
_comparison_operator: Token::new(TokenType::Equal, &"".to_string(), &"is".to_string()),
_literal: Token::new(TokenType::NumberLiteral, &"5".to_string(), &"5".to_string()),
identifier: Token::new(TokenType::Identifier, &"".to_string(), &"id".to_string()),
comparison_operator: Token::new(TokenType::Equal, &"".to_string(), &"is".to_string()),
literal: Token::new(TokenType::NumberLiteral, &"5".to_string(), &"5".to_string()),

_depth: 0,
};
Expand Down
Loading