-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
621 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use lalrpop_util::lalrpop_mod; | ||
|
||
pub mod ast; | ||
pub mod parse; | ||
pub use ast::*; | ||
|
||
lalrpop_mod!( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use unescape::unescape; | ||
|
||
pub fn parse_str(str: &str) -> String { | ||
unescape(str).unwrap_or(String::new()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{collections::HashMap, rc::Rc}; | ||
use crate::{Val, Value}; | ||
use super::ty::Ty; | ||
|
||
pub struct Map(Rc<HashMap<Val, Val>>); | ||
|
||
impl Map { | ||
pub fn new(h: Rc<HashMap<Val, Val>>) -> Self { | ||
Self(h) | ||
} | ||
} | ||
|
||
impl Value for Map { | ||
fn ty(&self) -> super::ty::Ty { | ||
Ty::Map | ||
} | ||
|
||
fn native_value(&self) -> &dyn std::any::Any { | ||
&self.0 | ||
} | ||
|
||
fn equals(&self, other: &Val) -> Val { | ||
other | ||
.native_value() | ||
.downcast_ref::<Rc<HashMap<Val, Val>>>() | ||
.map(|other| { | ||
if other.len() != self.0.len() { | ||
return Val::new_bool(false); | ||
} | ||
|
||
for (k, v) in self.0.iter() { | ||
let ov = other.get(k); | ||
if !ov.is_none() { | ||
return Val::new_bool(false); | ||
} | ||
|
||
// TODO: use value.equals once all types support it. | ||
if !ov | ||
.unwrap() | ||
.compare(v) | ||
.is_some_and(|o| o.as_int() == Some(&0)) | ||
{ | ||
return Val::new_bool(false); | ||
} | ||
} | ||
|
||
return Val::new_bool(true); | ||
}) | ||
.unwrap_or(Val::new_bool(false)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ pub mod bytes; | |
pub mod double; | ||
pub mod uint; | ||
pub mod int; | ||
pub mod map; |
Oops, something went wrong.