Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwin Naren <[email protected]>
  • Loading branch information
arihant2math committed Apr 7, 2024
1 parent e5a51de commit 19e8a5c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dev-scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ networking = { path = "../internal/networking" }
serde = "1.0"
serde_json = "1.0"
bincode = "1.3"
zip = "0.6"
untwine = "0.4"
rayon = "1.10"
regex = "1.10"
zip = "0.6"
1 change: 1 addition & 0 deletions dev-scripts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod update_docs;
mod update_hash;
mod default_layout;
mod layout;
mod parser;


#[derive(Clone, Parser)]
Expand Down
56 changes: 56 additions & 0 deletions dev-scripts/src/parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::{
collections::HashMap,
num::{ParseFloatError, ParseIntError},
};

use untwine::{parser, parser_repl};

#[derive(Debug)]
pub enum JSONValue {
String(String),
Null,
Int(i128),
Float(f64),
Bool(bool),
List(Vec<JSONValue>),
Map(HashMap<String, JSONValue>),
}

impl JSONValue {
pub fn string(self) -> Option<String> {
match self {
JSONValue::String(s) => Some(s),
_ => None,
}
}
}

#[derive(Debug, thiserror::Error)]
enum ParseJSONError {
#[error("Syntax error: {0}")]
Untwine(#[from] untwine::ParserError),
#[error("Failed to parse number: {0}")]
ParseInt(#[from] ParseIntError),
#[error("Failed to parse number: {0}")]
ParseFloat(#[from] ParseFloatError),
}

parser! {
[error = ParseJSONError]
sep = #{char::is_ascii_whitespace}*;
comma = sep "," sep;
int: num=<"-"? '0'-'9'+> -> JSONValue { JSONValue::Int(num.parse()?) }
float: num=<"-"? '0'-'9'+ "." '0'-'9'+> -> JSONValue { JSONValue::Float(num.parse()?) }
str_char = ("\\" . | [^"\""]) -> char;
str: "\"" chars=str_char* "\"" -> JSONValue { JSONValue::String(chars.into_iter().collect()) }
null: "null" -> JSONValue { JSONValue::Null }
bool: bool=<"true" | "false"> -> JSONValue { JSONValue::Bool(bool == "true") }
list: "[" sep values=json$comma* sep "]" -> JSONValue { JSONValue::List(values) }
map_entry: key=str sep ":" sep value=json -> (String, JSONValue) { (key.string().unwrap(), value) }
map: "{" sep values=map_entry$comma* sep "}" -> JSONValue { JSONValue::Map(values.into_iter().collect()) }
pub json = (bool | null | str | float | int | list | map) -> JSONValue;
}

fn main() {
parser_repl(json);
}
4 changes: 4 additions & 0 deletions internal/backend/src/datasource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// TODO: use
trait Datasource {
fn get(&self, coordinates: &Coordinates, settings: Settings) -> crate::Result<WeatherForecast>;
}

0 comments on commit 19e8a5c

Please sign in to comment.