Skip to content

Commit

Permalink
fix: Removed NaN and Null
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Dec 26, 2024
1 parent d149603 commit bd4d5ec
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 144 deletions.
6 changes: 2 additions & 4 deletions lykiadb-lang/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ impl Display for Expr {
Literal::Str(s) => write!(f, "Str(\"{}\")", s),
Literal::Num(n) => write!(f, "Num({:?})", n),
Literal::Bool(b) => write!(f, "{}", b),
Literal::Undefined => write!(f, "undefined"),
Literal::Object(o) => write!(f, "{:?}", o),
Literal::Object(o) => write!(f, "Object({:?})", o),

Check warning on line 332 in lykiadb-lang/src/ast/expr.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-lang/src/ast/expr.rs#L332

Added line #L332 was not covered by tests
Literal::Array(a) => write!(
f,
"Array({})",
Expand All @@ -339,8 +338,7 @@ impl Display for Expr {
.collect::<Vec<_>>()
.join(", ")
),
Literal::NaN => write!(f, "NaN"),
Literal::Null => write!(f, "null"),
Literal::Undefined => write!(f, "Undefined"),

Check warning on line 341 in lykiadb-lang/src/ast/expr.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-lang/src/ast/expr.rs#L341

Added line #L341 was not covered by tests
},
Expr::Function {
name, parameters, ..
Expand Down
6 changes: 1 addition & 5 deletions lykiadb-lang/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ pub enum Literal {
Str(Arc<String>),
Num(f64),
Bool(bool),
Undefined,
Object(FxHashMap<String, Box<Expr>>),
Array(Vec<Expr>),
NaN,
Null,
Undefined,
}

impl Literal {
Expand All @@ -78,8 +76,6 @@ impl Hash for Literal {
Literal::Array(a) => a.hash(state),
//
Literal::Undefined => "undefined".hash(state),
Literal::NaN => "NaN".hash(state),
Literal::Null => "null".hash(state),
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions lykiadb-lang/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,6 @@ impl<'a> Parser<'a> {
span: tok.span,
id: self.get_expr_id(),
})),
TokenType::Null => Ok(Box::new(Expr::Literal {
value: Literal::Null,
raw: "null".to_string(),
span: tok.span,
id: self.get_expr_id(),
})),
TokenType::Undefined => Ok(Box::new(Expr::Literal {
value: Literal::Undefined,
raw: "undefined".to_string(),
Expand Down
3 changes: 1 addition & 2 deletions lykiadb-lang/src/tokenizer/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ mod test {
#[test]
fn test_sql_keywords() {
assert_tokens(
"Begin Transaction Rollback Commit Where Having Asc Desc Order By Explain Is Not Null Offset Like Limit And Or Join Inner Right Left On Create Insert Update Delete Drop Into Values Index Collection Select From As Cross Default Group Key Of Only Primary References Set System Unique Read Write", vec![
"Begin Transaction Rollback Commit Where Having Asc Desc Order By Explain Is Not Offset Like Limit And Or Join Inner Right Left On Create Insert Update Delete Drop Into Values Index Collection Select From As Cross Default Group Key Of Only Primary References Set System Unique Read Write", vec![
Token {tok_type: skw!(SqlKeyword::Begin), literal: None, lexeme: lexm!("Begin"), span: Span { line: 0, start: 0, line_end: 0, end: 5 }},
Token {tok_type: skw!(SqlKeyword::Transaction), literal: None, lexeme: lexm!("Transaction") , span: Span { line: 0, start: 6, line_end: 0, end: 17 }},
Token {tok_type: skw!(SqlKeyword::Rollback), literal: None, lexeme: lexm!("Rollback"), span: Span { line: 0, start: 18, line_end: 0, end: 26 }},
Expand All @@ -1224,7 +1224,6 @@ mod test {
Token {tok_type: skw!(SqlKeyword::Explain), literal: None, lexeme: lexm!("Explain"), span: Span { line: 0, start: 65, line_end: 0, end: 72 }},
Token {tok_type: skw!(SqlKeyword::Is), literal: None, lexeme: lexm!("Is"), span: Span { line: 0, start: 73, line_end: 0, end: 75 }},
Token {tok_type: skw!(SqlKeyword::Not), literal: None, lexeme: lexm!("Not"), span: Span { line: 0, start: 76, line_end: 0, end: 79 }},
Token {tok_type: skw!(SqlKeyword::Null), literal: None, lexeme: lexm!("Null"), span: Span { line: 0, start: 80, line_end: 0, end: 84 }},
Token {tok_type: skw!(SqlKeyword::Offset), literal: None, lexeme: lexm!("Offset"), span: Span { line: 0, start: 85, line_end: 0, end: 91 }},
Token {tok_type: skw!(SqlKeyword::Like), literal: None, lexeme: lexm!("Like"), span: Span { line: 0, start: 92, line_end: 0, end: 96 }},
Token {tok_type: skw!(SqlKeyword::Limit), literal: None, lexeme: lexm!("Limit"), span: Span { line: 0, start: 97, line_end: 0, end: 102 }},
Expand Down
4 changes: 0 additions & 4 deletions lykiadb-lang/src/tokenizer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub enum Symbol {
pub enum TokenType {
Str,
Num,
Null,
Undefined,
False,
True,
Expand Down Expand Up @@ -102,7 +101,6 @@ pub enum SqlKeyword {
//
Is,
Not,
Null,
Like,
In,
Between,
Expand Down Expand Up @@ -200,7 +198,6 @@ pub static GENERIC_KEYWORDS: phf::Map<&'static str, TokenType> = phf_map! {
"while" => kw!(Keyword::While),
"loop" => kw!(Keyword::Loop),
//
"null" => TokenType::Null,
"undefined" => TokenType::Undefined,
"false" => TokenType::False,
"true" => TokenType::True,
Expand Down Expand Up @@ -228,7 +225,6 @@ pub static SQL_KEYWORDS: phf::Map<&'static str, TokenType> = phf_map! {
"EXPLAIN" => skw!(SqlKeyword::Explain),
"IS" => skw!(SqlKeyword::Is),
"NOT" => skw!(SqlKeyword::Not),
"NULL" => skw!(SqlKeyword::Null),
"LIKE" => skw!(SqlKeyword::Like),
"IN" => skw!(SqlKeyword::In),
"BETWEEN" => skw!(SqlKeyword::Between),
Expand Down
15 changes: 0 additions & 15 deletions lykiadb-lang/tests/lang/generic/other_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,5 @@ assert_parsing! {
}
]
}
},
null: {
"null;" => {
"@type": "Stmt::Program",
"body": [
{
"@type": "Stmt::Expression",
"expr": {
"@type": "Expr::Literal",
"value": "Null",
"raw": "null"
}
}
]
}
}
}
10 changes: 0 additions & 10 deletions lykiadb-server/benches/scripts/while.ly
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@ var $i = 0;

while ($i < 10000000) {
$i = $i + 1;

1; 1; 1; 2; 1; null; 1; "str"; 1; true;
null; null; null; 1; null; "str"; null; true;
true; true; true; 1; true; false; true; "str"; true; null;
"str"; "str"; "str"; "stru"; "str"; 1; "str"; null; "str"; true;
}

$i = 0;
while ($i < 10000000) {
$i = $i + 1;

1 == 1; 1 == 2; 1 == null; 1 == "str"; 1 == true;
null == null; null == 1; null == "str"; null == true;
true == true; true == 1; true == false; true == "str"; true == null;
"str" == "str"; "str" == "stru"; "str" == 1; "str" == null; "str" == true;
}
5 changes: 0 additions & 5 deletions lykiadb-server/benches/scripts/while.short.ly
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ var $i = 0;

while ($i < 10000000) {
$i = $i + 1;

1; 1; 1; 2; 1; null; 1; "str"; 1; true;
null; null; null; 1; null; "str"; null; true;
true; true; true; 1; true; false; true; "str"; true; null;
"str"; "str"; "str"; "stru"; "str"; 1; "str"; null; "str"; true;
}
4 changes: 1 addition & 3 deletions lykiadb-server/src/engine/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Interpreter {
if let Some(num) = self.visit_expr(expr)?.as_number() {
return Ok(RV::Num(-num));
}
Ok(RV::NaN)
Ok(RV::Undefined)

Check warning on line 203 in lykiadb-server/src/engine/interpreter.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-server/src/engine/interpreter.rs#L203

Added line #L203 was not covered by tests
} else {
Ok(RV::Bool(!self.visit_expr(expr)?.as_bool()))
}
Expand Down Expand Up @@ -276,8 +276,6 @@ impl Interpreter {
Literal::Num(n) => RV::Num(*n),
Literal::Bool(b) => RV::Bool(*b),
Literal::Undefined => RV::Undefined,
Literal::NaN => RV::NaN,
Literal::Null => RV::Null,
Literal::Object(map) => {
let mut new_map = FxHashMap::default();
for (k, v) in map.iter() {
Expand Down
4 changes: 2 additions & 2 deletions lykiadb-server/src/engine/stdlib/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod tests {
);

assert_eq!(
nt_json_encode(&mut interpreter, &[RV::Null]).unwrap(),
nt_json_encode(&mut interpreter, &[RV::Undefined]).unwrap(),
RV::Str(Arc::new("null".to_string()))
);

Expand Down Expand Up @@ -121,7 +121,7 @@ mod tests {

assert_eq!(
nt_json_decode(&mut interpreter, &[RV::Str(Arc::new("null".to_string()))]).unwrap(),
RV::Null
RV::Undefined
);

// Test array
Expand Down
11 changes: 11 additions & 0 deletions lykiadb-server/src/value/datatype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use rustc_hash::FxHashMap;

pub enum Datatype {
Str,
Num,
Bool,
Composite(FxHashMap<String, Datatype>),
Array(Box<Datatype>),
Callable,
Undefined
}
Loading

0 comments on commit bd4d5ec

Please sign in to comment.